mirror of
https://codeberg.org/streams/streams.git
synced 2024-09-20 01:15:13 +00:00
29 lines
718 B
JavaScript
29 lines
718 B
JavaScript
// This file should be served from the web root to avoid scope and cookie related issues with some browsers
|
|
self.addEventListener('install', function(e) {
|
|
console.log('install event');
|
|
});
|
|
|
|
self.addEventListener('fetch', function(e) {
|
|
// nothing here yet
|
|
|
|
});
|
|
|
|
self.addEventListener('push', function (event) {
|
|
if (!(self.Notification && self.Notification.permission === 'granted')) {
|
|
return;
|
|
}
|
|
|
|
const sendNotification = body => {
|
|
// you could refresh a notification badge here with postMessage API
|
|
const title = "";
|
|
|
|
return self.registration.showNotification(title, {
|
|
body,
|
|
});
|
|
};
|
|
|
|
if (event.data) {
|
|
const payload = event.data.json();
|
|
event.waitUntil(sendNotification(payload.message));
|
|
}
|
|
});
|