diff --git a/web/static/call.wav b/call.wav similarity index 100% rename from web/static/call.wav rename to call.wav diff --git a/index.ts b/index.ts index d07beea..e4a2bac 100644 --- a/index.ts +++ b/index.ts @@ -94,6 +94,12 @@ Bun.serve({ } } else if (data.type == "rooms") { ws.send(JSON.stringify({ type: "rooms", rooms: ROOMS })); + } else if (data.type == "call-audio") { + // Send the call.wav file as data URI + const file = await Bun.file("./call.wav").arrayBuffer(); + const base64 = Buffer.from(file).toString("base64"); + const dataUri = `data:audio/wav;base64,${base64}`; + ws.send(JSON.stringify({ type: "call-audio", dataUri })); } }, // a message is received open(ws) { diff --git a/web/src/routes/display/+page.svelte b/web/src/routes/display/+page.svelte index f4695c2..69ecc3f 100644 --- a/web/src/routes/display/+page.svelte +++ b/web/src/routes/display/+page.svelte @@ -13,6 +13,7 @@ } let withSound = false; + let callAudioURI = ""; let persisted: PersistedState = new PersistedState("calls", []); let calls = $state($state.snapshot(persisted.current)); let newCalls = $state([]); @@ -37,8 +38,8 @@ persisted.current = calls; connected = true; if (!firstLoad) { - if (_newCalls.length > 0 && withSound) { - const audio = new Audio("/call.wav"); + if (_newCalls.length > 0 && withSound && callAudioURI) { + const audio = new Audio(callAudioURI); audio.play(); } newCalls.push(..._newCalls); @@ -52,6 +53,15 @@ eventTarget.dispatchEvent( new CustomEvent("send", { detail: { type: "display" } }) ); + if(withSound) { + eventTarget.addEventListener("call-audio", (e) => { + const detail = (e as CustomEvent).detail; + callAudioURI = detail.dataUri; + }); + eventTarget.dispatchEvent( + new CustomEvent("send", { detail: { type: "call-audio" } }) + ); + } }); function updateMarqueeSpeed() {