mirror of
https://github.com/EchoSixHIYA/WebSpeak-client-for-TeamSpeak.git
synced 2026-12-02 19:42:51 +08:00
feat: add STUN candidates for screen sharing
This commit is contained in:
1 parent
de8f6a11c9
commit
8ed3e788be
10 files changed
+174
-8
No files matched your search
@@ -7,6 +7,40 @@ import { loadLocalPreferences, saveLocalPreferences } from "../services/local-pe
|
||||
|
||||
const micCaptureWorkletUrl = "/mic-capture-worklet.js";
|
||||
const SCREEN_SHARE_NEGOTIATION_TIMEOUT_MS = 15_000;
|
||||
const DEFAULT_SCREEN_SHARE_ICE_SERVERS: RTCIceServer[] = [
|
||||
{ urls: "stun:turn.teamspeak.com:3478" },
|
||||
{ urls: "stun:turn2.teamspeak.com:3478" },
|
||||
];
|
||||
let screenShareIceServers: RTCIceServer[] = DEFAULT_SCREEN_SHARE_ICE_SERVERS;
|
||||
|
||||
function normalizeScreenShareIceServers(raw: unknown): RTCIceServer[] {
|
||||
if (!Array.isArray(raw)) return DEFAULT_SCREEN_SHARE_ICE_SERVERS;
|
||||
const normalized: RTCIceServer[] = [];
|
||||
const seen = new Set<string>();
|
||||
for (const item of raw) {
|
||||
if (!item || typeof item !== "object" || Array.isArray(item)) continue;
|
||||
const value = item as Record<string, unknown>;
|
||||
const rawUrls = value.urls;
|
||||
const urls = (Array.isArray(rawUrls) ? rawUrls : [rawUrls])
|
||||
.filter((url): url is string => typeof url === "string" && /^(?:stun|stuns|turn|turns):/i.test(url.trim()))
|
||||
.map((url) => url.trim())
|
||||
.filter(Boolean);
|
||||
const uniqueUrls = [...new Set(urls)];
|
||||
if (!uniqueUrls.length) continue;
|
||||
const username = typeof value.username === "string" ? value.username : undefined;
|
||||
const credential = typeof value.credential === "string" ? value.credential : undefined;
|
||||
const key = JSON.stringify([uniqueUrls, username ?? ""]);
|
||||
if (seen.has(key)) continue;
|
||||
seen.add(key);
|
||||
normalized.push({
|
||||
urls: uniqueUrls.length === 1 ? uniqueUrls[0] : uniqueUrls,
|
||||
...(username !== undefined ? { username } : {}),
|
||||
...(credential !== undefined ? { credential } : {}),
|
||||
});
|
||||
if (normalized.length >= 8) break;
|
||||
}
|
||||
return normalized.length ? normalized : DEFAULT_SCREEN_SHARE_ICE_SERVERS;
|
||||
}
|
||||
|
||||
export interface VoiceState {
|
||||
connected: boolean;
|
||||
@@ -1694,8 +1728,10 @@ export function useVoiceWebSocket() {
|
||||
function createScreenSharePeer(streamId: string, peerId: string, role: "owner" | "viewer"): RTCPeerConnection {
|
||||
const existing = screenSharePeers.get(peerId);
|
||||
if (existing) return existing;
|
||||
// Deliberately no STUN/TURN: this feature is direct host-candidate P2P only.
|
||||
const peer = new RTCPeerConnection({ iceServers: [] });
|
||||
// STUN discovers server-reflexive candidates; it does not carry media.
|
||||
// TURN is accepted only when explicitly configured by the deployment, and
|
||||
// would use that external TURN service rather than the WebSpeak gateway.
|
||||
const peer = new RTCPeerConnection({ iceServers: screenShareIceServers });
|
||||
screenSharePeers.set(peerId, peer);
|
||||
if (role === "owner") {
|
||||
for (const track of screenShareLocalStream?.getTracks() ?? []) peer.addTrack(track, screenShareLocalStream!);
|
||||
@@ -2031,6 +2067,7 @@ export function useVoiceWebSocket() {
|
||||
state.channelSwitchedChannelId = "";
|
||||
state.tsClientId = Number(msg.tsClientId) || 0;
|
||||
state.canMoveClients = msg.canMoveClients === true;
|
||||
screenShareIceServers = normalizeScreenShareIceServers(msg.screenShareIceServers);
|
||||
applyWhisperState(msg.whisperTargetIds, msg.whisperActive);
|
||||
if (Array.isArray(msg.members)) {
|
||||
members.length = 0;
|
||||
|
||||
@@ -614,7 +614,7 @@ const translations: Record<string, Record<string, string>> = {
|
||||
teamSpeakSource: "TeamSpeak 客户端来源",
|
||||
sharedAudio: "含共享音频",
|
||||
noScreenShares: "当前没有正在进行的屏幕共享",
|
||||
directP2POnly: "直连 P2P · 不使用 STUN/TURN",
|
||||
directP2POnly: "直连 P2P · STUN 仅用于发现公网地址",
|
||||
screenShareNativeUnavailable: "原生 TeamSpeak 屏幕共享暂不支持网页观看",
|
||||
watching: "观看中",
|
||||
serverPassword: "服务器密码",
|
||||
@@ -920,7 +920,7 @@ const translations: Record<string, Record<string, string>> = {
|
||||
teamSpeakSource: "TeamSpeak client source",
|
||||
sharedAudio: "with shared audio",
|
||||
noScreenShares: "No active screen shares",
|
||||
directP2POnly: "Direct P2P · no STUN/TURN",
|
||||
directP2POnly: "Direct P2P · STUN for public candidate discovery",
|
||||
screenShareNativeUnavailable: "Native TeamSpeak screen sharing is not available to web viewers yet",
|
||||
watching: "Watching",
|
||||
serverPassword: "Server password",
|
||||
|
||||
Reference in new issue
Block a user