3 ms·
You don't need to poll. One can subscribe to storage events, and that way you can broadcast ordered messages to all your tabs without any polling. https://w3c.
by kalmi10 11y ago
You don't need to poll. One can subscribe to storage events, and that way you can broadcast ordered messages to all your tabs without any polling.
https://w3c.github.io/webstorage/#the-storage-event https://w3c.github.io/webstorage/#the-storage-event
- Retr0spectrum 11y agoWouldn't you still have to poll to check if the "leader" still exists?
- nathan-muir 11y agoIf playing the sound isn't latency sensitive, you could just have each tab pick a random delay [1]. When the tabs receive the event, they each wait X milliseconds. The first timer to expire marks the event as "played". Other tabs receive this event, and abort their timers. If a "leader" disappears, it will simply fall to a tab with a larger delay. [1] Something like, rounded to 50ms increments, in a range, 100 - 1000ms. Avoiding collisions / ensuring uniqueness is left as an exercise for the reader.