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