mirror of
https://github.com/EchoSixHIYA/WebSpeak-client-for-TeamSpeak.git
synced 2026-12-03 03:52:50 +08:00
fix(audio): cleanly fall back from WebRTC
This commit is contained in:
1 parent
a4cf5b5359
commit
40ea30b9e2
2 files changed
+16
No files matched your search
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in new issue
Block a user