BroadcastChannel is a native function in Angular. It doesn't require importing an additional library. You just declare it like this...
const broadcastChannel = new BroadcastChannel('demo-broadcast-channel');
You send messages like this...
this.counter++;
broadcastChannel.postMessage({
type: 'counter',
counter: this.counter
});
}
and you receive them like this...
const broadcastChannel = new BroadcastChannel('demo-broadcast-channel');
this.broadcastChannel.onmessage = (message) => {
console.log('Received message', message);
}
This works on ALL browsers except Safari on all Apple devices, where we get:
ReferenceError: Can't find variable: BroadcastChannel
Any suggestions?
Thanks.