mirror of
https://github.com/EchoSixHIYA/WebSpeak-client-for-TeamSpeak.git
synced 2026-12-02 19:42:51 +08:00
refactor: share admin contracts and isolate page styles
This commit is contained in:
1 parent
e2f0a43762
commit
f0712fa3fc
26 files changed
+2231
-1733
No files matched your search
@@ -1,6 +1,7 @@
|
||||
import { createScreenShareController } from "../voice/screen-share.js";
|
||||
export type { ScreenShareOutputSettings, ScreenShareCaptureStats, ScreenSharePeerStats, ScreenShareWebRtcStats } from "../voice/screen-share.js";
|
||||
import { parseServerMessage } from "../../../src/shared/server-messages.js";
|
||||
import { isSessionDescription, type WebRtcClientMessage } from "../../../src/shared/webrtc.js";
|
||||
import type { ClientCommandPayloads, ClientCommandType } from "../../../src/shared/client-commands.js";
|
||||
export type { ScreenShareStreamDescription as ScreenShareStream, ScreenShareViewerDescription as ScreenShareViewer, ScreenSharePeerSignal as ScreenShareSignal } from "../../../src/shared/screen-share.js";
|
||||
import type { ChannelMember, ChannelInfo, ChatMessage, ServerEvent, VoiceAudioBridgeStats } from "../../../src/shared/voice-models.js";
|
||||
@@ -220,6 +221,10 @@ class CancelledMediaOperation extends Error {
|
||||
constructor() { super("媒体操作已取消"); this.name = "AbortError"; }
|
||||
}
|
||||
|
||||
function sendWebRtcMessage(socket: WebSocket, message: WebRtcClientMessage): void {
|
||||
socket.send(JSON.stringify(message));
|
||||
}
|
||||
|
||||
export function useVoiceWebSocket() {
|
||||
const ws = shallowRef<WebSocket | null>(null);
|
||||
const state = reactive<VoiceState>({ connected: false, connecting: false, reconnecting: false, reconnectAttempt: 0, reconnectFailed: false, tsClientId: 0, error: "", errorCode: "", microphoneError: "", microphoneErrorCode: "", audioNotice: "", audioNoticeCode: "", channelSwitchedChannelId: "" });
|
||||
@@ -1059,12 +1064,12 @@ export function useVoiceWebSocket() {
|
||||
await waitForIceGathering(peer);
|
||||
if (!isCurrentPeer()) return;
|
||||
const description = peer.localDescription;
|
||||
if (!description) throw new Error("WebRTC offer was not created");
|
||||
socket.send(JSON.stringify({ type: "webrtcOffer", payload: {
|
||||
if (!description || description.type !== "offer") throw new Error("WebRTC offer was not created");
|
||||
sendWebRtcMessage(socket, { type: "webrtcOffer", payload: {
|
||||
sdp: { type: description.type, sdp: description.sdp },
|
||||
muted: microphoneMuted.value,
|
||||
accompanimentActive: accompanimentActive.value,
|
||||
} }));
|
||||
} });
|
||||
webrtcAnswerTimer = window.setTimeout(() => {
|
||||
webrtcAnswerTimer = null;
|
||||
if (isCurrentPeer() && !peer.remoteDescription) void fallbackFromWebRtc(sequence, socket, "WEBRTC_ANSWER_TIMEOUT");
|
||||
@@ -1124,7 +1129,7 @@ export function useVoiceWebSocket() {
|
||||
if (sequence !== connectionSequence || ws.value !== socket || !state.connected || webrtcFallbackStarted) return;
|
||||
webrtcFallbackStarted = true;
|
||||
webrtcActive.value = false;
|
||||
if (socket.readyState === WebSocket.OPEN) socket.send(JSON.stringify({ type: "webrtcStop" }));
|
||||
if (socket.readyState === WebSocket.OPEN) sendWebRtcMessage(socket, { type: "webrtcStop" });
|
||||
stopWebRtcTransport();
|
||||
if (socket.readyState === WebSocket.OPEN && state.connected) {
|
||||
// Degrading to the compatibility transport must be visible: the user is
|
||||
@@ -1209,12 +1214,6 @@ export function useVoiceWebSocket() {
|
||||
if (resetLevel) micLevel.value = 0;
|
||||
}
|
||||
|
||||
function isSessionDescription(value: unknown, type: "answer"): value is RTCSessionDescriptionInit {
|
||||
return Boolean(value) && typeof value === "object"
|
||||
&& (value as { type?: unknown }).type === type
|
||||
&& typeof (value as { sdp?: unknown }).sdp === "string";
|
||||
}
|
||||
|
||||
function stopCaptureGraph(): void {
|
||||
accumLen = 0;
|
||||
voxAttack = 0;
|
||||
|
||||
Reference in new issue
Block a user