|
|
@ -7,7 +7,9 @@ self.addEventListener('install', function(event) {
|
|
|
|
console.log('Installed', event);
|
|
|
|
console.log('Installed', event);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
self.addEventListener('activate', (event) => {
|
|
|
|
self.addEventListener('activate', (event) => {
|
|
|
|
|
|
|
|
// event.waitUntil(self.clients.claim());
|
|
|
|
event.waitUntil(openWebSocket());
|
|
|
|
event.waitUntil(openWebSocket());
|
|
|
|
|
|
|
|
self.clients.claim();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
self.addEventListener('push', (event) => {
|
|
|
|
self.addEventListener('push', (event) => {
|
|
|
@ -18,7 +20,7 @@ self.addEventListener('push', (event) => {
|
|
|
|
body: data.body || 'You have a new message',
|
|
|
|
body: data.body || 'You have a new message',
|
|
|
|
icon: 'path/to/icon.png',
|
|
|
|
icon: 'path/to/icon.png',
|
|
|
|
badge: 'path/to/badge.png',
|
|
|
|
badge: 'path/to/badge.png',
|
|
|
|
vibrate: [200, 100, 200],
|
|
|
|
vibrate: [200, 100, 200], // 振动
|
|
|
|
// Other notification options
|
|
|
|
// Other notification options
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
@ -26,3 +28,12 @@ self.addEventListener('push', (event) => {
|
|
|
|
self.registration.showNotification(title, options)
|
|
|
|
self.registration.showNotification(title, options)
|
|
|
|
);
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Send a message to all clients every minute
|
|
|
|
|
|
|
|
setInterval(function() {
|
|
|
|
|
|
|
|
self.clients.matchAll().then(function(clients) {
|
|
|
|
|
|
|
|
clients.forEach(function(client) {
|
|
|
|
|
|
|
|
client.postMessage('Service worker is still running');
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}, 60000); // 60000 ms = 1 minute
|
|
|
|