fix(audio): cleanly fall back from WebRTC

This commit is contained in:
illusia committed 2026-09-03 01:29:34 +08:00
1 parent a4cf5b5359
commit 40ea30b9e2
2 files changed
+16

No files matched your search

+15
View File
@@ -526,6 +526,12 @@ export class VoiceBridge {
void this.handleWebRtcOffer(entry!, webRtcOffer, sendJson);
return;
}
if (isWebRtcStopMessage(rawMessage)) {
const webRtc = entry!.webrtc;
entry!.webrtc = null;
if (webRtc) void webRtc.close();
return;
}
const command = parseClientCommand(rawMessage);
if ("error" in command) {
sendProtocolError(sendJson, command.error.code, command.error.message);
@@ -824,6 +830,15 @@ function parseWebRtcOffer(raw: string): WebRtcSessionDescription | null {
return { type: "offer", sdp: description.sdp };
}
function isWebRtcStopMessage(raw: string): boolean {
try {
const value: unknown = JSON.parse(raw);
return isRecord(value) && value.type === "webrtcStop";
} catch {
return false;
}
}
function isRecord(value: unknown): value is Record<string, unknown> {
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
}
+1
View File
@@ -538,6 +538,7 @@ export function useVoiceWebSocket() {
if (sequence !== connectionSequence || webrtcFallbackStarted) return;
webrtcFallbackStarted = true;
webrtcActive.value = false;
if (socket.readyState === WebSocket.OPEN) socket.send(JSON.stringify({ type: "webrtcStop" }));
stopWebRtcTransport();
if (socket.readyState === WebSocket.OPEN && state.connected) {
try { await startMicrophone(); } catch (error: unknown) {