feat: move call sound to server

This commit is contained in:
2026-03-07 17:04:55 +01:00
parent 952373bbee
commit dd7e7e59e6
3 changed files with 18 additions and 2 deletions

View File

@@ -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) {

View File

@@ -13,6 +13,7 @@
}
let withSound = false;
let callAudioURI = "";
let persisted: PersistedState<CallEntry[]> = new PersistedState("calls", []);
let calls = $state<CallEntry[]>($state.snapshot(persisted.current));
let newCalls = $state<CallEntry[]>([]);
@@ -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() {