a314aab7ec
* Add support for Web Push Notifications when users receive a new Message or Friend Request on the main website. * Users opt in or out of this on their Notification Settings. They can also individually opt out of Message and Friend Request push notifications.
20 lines
517 B
JavaScript
20 lines
517 B
JavaScript
/* nonshy service worker, for web push notifications */
|
|
|
|
self.addEventListener('install', (event) => {
|
|
self.skipWaiting();
|
|
});
|
|
|
|
self.addEventListener('push', (event) => {
|
|
const payload = JSON.parse(event.data.text());
|
|
try {
|
|
event.waitUntil(
|
|
self.registration.showNotification(payload.title, {
|
|
body: payload.body,
|
|
icon: "/static/img/favicon-192.png",
|
|
})
|
|
);
|
|
} catch(e) {
|
|
console.error("sw.showNotification:", e);
|
|
}
|
|
});
|