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