Broadcast channel
This commit is contained in:
parent
bec8fcdce1
commit
e4829976e4
1 changed files with 14 additions and 7 deletions
|
@ -11,14 +11,21 @@
|
|||
navigator.serviceWorker.register('/service-worker.js');
|
||||
});
|
||||
|
||||
if (BroadcastChannel) {
|
||||
const channel = new BroadcastChannel('sw-messages');
|
||||
channel.addEventListener('message', (event) => {
|
||||
console.log(event.data);
|
||||
new Toast({ target: node });
|
||||
});
|
||||
} else {
|
||||
navigator.serviceWorker.addEventListener('message', (evt) => {
|
||||
console.log(evt.data);
|
||||
new Toast({ target: node });
|
||||
});
|
||||
}
|
||||
|
||||
navigator.serviceWorker.ready.then((registration) => {
|
||||
console.log(registration);
|
||||
console.log('registered service worker');
|
||||
registration.active?.postMessage('Save client');
|
||||
});
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue