Implement proof of concept push notifications
This commit is contained in:
parent
e3210afe3a
commit
6007f4caeb
13 changed files with 407 additions and 1 deletions
25
public/sw.js
Normal file
25
public/sw.js
Normal file
|
@ -0,0 +1,25 @@
|
|||
self.addEventListener("push", function (event) {
|
||||
console.log(event);
|
||||
if (!event.data)
|
||||
return;
|
||||
|
||||
const payload = event.data.json();
|
||||
const { body, icon, image, badge, url, title } = payload;
|
||||
const notificationTitle = title ?? "No title";
|
||||
const notificationOptions = {
|
||||
body,
|
||||
icon,
|
||||
image,
|
||||
data: {
|
||||
url,
|
||||
},
|
||||
badge,
|
||||
};
|
||||
|
||||
event.waitUntil(
|
||||
self.registration.showNotification(notificationTitle, notificationOptions)
|
||||
.then(() => {
|
||||
console.log("Web push delivered");
|
||||
})
|
||||
);
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue