client/packages/shared/src/sounds.ts
Alois 184b85190b
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
(feat): add sounds
2026-07-30 23:51:38 +02:00

34 lines
763 B
TypeScript

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