You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
29 lines
698 B
JavaScript
29 lines
698 B
JavaScript
1 year ago
|
function openWebSocket() {
|
||
|
console.log('open websocket');
|
||
|
}
|
||
|
|
||
|
self.addEventListener('install', function(event) {
|
||
|
self.skipWaiting();
|
||
|
console.log('Installed', event);
|
||
|
});
|
||
|
self.addEventListener('activate', (event) => {
|
||
|
event.waitUntil(openWebSocket());
|
||
|
});
|
||
|
|
||
|
self.addEventListener('push', (event) => {
|
||
|
const data = event.data.json();
|
||
|
|
||
|
const title = data.title || 'New Message';
|
||
|
const options = {
|
||
|
body: data.body || 'You have a new message',
|
||
|
icon: 'path/to/icon.png',
|
||
|
badge: 'path/to/badge.png',
|
||
|
vibrate: [200, 100, 200],
|
||
|
// Other notification options
|
||
|
};
|
||
|
|
||
|
event.waitUntil(
|
||
|
self.registration.showNotification(title, options)
|
||
|
);
|
||
|
});
|