From 46b190a913b8bff30313421e931b7924df5b933f Mon Sep 17 00:00:00 2001 From: illusia <64828020+EchoSixHIYA@users.noreply.github.com> Date: Thu, 3 Sep 2026 01:02:18 +0800 Subject: [PATCH] fix(audio): avoid duplicate WebRTC playback --- src/server/voice-bridge.ts | 8 +++++++- web/src/composables/useVoiceWebSocket.ts | 4 ++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/server/voice-bridge.ts b/src/server/voice-bridge.ts index f60906e..a7d0b16 100644 --- a/src/server/voice-bridge.ts +++ b/src/server/voice-bridge.ts @@ -423,7 +423,13 @@ export class VoiceBridge { tsClient.on("voiceData", (data: TSVoiceData) => { if (ws.readyState !== WebSocket.OPEN || data.clientId === selfId) return; - entry!.webrtc?.pushTeamSpeakVoice(data); + const webRtc = entry!.webrtc; + webRtc?.pushTeamSpeakVoice(data); + // A negotiated WebRTC session owns the browser's realtime audio + // egress. Do not also send the same TeamSpeak packet over the + // reliable WebSocket, otherwise the browser plays two copies and + // the TCP path can still accumulate stale audio behind the peer. + if (webRtc) return; const now = Date.now(); if (entry!.audio.egressLastAt !== null) entry!.audio.egressMaxGapMs = Math.max(entry!.audio.egressMaxGapMs, now - entry!.audio.egressLastAt); entry!.audio.egressFirstAt ??= now; diff --git a/web/src/composables/useVoiceWebSocket.ts b/web/src/composables/useVoiceWebSocket.ts index 5f73ef5..d264ccd 100644 --- a/web/src/composables/useVoiceWebSocket.ts +++ b/web/src/composables/useVoiceWebSocket.ts @@ -1096,6 +1096,10 @@ export function useVoiceWebSocket() { } function handleAudioFrame(data: Uint8Array): void { + // WebRTC carries the realtime downlink after negotiation. Ignore any + // in-flight fallback WebSocket packets so a transport switch cannot + // produce duplicate or delayed playback. + if (webrtcActive.value) return; if (data.length < 4) return; const clientId = (data[1] << 8) | data[2]; if (clientId === state.tsClientId) return;