xonecas.io
8058
Ir

irvc / commit afa3863

feat: annoying ass sound notif for join/leave

xonecas2026-10-12 afa38637caed0bf3e19dec315e6e052021fa9c97 parent 55c9351

3 files changed

web/src/components/SettingsPanel.tsx+9−1
@@ -69,7 +69,7 @@ export default function SettingsPanel({
6969 return (
7070 <div className="flex-1 overflow-y-auto">
7171 <div className="mx-auto max-w-2xl space-y-4 p-6">
72- <Group label="Appearance">
72+ <Group label="User preferences">
7373 <Field label="theme">
7474 <Select
7575 value={theme}
@@ -92,6 +92,14 @@ export default function SettingsPanel({
9292 </Field>
9393 </Group>
9494
95+ <Group label="Sounds">
96+ <Toggle
97+ label="join/leave sound"
98+ value={settings.joinSound}
99+ onChange={(v) => update({ joinSound: v })}
100+ />
101+ </Group>
102+
95103 <Group label="Voice">
96104 <Button
97105 variant={settings.deafened ? "secondary" : "ghost"}
web/src/lib/settings.ts+2−0
@@ -20,6 +20,7 @@ export interface Settings {
2020 speakerDeviceId: string;
2121 deafened: boolean;
2222 gateThreshold: number;
23+ joinSound: boolean;
2324 fontSize: FontSize;
2425 }
2526
@@ -33,6 +34,7 @@ export const defaultSettings: Settings = {
3334 speakerDeviceId: "",
3435 deafened: false,
3536 gateThreshold: -60,
37+ joinSound: true,
3638 fontSize: "default",
3739 };
3840
web/src/lib/voice.ts+28−2
@@ -16,6 +16,21 @@ interface VoiceToken {
1616 room: string;
1717 }
1818
19+// beep plays a short tone for call roster changes (someone joined or left the
20+// call you are in). Web Audio needs no asset; it unlocks on the click that
21+// joined the call.
22+function beep(freq: number) {
23+ const ctx = new AudioContext();
24+ const osc = ctx.createOscillator();
25+ const gain = ctx.createGain();
26+ gain.gain.value = 0.1;
27+ osc.frequency.value = freq;
28+ osc.connect(gain).connect(ctx.destination);
29+ osc.start();
30+ osc.stop(ctx.currentTime + 0.12);
31+ osc.onended = () => ctx.close();
32+}
33+
1934 // dbfs computes the RMS level, in dBFS, of an analyser's latest time-domain
2035 // samples. Near-silence clamps toward -inf via the epsilon.
2136 function dbfs(analyser: AnalyserNode, buf: Float32Array<ArrayBuffer>): number {
@@ -194,6 +209,7 @@ export function useVoice(
194209 const roomRef = useRef<Room | null>(null);
195210 const audioRef = useRef<HTMLAudioElement[]>([]);
196211 const genRef = useRef(0);
212+ const readyRef = useRef(false);
197213 const settingsRef = useRef(settings);
198214 const mutedRef = useRef(false);
199215 const appliedRef = useRef("");
@@ -213,6 +229,7 @@ export function useVoice(
213229 const room = roomRef.current;
214230 roomRef.current = null;
215231 appliedRef.current = "";
232+ readyRef.current = false;
216233 audioRef.current.forEach((el) => el.remove());
217234 audioRef.current = [];
218235 room?.disconnect();
@@ -242,8 +259,14 @@ export function useVoice(
242259 roomRef.current = room;
243260 const sync = () =>
244261 setPeers([...room.remoteParticipants.values()].map((p) => p.name || p.identity));
245- room.on(RoomEvent.ParticipantConnected, sync);
246- room.on(RoomEvent.ParticipantDisconnected, sync);
262+ room.on(RoomEvent.ParticipantConnected, () => {
263+ if (readyRef.current && settingsRef.current.joinSound) beep(660);
264+ sync();
265+ });
266+ room.on(RoomEvent.ParticipantDisconnected, () => {
267+ if (readyRef.current && settingsRef.current.joinSound) beep(440);
268+ sync();
269+ });
247270 room.on(RoomEvent.ActiveSpeakersChanged, (speakers: Participant[]) =>
248271 setSpeaking(speakers.map((p) => p.name || p.identity)),
249272 );
@@ -265,6 +288,9 @@ export function useVoice(
265288 room.disconnect();
266289 return;
267290 }
291+ // Existing participants fired ParticipantConnected during connect; only
292+ // later connect/disconnect events should beep.
293+ readyRef.current = true;
268294 const mic = await room.localParticipant.setMicrophoneEnabled(true, capture(s), publish(s));
269295 if (mic?.audioTrack) await mic.audioTrack.setProcessor(gate.processor);
270296 if (s.speakerDeviceId) {