shuttlecraft
shuttlecraft copied to clipboard
Add a beep sound
CC0 licensed, no attribution needed, https://opengameart.org/content/8-bit-sound-effect-pack
Alas, in Chrome, this throws an error instead of playing the sound.
"app.js:45 Uncaught (in promise) DOMException: play() failed because the user didn't interact with the document first. https://goo.gl/xX8pDD"
Huh! It seems to be working after some small tweaks.
A few things to do before this merges:
- [ ] put the sound at a normal url like public/beep.mp4 or whatever it is (make it easier for people to change, find, etc)
- [ ] sound currently fires every page load. should only fire when the number changes. tricky.
Changed to use /audio/beep.wav AIUI, the beep sound does not play on every page load as app.newDMs will be undefined, https://github.com/benbrown/shuttlecraft/blob/main/public/app.js#L90
app.newDMs should be initialized to 0, not doing so was a bug. Any of the other counters could also immediately return with a number and cause the beep to fire, and as implemented could cause multi-beeps!
Just thinking out loud here but I think to get this right I need to:
- improve the implementation and generalize the availability of the notification indicators
- perhaps render them serverside and initialize with real current values
- make the client side code a bit more sophisticated about when to beep