custom service-worker
parent
2650ed63c6
commit
e7c7d7b1be
@ -0,0 +1,28 @@
|
||||
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)
|
||||
);
|
||||
});
|
Loading…
Reference in New Issue