4 ms·
This sounds like a good use case for a Shared Worker[0]. A shared worker is a web worker which can be shared by multiple pages / windows / tabs, and can easily
by timothya 11y ago
This sounds like a good use case for a Shared Worker[0].
A shared worker is a web worker which can be shared by multiple pages / windows / tabs, and can easily be used for coordination of this type. The shared worker can listen for the asynchronous event and then send a message to an appropriate tab to play the sound as necessary. Unfortunately, Shared Workers aren't supported everywhere yet[1] (only on Chrome, Firefox, and Opera), but hopefully support will come to the other browsers soon.
Regarding playing sounds on iOS, the Web Audio API is a good way to go here. While it's true that you need a user gesture to trigger sound, you only need it for the first sound you play. So you can add a button to your web app which when clicked plays a short "empty" sound (just silence), and after that point you can play whatever sound you like at whatever time you like; it no longer needs a user gesture for it to be played.
[0]: https://developer.mozilla.org/en-US/docs/Web/API/SharedWorker https://developer.mozilla.org/en-US/docs/Web/API/SharedWorke...
[1]: http://caniuse.com/#feat=sharedworkers http://caniuse.com/#feat=sharedworkers