(feat): add sounds
Some checks failed
/ release (push) Has been cancelled
/ build-desktop (linux) (push) Has been cancelled
/ build-web (push) Has been cancelled
/ build-mobile (push) Has been cancelled

This commit is contained in:
Alois 2026-07-30 23:51:38 +02:00
commit 184b85190b
Signed by: alois
SSH key fingerprint: SHA256:GBzT2DXvAuGV9XIV5W3WrzVpjU54FThmxHXdbz95J24
19 changed files with 207 additions and 16 deletions

View 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;
}