(feat): add sounds
This commit is contained in:
parent
6a5236bafe
commit
184b85190b
19 changed files with 207 additions and 16 deletions
34
packages/shared/src/sounds.ts
Normal file
34
packages/shared/src/sounds.ts
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
export type SoundName =
|
||||
| "call_jingle_1"
|
||||
| "call_jingle_2"
|
||||
| "call_join"
|
||||
| "call_leave"
|
||||
| "message"
|
||||
| "stream_end_other"
|
||||
| "stream_end_self"
|
||||
| "stream_start_other"
|
||||
| "stream_start_self"
|
||||
| "stream_watch_end"
|
||||
| "stream_watch_start";
|
||||
|
||||
function soundUrl(sound: SoundName) {
|
||||
if (window.location.protocol === "file:") {
|
||||
return new URL(`./sounds/${sound}.wav`, document.baseURI).href;
|
||||
}
|
||||
|
||||
return `/sounds/${sound}.wav`;
|
||||
}
|
||||
|
||||
export function playSound(sound: SoundName, loop = false) {
|
||||
const audio = new Audio(soundUrl(sound));
|
||||
audio.loop = loop;
|
||||
void audio.play().catch(() => undefined);
|
||||
return audio;
|
||||
}
|
||||
|
||||
export function stopSound(audio: HTMLAudioElement | null) {
|
||||
if (!audio) return;
|
||||
|
||||
audio.pause();
|
||||
audio.currentTime = 0;
|
||||
}
|
||||
Loading…
Reference in a new issue