Re:Javascript, locking and sound
by Retr0spectrum on Saturday July 25, 2015 @08:48PM
(#9949656)
Wouldn't you still have to poll to check if the "leader" still exists?
Re:Javascript, locking and sound
by nathan-muir on Saturday July 25, 2015 @09:30PM
(#9949747)
If 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.
https://w3c.github.io/webstorage/#the-storage-event