mirror of
https://github.com/EchoSixHIYA/WebSpeak-client-for-TeamSpeak.git
synced 2026-12-02 19:42:51 +08:00
feat: add direct P2P screen sharing signaling
This commit is contained in:
1 parent
dc63f4b45b
commit
d75bdccfd9
7 files changed
+1038
-4
No files matched your search
Generated
+2
-2
@@ -10,7 +10,7 @@
|
||||
"license": "AGPL-3.0-only",
|
||||
"dependencies": {
|
||||
"@discordjs/opus": "^0.10.0",
|
||||
"@echosixhiya/teamspeak-client": "git+https://github.com/EchoSixHIYA/teamspeak-js.git#0fd526637c44b9ddc83ea89793aca76765399a6a",
|
||||
"@echosixhiya/teamspeak-client": "git+https://github.com/EchoSixHIYA/teamspeak-js.git#be882e6a4ba12e0938fff2d06bdcc5b3bedeb232",
|
||||
"express": "^5.2.1",
|
||||
"pino": "^10.3.1",
|
||||
"werift": "0.24.4",
|
||||
@@ -63,7 +63,7 @@
|
||||
},
|
||||
"node_modules/@echosixhiya/teamspeak-client": {
|
||||
"version": "0.2.4",
|
||||
"resolved": "git+https://github.com/EchoSixHIYA/teamspeak-js.git#0fd526637c44b9ddc83ea89793aca76765399a6a",
|
||||
"resolved": "git+https://github.com/EchoSixHIYA/teamspeak-js.git#be882e6a4ba12e0938fff2d06bdcc5b3bedeb232",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@noble/curves": "^2.0.1"
|
||||
|
||||
+1
-1
@@ -22,7 +22,7 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"@discordjs/opus": "^0.10.0",
|
||||
"@echosixhiya/teamspeak-client": "git+https://github.com/EchoSixHIYA/teamspeak-js.git#0fd526637c44b9ddc83ea89793aca76765399a6a",
|
||||
"@echosixhiya/teamspeak-client": "git+https://github.com/EchoSixHIYA/teamspeak-js.git#be882e6a4ba12e0938fff2d06bdcc5b3bedeb232",
|
||||
"express": "^5.2.1",
|
||||
"pino": "^10.3.1",
|
||||
"werift": "0.24.4",
|
||||
|
||||
@@ -0,0 +1,169 @@
|
||||
/**
|
||||
* Browser ↔ browser screen-share signaling.
|
||||
*
|
||||
* Media never passes through this module. The gateway only authenticates the
|
||||
* connected TeamSpeak session and relays SDP/ICE messages. The browser peers
|
||||
* are deliberately created without STUN/TURN servers; a failed host-candidate
|
||||
* connection is reported to the user instead of silently becoming a relay.
|
||||
*/
|
||||
|
||||
export type ScreenSharePeerSignal =
|
||||
| {
|
||||
kind: "offer" | "answer";
|
||||
sdp: string;
|
||||
}
|
||||
| {
|
||||
kind: "iceCandidate";
|
||||
candidate: string;
|
||||
sdpMid?: string | null;
|
||||
sdpMLineIndex?: number | null;
|
||||
}
|
||||
| {
|
||||
kind: "close";
|
||||
};
|
||||
|
||||
export interface ScreenShareStreamDescription {
|
||||
streamId: string;
|
||||
source: "browser" | "teamspeak";
|
||||
ownerPeerId: string;
|
||||
ownerNickname: string;
|
||||
name: string;
|
||||
audio: boolean;
|
||||
createdAt: number;
|
||||
viewerCount: number;
|
||||
}
|
||||
|
||||
export type ScreenShareClientMessage =
|
||||
| {
|
||||
type: "screenShareList";
|
||||
}
|
||||
| {
|
||||
type: "screenShareStart";
|
||||
requestId?: string;
|
||||
name?: string;
|
||||
audio?: boolean;
|
||||
}
|
||||
| {
|
||||
type: "screenShareStop";
|
||||
requestId?: string;
|
||||
streamId: string;
|
||||
}
|
||||
| {
|
||||
type: "screenShareJoin";
|
||||
requestId?: string;
|
||||
streamId: string;
|
||||
}
|
||||
| {
|
||||
type: "screenShareLeave";
|
||||
requestId?: string;
|
||||
streamId: string;
|
||||
}
|
||||
| {
|
||||
type: "screenShareSignal";
|
||||
streamId: string;
|
||||
targetPeerId: string;
|
||||
signal: ScreenSharePeerSignal;
|
||||
};
|
||||
|
||||
export type ScreenShareMessageParseResult =
|
||||
| ScreenShareClientMessage
|
||||
| { error: { code: string; message: string } };
|
||||
|
||||
const MAX_STREAM_ID_LENGTH = 128;
|
||||
const MAX_PEER_ID_LENGTH = 128;
|
||||
const MAX_NAME_LENGTH = 120;
|
||||
const MAX_SDP_LENGTH = 256 * 1024;
|
||||
const MAX_CANDIDATE_LENGTH = 8 * 1024;
|
||||
|
||||
export function parseScreenShareMessage(raw: string): ScreenShareMessageParseResult | null {
|
||||
let value: unknown;
|
||||
try {
|
||||
value = JSON.parse(raw);
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
if (!isRecord(value) || typeof value.type !== "string" || !value.type.startsWith("screenShare")) return null;
|
||||
const requestId = parseRequestId(value.requestId);
|
||||
if (requestId === false) return invalid("INVALID_SCREEN_SHARE_REQUEST", "屏幕共享请求标识无效");
|
||||
|
||||
switch (value.type) {
|
||||
case "screenShareList":
|
||||
return { type: "screenShareList" };
|
||||
case "screenShareStart": {
|
||||
const name = value.name === undefined ? undefined : parseName(value.name);
|
||||
if (name === false) return invalid("INVALID_SCREEN_SHARE_NAME", "屏幕共享名称无效");
|
||||
if (value.audio !== undefined && typeof value.audio !== "boolean") return invalid("INVALID_SCREEN_SHARE_AUDIO", "共享音频选项无效");
|
||||
return {
|
||||
type: "screenShareStart",
|
||||
...(requestId ? { requestId } : {}),
|
||||
...(name ? { name } : {}),
|
||||
...(value.audio === true ? { audio: true } : {}),
|
||||
};
|
||||
}
|
||||
case "screenShareStop":
|
||||
case "screenShareJoin":
|
||||
case "screenShareLeave": {
|
||||
const streamId = parseIdentifier(value.streamId, MAX_STREAM_ID_LENGTH);
|
||||
if (!streamId) return invalid("INVALID_SCREEN_SHARE_STREAM", "屏幕共享标识无效");
|
||||
return {
|
||||
type: value.type,
|
||||
...(requestId ? { requestId } : {}),
|
||||
streamId,
|
||||
};
|
||||
}
|
||||
case "screenShareSignal": {
|
||||
const streamId = parseIdentifier(value.streamId, MAX_STREAM_ID_LENGTH);
|
||||
const targetPeerId = parseIdentifier(value.targetPeerId, MAX_PEER_ID_LENGTH);
|
||||
const signal = parseSignal(value.signal);
|
||||
if (!streamId) return invalid("INVALID_SCREEN_SHARE_STREAM", "屏幕共享标识无效");
|
||||
if (!targetPeerId) return invalid("INVALID_SCREEN_SHARE_PEER", "屏幕共享对端无效");
|
||||
if (!signal) return invalid("INVALID_SCREEN_SHARE_SIGNAL", "屏幕共享信令无效");
|
||||
return { type: "screenShareSignal", streamId, targetPeerId, signal };
|
||||
}
|
||||
default:
|
||||
return invalid("UNKNOWN_SCREEN_SHARE_MESSAGE", "不支持的屏幕共享消息");
|
||||
}
|
||||
}
|
||||
|
||||
function parseSignal(value: unknown): ScreenSharePeerSignal | null {
|
||||
if (!isRecord(value) || typeof value.kind !== "string") return null;
|
||||
if (value.kind === "close") return { kind: "close" };
|
||||
if (value.kind === "offer" || value.kind === "answer") {
|
||||
if (typeof value.sdp !== "string" || value.sdp.length === 0 || value.sdp.length > MAX_SDP_LENGTH) return null;
|
||||
return { kind: value.kind, sdp: value.sdp };
|
||||
}
|
||||
if (value.kind !== "iceCandidate" || typeof value.candidate !== "string" || value.candidate.length > MAX_CANDIDATE_LENGTH) return null;
|
||||
if (value.sdpMid !== undefined && value.sdpMid !== null && typeof value.sdpMid !== "string") return null;
|
||||
const sdpMLineIndex = value.sdpMLineIndex;
|
||||
if (sdpMLineIndex !== undefined && sdpMLineIndex !== null && (typeof sdpMLineIndex !== "number" || !Number.isInteger(sdpMLineIndex) || sdpMLineIndex < 0 || sdpMLineIndex > 255)) return null;
|
||||
return {
|
||||
kind: "iceCandidate",
|
||||
candidate: value.candidate,
|
||||
...(value.sdpMid === null || typeof value.sdpMid === "string" ? { sdpMid: value.sdpMid } : {}),
|
||||
...(sdpMLineIndex === null || typeof sdpMLineIndex === "number" ? { sdpMLineIndex } : {}),
|
||||
};
|
||||
}
|
||||
|
||||
function parseRequestId(value: unknown): string | undefined | false {
|
||||
if (value === undefined) return undefined;
|
||||
return typeof value === "string" && value.length > 0 && value.length <= 64 ? value : false;
|
||||
}
|
||||
|
||||
function parseName(value: unknown): string | false {
|
||||
if (typeof value !== "string") return false;
|
||||
const name = value.trim();
|
||||
return name.length > 0 && name.length <= MAX_NAME_LENGTH ? name : false;
|
||||
}
|
||||
|
||||
function parseIdentifier(value: unknown, maxLength: number): string | null {
|
||||
if (typeof value !== "string" || value.length === 0 || value.length > maxLength) return null;
|
||||
return value;
|
||||
}
|
||||
|
||||
function invalid(code: string, message: string): { error: { code: string; message: string } } {
|
||||
return { error: { code, message } };
|
||||
}
|
||||
|
||||
function isRecord(value: unknown): value is Record<string, unknown> {
|
||||
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
||||
}
|
||||
@@ -12,6 +12,7 @@ import {
|
||||
type VoiceData,
|
||||
type DirectoryClientInfo,
|
||||
type DirectorySnapshot,
|
||||
type RawNotification,
|
||||
type TextMessage,
|
||||
} from "@echosixhiya/teamspeak-client";
|
||||
import type { Logger } from "../logger.js";
|
||||
@@ -46,6 +47,7 @@ const MAX_CLIENT_AVATAR_BYTES = 120 * 1024;
|
||||
|
||||
export type TSDirectorySnapshot = DirectorySnapshot;
|
||||
export type TSDirectoryClient = DirectoryClientInfo;
|
||||
export type TSRawNotification = RawNotification;
|
||||
|
||||
export type TSChatScope = "channel" | "server" | "private";
|
||||
|
||||
@@ -134,6 +136,22 @@ export class TSClient extends EventEmitter {
|
||||
err: error instanceof Error ? error.message : String(error),
|
||||
}, "Could not subscribe to all TeamSpeak channels");
|
||||
}
|
||||
// TS6 stream/screen-share notifications are delivered through the normal
|
||||
// server notification channel. Keep this subscription in the same client
|
||||
// session so a browser can participate in the native TS6 P2P signaling
|
||||
// flow without a second query connection.
|
||||
for (const event of ["server", "channel", "textchannel"] as const) {
|
||||
try {
|
||||
await client.execCommand(`servernotifyregister event=${event}`, 5_000);
|
||||
} catch (error: unknown) {
|
||||
// Older TeamSpeak servers may reject one of the newer event scopes.
|
||||
// This is optional: voice and directory sync must remain available.
|
||||
this.logger.debug({
|
||||
event,
|
||||
err: error instanceof Error ? error.message : String(error),
|
||||
}, "Optional TeamSpeak notification scope unavailable");
|
||||
}
|
||||
}
|
||||
// Directory snapshots are dispatched through two setImmediate layers in
|
||||
// the SDK. Let both flush before reconciling with a direct client-protocol
|
||||
// snapshot so the gateway's first connected state contains every member.
|
||||
@@ -240,6 +258,13 @@ export class TSClient extends EventEmitter {
|
||||
});
|
||||
});
|
||||
|
||||
client.on("rawNotification", (notification: RawNotification) => {
|
||||
this.emit("rawNotification", {
|
||||
name: notification.name,
|
||||
params: { ...notification.params },
|
||||
} satisfies TSRawNotification);
|
||||
});
|
||||
|
||||
client.on("textMessage", (msg) => {
|
||||
this.emit("textMessage", toTSChatMessage(msg));
|
||||
});
|
||||
@@ -373,6 +398,16 @@ export class TSClient extends EventEmitter {
|
||||
return this.client.execCommandWithResponse(command, timeoutMs);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a TeamSpeak protocol command whose response is delivered later as a
|
||||
* notification (for example setupstream/streamsignaling). The command is
|
||||
* assembled by the trusted server-side stream adapter, never by the browser.
|
||||
*/
|
||||
async sendProtocolCommand(command: string): Promise<void> {
|
||||
if (!this.client || !this.connected) throw new Error("TeamSpeak session is not ready");
|
||||
await this.client.sendCommandNoWait(command);
|
||||
}
|
||||
|
||||
getIdentityString(): string {
|
||||
return this.identity.toString();
|
||||
}
|
||||
|
||||
+366
-1
@@ -1,10 +1,11 @@
|
||||
import { WebSocketServer, WebSocket } from "ws";
|
||||
import type { IncomingMessage, Server } from "node:http";
|
||||
import { createRequire } from "node:module";
|
||||
import { randomUUID } from "node:crypto";
|
||||
import { isIP } from "node:net";
|
||||
import { identityFromString } from "@echosixhiya/teamspeak-client";
|
||||
import { DirectorySynchronizer } from "./directory-sync.js";
|
||||
import { TSClient, type TSDirectorySnapshot, type TSVoiceData } from "./ts-client.js";
|
||||
import { TSClient, type TSDirectorySnapshot, type TSVoiceData, type TSRawNotification } from "./ts-client.js";
|
||||
import type { Logger as LoggerType } from "../logger.js";
|
||||
import { clientConnectionFailureCode, describeTeamSpeakError, normalizeTeamSpeakError, teamSpeakServerErrorCode, type WebSpeakError } from "../errors.js";
|
||||
import { formatTeamSpeakTarget, teamSpeakTargetKey, type TeamSpeakTarget } from "../domain/teamspeak-target.js";
|
||||
@@ -16,6 +17,7 @@ import { isRecoverable, reconnectDelayMs, reconnectWindowOpen } from "./reconnec
|
||||
import { WebRtcAudioSession, type WebRtcAudioOptions, type WebRtcAudioStats, type WebRtcSessionDescription } from "./webrtc-audio.js";
|
||||
import { pingTeamSpeakSession } from "./network-probe.js";
|
||||
import type { AccelerationRelayOptions, ConfiguredAccelerationRelay } from "./acceleration-relay.js";
|
||||
import { parseScreenShareMessage, type ScreenShareClientMessage, type ScreenSharePeerSignal, type ScreenShareStreamDescription } from "./screen-share.js";
|
||||
|
||||
const require = createRequire(import.meta.url);
|
||||
const { OpusEncoder } = require("@discordjs/opus") as {
|
||||
@@ -155,11 +157,21 @@ interface WebClientEntry {
|
||||
canMoveClients: boolean;
|
||||
movePermissionProbeTimer: ReturnType<typeof setInterval> | null;
|
||||
connectionFailureCode?: string;
|
||||
screenPeerId: string;
|
||||
}
|
||||
|
||||
interface ScreenStreamRecord extends ScreenShareStreamDescription {
|
||||
targetKey: string;
|
||||
channelId: bigint;
|
||||
ownerEntryId: string;
|
||||
viewerEntryIds: Set<string>;
|
||||
sourceClientId?: number;
|
||||
}
|
||||
|
||||
export class VoiceBridge {
|
||||
private readonly sessionManager = new SessionManager();
|
||||
private readonly entries = new Map<string, WebClientEntry>();
|
||||
private readonly screenStreams = new Map<string, ScreenStreamRecord>();
|
||||
private readonly identityLeases = new IdentityLeaseStore();
|
||||
private wss: WebSocketServer | null = null;
|
||||
private heartbeatTimer: ReturnType<typeof setInterval> | null = null;
|
||||
@@ -273,6 +285,7 @@ export class VoiceBridge {
|
||||
lastLatencyProbeAt: 0,
|
||||
canMoveClients: false,
|
||||
movePermissionProbeTimer: null,
|
||||
screenPeerId: entryId,
|
||||
};
|
||||
this.entries.set(entryId, entry!);
|
||||
try {
|
||||
@@ -656,6 +669,10 @@ export class VoiceBridge {
|
||||
if (tsReady && initialStateSent) sendJson({ type: "channelList", channels: entry!.channelTree });
|
||||
});
|
||||
|
||||
tsClient.on("rawNotification", (notification: TSRawNotification) => {
|
||||
this.handleRawScreenNotification(entry!, notification);
|
||||
});
|
||||
|
||||
tsClient.on("voiceData", (data: TSVoiceData) => {
|
||||
const receivedAt = Date.now();
|
||||
if (entry!.audio.tsReceiveLastAt !== null) entry!.audio.tsReceiveMaxGapMs = Math.max(entry!.audio.tsReceiveMaxGapMs, receivedAt - entry!.audio.tsReceiveLastAt);
|
||||
@@ -823,6 +840,19 @@ export class VoiceBridge {
|
||||
}
|
||||
return;
|
||||
}
|
||||
const screenShareMessage = parseScreenShareMessage(rawMessage);
|
||||
if (screenShareMessage) {
|
||||
if ("error" in screenShareMessage) {
|
||||
sendProtocolError(sendJson, screenShareMessage.error.code, screenShareMessage.error.message);
|
||||
return;
|
||||
}
|
||||
if (!tsReady || session.state !== "connected") {
|
||||
sendProtocolError(sendJson, "SESSION_NOT_READY", "TeamSpeak 会话尚未就绪");
|
||||
return;
|
||||
}
|
||||
this.handleScreenShareMessage(entry!, screenShareMessage, sendJson);
|
||||
return;
|
||||
}
|
||||
const command = parseClientCommand(rawMessage);
|
||||
if ("error" in command) {
|
||||
sendProtocolError(sendJson, command.error.code, command.error.message);
|
||||
@@ -927,6 +957,7 @@ export class VoiceBridge {
|
||||
}
|
||||
|
||||
private async cleanupEntry(entry: WebClientEntry, reason: SessionTeardownReason): Promise<void> {
|
||||
this.removeScreenSharePeer(entry.id);
|
||||
if (this.entries.get(entry.id) === entry) this.entries.delete(entry.id);
|
||||
if (entry.reconnectTimer) {
|
||||
clearTimeout(entry.reconnectTimer);
|
||||
@@ -1004,6 +1035,287 @@ export class VoiceBridge {
|
||||
return selected;
|
||||
}
|
||||
|
||||
private handleScreenShareMessage(
|
||||
entry: WebClientEntry,
|
||||
message: ScreenShareClientMessage,
|
||||
sendJson: (message: Record<string, unknown>) => void,
|
||||
): void {
|
||||
if (message.type === "screenShareList") {
|
||||
sendJson({ type: "screenShareList", streams: this.listScreenStreamsFor(entry) });
|
||||
return;
|
||||
}
|
||||
|
||||
if (message.type === "screenShareStart") {
|
||||
if ([...this.screenStreams.values()].some((stream) => stream.source === "browser" && stream.ownerEntryId === entry.id)) {
|
||||
sendJson({ type: "screenShareError", requestId: message.requestId, code: "SCREEN_SHARE_ALREADY_ACTIVE", message: "你已经在共享屏幕" });
|
||||
return;
|
||||
}
|
||||
const stream: ScreenStreamRecord = {
|
||||
streamId: `screen-${randomUUID()}`,
|
||||
source: "browser",
|
||||
ownerPeerId: entry.screenPeerId,
|
||||
ownerNickname: entry.nickname,
|
||||
name: message.name?.trim() || `${entry.nickname} 的屏幕`,
|
||||
audio: message.audio === true,
|
||||
createdAt: Date.now(),
|
||||
viewerCount: 0,
|
||||
targetKey: teamSpeakTargetKey(entry.target),
|
||||
channelId: entry.tsClient.getChannelId(),
|
||||
ownerEntryId: entry.id,
|
||||
viewerEntryIds: new Set(),
|
||||
};
|
||||
this.screenStreams.set(stream.streamId, stream);
|
||||
sendJson({ type: "screenShareStarted", stream: this.describeScreenStream(stream), owner: true });
|
||||
this.broadcastScreenMessage(stream, {
|
||||
type: "screenShareStarted",
|
||||
stream: this.describeScreenStream(stream),
|
||||
owner: false,
|
||||
}, entry.id);
|
||||
return;
|
||||
}
|
||||
|
||||
const stream = this.screenStreams.get(message.streamId);
|
||||
if (!stream) {
|
||||
sendJson({ type: "screenShareError", requestId: "requestId" in message ? message.requestId : undefined, code: "SCREEN_SHARE_NOT_FOUND", message: "屏幕共享已结束或不存在" });
|
||||
return;
|
||||
}
|
||||
if (stream.targetKey !== teamSpeakTargetKey(entry.target)) {
|
||||
sendJson({ type: "screenShareError", requestId: "requestId" in message ? message.requestId : undefined, code: "SCREEN_SHARE_TARGET_MISMATCH", message: "屏幕共享不属于当前服务器" });
|
||||
return;
|
||||
}
|
||||
|
||||
if (message.type === "screenShareStop") {
|
||||
if (stream.ownerEntryId !== entry.id) {
|
||||
sendJson({ type: "screenShareError", requestId: message.requestId, code: "SCREEN_SHARE_NOT_OWNER", message: "只有共享者可以结束共享" });
|
||||
return;
|
||||
}
|
||||
this.stopScreenStream(stream, "owner-stopped");
|
||||
if (message.requestId) sendJson({ type: "screenShareCompleted", requestId: message.requestId });
|
||||
return;
|
||||
}
|
||||
|
||||
if (message.type === "screenShareJoin") {
|
||||
if (stream.ownerEntryId === entry.id) {
|
||||
sendJson({ type: "screenShareError", requestId: message.requestId, code: "SCREEN_SHARE_OWNER_CANNOT_JOIN", message: "共享者不能作为观看者加入自己的共享" });
|
||||
return;
|
||||
}
|
||||
if (!stream.viewerEntryIds.has(entry.id)) stream.viewerEntryIds.add(entry.id);
|
||||
stream.viewerCount = stream.viewerEntryIds.size;
|
||||
sendJson({
|
||||
type: "screenShareJoined",
|
||||
requestId: message.requestId,
|
||||
stream: this.describeScreenStream(stream),
|
||||
ownerPeerId: stream.ownerPeerId,
|
||||
mode: stream.source,
|
||||
});
|
||||
if (stream.source === "browser") {
|
||||
this.sendToEntry(stream.ownerEntryId, {
|
||||
type: "screenShareViewerJoined",
|
||||
streamId: stream.streamId,
|
||||
viewerPeerId: entry.screenPeerId,
|
||||
viewerNickname: entry.nickname,
|
||||
});
|
||||
} else {
|
||||
void this.joinNativeScreenStream(entry, stream, sendJson, message.requestId);
|
||||
}
|
||||
this.broadcastScreenMessage(stream, { type: "screenShareViewerCount", streamId: stream.streamId, viewerCount: stream.viewerCount });
|
||||
return;
|
||||
}
|
||||
|
||||
if (message.type === "screenShareLeave") {
|
||||
this.leaveScreenStream(entry, stream);
|
||||
if (message.requestId) sendJson({ type: "screenShareCompleted", requestId: message.requestId });
|
||||
return;
|
||||
}
|
||||
|
||||
if (message.type === "screenShareSignal") {
|
||||
this.relayScreenShareSignal(entry, stream, message.targetPeerId, message.signal, sendJson);
|
||||
}
|
||||
}
|
||||
|
||||
private listScreenStreamsFor(entry: WebClientEntry): ScreenShareStreamDescription[] {
|
||||
const targetKey = teamSpeakTargetKey(entry.target);
|
||||
return [...this.screenStreams.values()]
|
||||
.filter((stream) => stream.targetKey === targetKey)
|
||||
.map((stream) => this.describeScreenStream(stream));
|
||||
}
|
||||
|
||||
private describeScreenStream(stream: ScreenStreamRecord): ScreenShareStreamDescription {
|
||||
return {
|
||||
streamId: stream.streamId,
|
||||
source: stream.source,
|
||||
ownerPeerId: stream.ownerPeerId,
|
||||
ownerNickname: stream.ownerNickname,
|
||||
name: stream.name,
|
||||
audio: stream.audio,
|
||||
createdAt: stream.createdAt,
|
||||
viewerCount: stream.viewerCount,
|
||||
};
|
||||
}
|
||||
|
||||
private broadcastScreenMessage(stream: ScreenStreamRecord, message: Record<string, unknown>, excludeEntryId?: string): void {
|
||||
for (const candidate of this.entries.values()) {
|
||||
if (candidate.id === excludeEntryId || candidate.target && teamSpeakTargetKey(candidate.target) !== stream.targetKey) continue;
|
||||
this.sendToEntry(candidate.id, message);
|
||||
}
|
||||
}
|
||||
|
||||
private sendToEntry(entryId: string, message: Record<string, unknown>): void {
|
||||
const candidate = this.entries.get(entryId);
|
||||
if (candidate?.ws.readyState === WebSocket.OPEN) candidate.ws.send(JSON.stringify(message));
|
||||
}
|
||||
|
||||
private stopScreenStream(stream: ScreenStreamRecord, reason: string): void {
|
||||
if (!this.screenStreams.delete(stream.streamId)) return;
|
||||
const message = { type: "screenShareStopped", streamId: stream.streamId, reason };
|
||||
this.broadcastScreenMessage(stream, message);
|
||||
for (const viewerEntryId of stream.viewerEntryIds) this.sendToEntry(viewerEntryId, message);
|
||||
stream.viewerEntryIds.clear();
|
||||
stream.viewerCount = 0;
|
||||
}
|
||||
|
||||
private leaveScreenStream(entry: WebClientEntry, stream: ScreenStreamRecord): void {
|
||||
if (!stream.viewerEntryIds.delete(entry.id)) return;
|
||||
stream.viewerCount = stream.viewerEntryIds.size;
|
||||
if (stream.source === "browser") this.sendToEntry(stream.ownerEntryId, { type: "screenShareViewerLeft", streamId: stream.streamId, viewerPeerId: entry.screenPeerId });
|
||||
else {
|
||||
void entry.tsClient.sendProtocolCommand(buildTeamSpeakCommand("removeclientfromstream", {
|
||||
id: stream.streamId,
|
||||
clid: String(entry.tsClient.getClientId()),
|
||||
})).catch(() => undefined);
|
||||
}
|
||||
this.sendToEntry(entry.id, { type: "screenShareLeft", streamId: stream.streamId });
|
||||
this.broadcastScreenMessage(stream, { type: "screenShareViewerCount", streamId: stream.streamId, viewerCount: stream.viewerCount });
|
||||
}
|
||||
|
||||
private relayScreenShareSignal(
|
||||
entry: WebClientEntry,
|
||||
stream: ScreenStreamRecord,
|
||||
targetPeerId: string,
|
||||
signal: ScreenSharePeerSignal,
|
||||
sendJson: (message: Record<string, unknown>) => void,
|
||||
): void {
|
||||
if (stream.source === "teamspeak") {
|
||||
if (!stream.viewerEntryIds.has(entry.id) || targetPeerId !== stream.ownerPeerId) {
|
||||
sendJson({ type: "screenShareError", code: "SCREEN_SHARE_SIGNAL_FORBIDDEN", message: "无权发送该屏幕共享信令" });
|
||||
return;
|
||||
}
|
||||
const targetClientId = stream.sourceClientId;
|
||||
if (!targetClientId) {
|
||||
sendJson({ type: "screenShareError", code: "SCREEN_SHARE_SOURCE_UNAVAILABLE", message: "共享来源暂不可用" });
|
||||
return;
|
||||
}
|
||||
if (signal.kind === "close") {
|
||||
void entry.tsClient.sendProtocolCommand(buildTeamSpeakCommand("removeclientfromstream", { id: stream.streamId, clid: String(entry.tsClient.getClientId()) })).catch(() => undefined);
|
||||
return;
|
||||
}
|
||||
const payload = signal.kind === "iceCandidate"
|
||||
? { cmd: "iceCandidate", args: { sdp: signal.candidate, ...(signal.sdpMid !== undefined ? { mid: signal.sdpMid } : {}), ...(signal.sdpMLineIndex !== undefined ? { mLine: signal.sdpMLineIndex } : {}) } }
|
||||
: { cmd: signal.kind, args: signal.kind === "offer" ? { offer: signal.sdp } : { answer: signal.sdp } };
|
||||
void entry.tsClient.sendProtocolCommand(buildTeamSpeakCommand("streamsignaling", {
|
||||
id: stream.streamId,
|
||||
clid: String(targetClientId),
|
||||
json: JSON.stringify(payload),
|
||||
})).catch((error: unknown) => {
|
||||
sendJson({ type: "screenShareError", code: "SCREEN_SHARE_SIGNAL_FAILED", message: error instanceof Error ? error.message : "屏幕共享信令发送失败" });
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
const owner = this.entries.get(stream.ownerEntryId);
|
||||
const viewer = stream.viewerEntryIds.has(entry.id) ? entry : null;
|
||||
if (!owner || (!viewer && entry.id !== stream.ownerEntryId)) {
|
||||
sendJson({ type: "screenShareError", code: "SCREEN_SHARE_SIGNAL_FORBIDDEN", message: "无权发送该屏幕共享信令" });
|
||||
return;
|
||||
}
|
||||
const targetEntry = targetPeerId === owner.screenPeerId
|
||||
? owner
|
||||
: [...stream.viewerEntryIds].map((id) => this.entries.get(id)).find((candidate) => candidate?.screenPeerId === targetPeerId);
|
||||
if (!targetEntry || targetEntry.id === entry.id) {
|
||||
sendJson({ type: "screenShareError", code: "SCREEN_SHARE_PEER_NOT_FOUND", message: "观看者已离开" });
|
||||
return;
|
||||
}
|
||||
this.sendToEntry(targetEntry.id, { type: "screenShareSignal", streamId: stream.streamId, fromPeerId: entry.screenPeerId, signal });
|
||||
}
|
||||
|
||||
private removeScreenSharePeer(entryId: string): void {
|
||||
for (const stream of [...this.screenStreams.values()]) {
|
||||
if (stream.ownerEntryId === entryId) {
|
||||
this.stopScreenStream(stream, "owner-disconnected");
|
||||
continue;
|
||||
}
|
||||
const entry = this.entries.get(entryId);
|
||||
if (entry && stream.viewerEntryIds.has(entryId)) this.leaveScreenStream(entry, stream);
|
||||
}
|
||||
}
|
||||
|
||||
private async joinNativeScreenStream(
|
||||
entry: WebClientEntry,
|
||||
stream: ScreenStreamRecord,
|
||||
sendJson: (message: Record<string, unknown>) => void,
|
||||
requestId?: string,
|
||||
): Promise<void> {
|
||||
try {
|
||||
await entry.tsClient.sendProtocolCommand(buildTeamSpeakCommand("joinstream", { id: stream.streamId }));
|
||||
sendJson({ type: "screenShareNativeJoinPending", requestId, streamId: stream.streamId, directP2P: true });
|
||||
} catch (error: unknown) {
|
||||
stream.viewerEntryIds.delete(entry.id);
|
||||
stream.viewerCount = stream.viewerEntryIds.size;
|
||||
sendJson({ type: "screenShareError", requestId, code: "SCREEN_SHARE_JOIN_FAILED", message: error instanceof Error ? error.message : "无法加入屏幕共享" });
|
||||
}
|
||||
}
|
||||
|
||||
private handleRawScreenNotification(entry: WebClientEntry, notification: TSRawNotification): void {
|
||||
const params = notification.params;
|
||||
if (notification.name === "notifystreamstarted" || notification.name === "notifystreaminfo") {
|
||||
const streamId = params.id || params.stream_id;
|
||||
const sourceClientId = parseNumber(params.clid);
|
||||
if (!streamId || !sourceClientId) return;
|
||||
const sourceEntry = [...this.entries.values()].find((candidate) => candidate.tsClient.getClientId() === sourceClientId);
|
||||
const current = this.screenStreams.get(streamId);
|
||||
const stream: ScreenStreamRecord = current ?? {
|
||||
streamId,
|
||||
source: "teamspeak",
|
||||
ownerPeerId: `ts-${sourceClientId}`,
|
||||
ownerNickname: params.name || `TeamSpeak 用户 ${sourceClientId}`,
|
||||
name: params.name || "TeamSpeak 屏幕共享",
|
||||
audio: params.audio === "1",
|
||||
createdAt: Date.now(),
|
||||
viewerCount: 0,
|
||||
targetKey: teamSpeakTargetKey(entry.target),
|
||||
channelId: sourceEntry?.tsClient.getChannelId() ?? entry.tsClient.getChannelId(),
|
||||
ownerEntryId: "",
|
||||
viewerEntryIds: new Set(),
|
||||
sourceClientId,
|
||||
};
|
||||
stream.sourceClientId = sourceClientId;
|
||||
stream.ownerNickname = params.name || stream.ownerNickname;
|
||||
stream.name = params.name || stream.name;
|
||||
stream.audio = params.audio === "1";
|
||||
this.screenStreams.set(streamId, stream);
|
||||
this.broadcastScreenMessage(stream, { type: "screenShareStarted", stream: this.describeScreenStream(stream), owner: false });
|
||||
return;
|
||||
}
|
||||
if (notification.name === "notifystreamstopped") {
|
||||
const streamId = params.id || params.stream_id;
|
||||
const stream = streamId ? this.screenStreams.get(streamId) : undefined;
|
||||
if (stream) this.stopScreenStream(stream, "source-stopped");
|
||||
return;
|
||||
}
|
||||
if (notification.name === "notifyrespondjoinstreamrequest" || notification.name === "notifystreamsignaling") {
|
||||
const streamId = params.id || params.stream_id;
|
||||
const stream = streamId ? this.screenStreams.get(streamId) : undefined;
|
||||
if (!stream || stream.source !== "teamspeak" || !stream.viewerEntryIds.has(entry.id)) return;
|
||||
const payload = notification.name === "notifyrespondjoinstreamrequest"
|
||||
? { cmd: "offer", args: { offer: params.offer || "" } }
|
||||
: parseStreamSignalPayload(params.json || params.data || "");
|
||||
if (!payload) return;
|
||||
const signal = toBrowserScreenSignal(payload);
|
||||
if (!signal) return;
|
||||
this.sendToEntry(entry.id, { type: "screenShareSignal", streamId, fromPeerId: stream.ownerPeerId, signal });
|
||||
}
|
||||
}
|
||||
|
||||
private async handleWebRtcOffer(
|
||||
entry: WebClientEntry,
|
||||
offer: WebRtcSessionDescription,
|
||||
@@ -1294,6 +1606,59 @@ function isWebRtcStopMessage(raw: string): boolean {
|
||||
}
|
||||
}
|
||||
|
||||
function parseNumber(value: string | undefined): number | undefined {
|
||||
if (!value || !/^\d+$/.test(value)) return undefined;
|
||||
const parsed = Number(value);
|
||||
return Number.isSafeInteger(parsed) && parsed > 0 ? parsed : undefined;
|
||||
}
|
||||
|
||||
function buildTeamSpeakCommand(command: string, params: Record<string, string>): string {
|
||||
return [command, ...Object.entries(params).map(([key, value]) => `${key}=${escapeTeamSpeakValue(value)}`)].join(" ");
|
||||
}
|
||||
|
||||
function parseStreamSignalPayload(raw: string): { cmd: string; args: Record<string, unknown> } | null {
|
||||
try {
|
||||
const value: unknown = JSON.parse(raw);
|
||||
if (!isRecord(value) || typeof value.cmd !== "string" || !isRecord(value.args)) return null;
|
||||
return { cmd: value.cmd, args: value.args };
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
function toBrowserScreenSignal(payload: { cmd: string; args: Record<string, unknown> }): ScreenSharePeerSignal | null {
|
||||
const args = payload.args;
|
||||
if (payload.cmd === "offer" || payload.cmd === "reconnectOffer") {
|
||||
const sdp = typeof args.offer === "string" ? args.offer : typeof args.sdp === "string" ? args.sdp : "";
|
||||
return sdp ? { kind: "offer", sdp } : null;
|
||||
}
|
||||
if (payload.cmd === "answer") {
|
||||
const sdp = typeof args.answer === "string" ? args.answer : typeof args.sdp === "string" ? args.sdp : "";
|
||||
return sdp ? { kind: "answer", sdp } : null;
|
||||
}
|
||||
if (payload.cmd === "iceCandidate") {
|
||||
const candidate = typeof args.sdp === "string" ? args.sdp : typeof args.candidate === "string" ? args.candidate : "";
|
||||
if (!candidate) return null;
|
||||
return {
|
||||
kind: "iceCandidate",
|
||||
candidate,
|
||||
...(typeof args.mid === "string" ? { sdpMid: args.mid } : {}),
|
||||
...(typeof args.mLine === "number" ? { sdpMLineIndex: args.mLine } : {}),
|
||||
};
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function escapeTeamSpeakValue(value: string): string {
|
||||
return value
|
||||
.replace(/\\/g, "\\\\")
|
||||
.replace(/ /g, "\\s")
|
||||
.replace(/\//g, "\\/")
|
||||
.replace(/\|/g, "\\p")
|
||||
.replace(/\n/g, "\\n")
|
||||
.replace(/\r/g, "\\r");
|
||||
}
|
||||
|
||||
function isRecord(value: unknown): value is Record<string, unknown> {
|
||||
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
||||
}
|
||||
|
||||
@@ -29,6 +29,25 @@ export interface VoiceState {
|
||||
channelSwitchedChannelId: string;
|
||||
}
|
||||
|
||||
export interface ScreenShareStream {
|
||||
streamId: string;
|
||||
source: "browser" | "teamspeak";
|
||||
ownerPeerId: string;
|
||||
ownerNickname: string;
|
||||
name: string;
|
||||
audio: boolean;
|
||||
createdAt: number;
|
||||
viewerCount: number;
|
||||
}
|
||||
|
||||
export interface ScreenShareSignal {
|
||||
kind: "offer" | "answer" | "iceCandidate" | "close";
|
||||
sdp?: string;
|
||||
candidate?: string;
|
||||
sdpMid?: string | null;
|
||||
sdpMLineIndex?: number | null;
|
||||
}
|
||||
|
||||
export interface ChannelMember {
|
||||
id: number;
|
||||
nickname: string;
|
||||
@@ -277,6 +296,18 @@ export function useVoiceWebSocket() {
|
||||
const accompanimentSupported = ref(typeof navigator !== "undefined" && Boolean(navigator.mediaDevices?.getDisplayMedia));
|
||||
const accompanimentErrorCode = ref<"" | "unsupported" | "needsWebRtc" | "noAudio" | "permission">("");
|
||||
let accompanimentStream: MediaStream | null = null;
|
||||
const screenShareStreams = reactive<ScreenShareStream[]>([]);
|
||||
const screenShareActive = ref(false);
|
||||
const screenShareActiveStreamId = ref("");
|
||||
const screenShareViewing = ref(false);
|
||||
const screenShareViewingStreamId = ref("");
|
||||
const screenShareRemoteStream = ref<MediaStream | null>(null);
|
||||
const screenShareError = ref("");
|
||||
const screenShareRemoteVolume = ref(1);
|
||||
let screenShareLocalStream: MediaStream | null = null;
|
||||
const screenSharePeers = new Map<string, RTCPeerConnection>();
|
||||
const screenSharePendingIce = new Map<string, RTCIceCandidateInit[]>();
|
||||
const screenSharePeerStreams = new Map<string, MediaStream>();
|
||||
let webrtcMixDestination: MediaStreamAudioDestinationNode | null = null;
|
||||
let webrtcMixMicSource: MediaStreamAudioSourceNode | null = null;
|
||||
let webrtcMixMicGain: GainNode | null = null;
|
||||
@@ -1549,6 +1580,7 @@ export function useVoiceWebSocket() {
|
||||
stopMicrophone();
|
||||
clearMicrophoneError();
|
||||
clearAudioNotice();
|
||||
stopScreenShareTransport(!preserveConnection);
|
||||
const socket = ws.value;
|
||||
ws.value = null;
|
||||
stopWebRtcTransport();
|
||||
@@ -1594,6 +1626,257 @@ export function useVoiceWebSocket() {
|
||||
}
|
||||
}
|
||||
|
||||
function sendScreenShareMessage(message: Record<string, unknown>): void {
|
||||
if (ws.value?.readyState === WebSocket.OPEN) ws.value.send(JSON.stringify(message));
|
||||
}
|
||||
|
||||
function closeScreenSharePeer(peerId: string): void {
|
||||
const peer = screenSharePeers.get(peerId);
|
||||
screenSharePeers.delete(peerId);
|
||||
screenSharePendingIce.delete(peerId);
|
||||
screenSharePeerStreams.delete(peerId);
|
||||
try { peer?.close(); } catch { /* closing an already closed peer is harmless */ }
|
||||
}
|
||||
|
||||
function closeAllScreenSharePeers(): void {
|
||||
for (const peerId of [...screenSharePeers.keys()]) closeScreenSharePeer(peerId);
|
||||
}
|
||||
|
||||
function setScreenShareP2PError(message = "直连 P2P 失败,当前网络无法建立浏览器之间的直接连接") {
|
||||
screenShareError.value = message;
|
||||
}
|
||||
|
||||
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: [] });
|
||||
screenSharePeers.set(peerId, peer);
|
||||
if (role === "owner") {
|
||||
for (const track of screenShareLocalStream?.getTracks() ?? []) peer.addTrack(track, screenShareLocalStream!);
|
||||
} else {
|
||||
peer.addTransceiver("video", { direction: "recvonly" });
|
||||
const stream = screenShareStreams.find((candidate) => candidate.streamId === streamId);
|
||||
if (stream?.audio) peer.addTransceiver("audio", { direction: "recvonly" });
|
||||
}
|
||||
peer.onicecandidate = (event) => {
|
||||
if (!event.candidate) return;
|
||||
const candidate = event.candidate;
|
||||
sendScreenShareMessage({
|
||||
type: "screenShareSignal",
|
||||
streamId,
|
||||
targetPeerId: peerId,
|
||||
signal: {
|
||||
kind: "iceCandidate",
|
||||
candidate: candidate.candidate,
|
||||
sdpMid: candidate.sdpMid,
|
||||
sdpMLineIndex: candidate.sdpMLineIndex,
|
||||
},
|
||||
});
|
||||
};
|
||||
peer.ontrack = (event) => {
|
||||
if (role !== "viewer") return;
|
||||
const remote = event.streams[0] ?? screenSharePeerStreams.get(peerId) ?? new MediaStream();
|
||||
if (!event.streams[0]) remote.addTrack(event.track);
|
||||
screenSharePeerStreams.set(peerId, remote);
|
||||
screenShareRemoteStream.value = remote;
|
||||
screenShareViewing.value = true;
|
||||
};
|
||||
peer.onconnectionstatechange = () => {
|
||||
if (peer.connectionState === "failed" || peer.connectionState === "disconnected") {
|
||||
setScreenShareP2PError();
|
||||
}
|
||||
if (peer.connectionState === "closed" && screenSharePeers.get(peerId) === peer) closeScreenSharePeer(peerId);
|
||||
};
|
||||
return peer;
|
||||
}
|
||||
|
||||
async function flushScreenShareCandidates(peerId: string, peer: RTCPeerConnection): Promise<void> {
|
||||
const pending = screenSharePendingIce.get(peerId) ?? [];
|
||||
screenSharePendingIce.delete(peerId);
|
||||
for (const candidate of pending) {
|
||||
try { await peer.addIceCandidate(candidate); } catch { /* an obsolete candidate can be ignored */ }
|
||||
}
|
||||
}
|
||||
|
||||
async function startScreenShareViewer(stream: ScreenShareStream): Promise<void> {
|
||||
closeAllScreenSharePeers();
|
||||
screenShareRemoteStream.value = null;
|
||||
screenShareViewing.value = true;
|
||||
screenShareViewingStreamId.value = stream.streamId;
|
||||
screenShareError.value = "";
|
||||
const peer = createScreenSharePeer(stream.streamId, stream.ownerPeerId, "viewer");
|
||||
if (stream.source === "teamspeak") return;
|
||||
try {
|
||||
const offer = await peer.createOffer();
|
||||
await peer.setLocalDescription(offer);
|
||||
sendScreenShareMessage({
|
||||
type: "screenShareSignal",
|
||||
streamId: stream.streamId,
|
||||
targetPeerId: stream.ownerPeerId,
|
||||
signal: { kind: "offer", sdp: offer.sdp ?? "" },
|
||||
});
|
||||
} catch {
|
||||
setScreenShareP2PError("无法创建屏幕共享直连请求,请重试");
|
||||
closeScreenSharePeer(stream.ownerPeerId);
|
||||
}
|
||||
}
|
||||
|
||||
async function handleScreenShareSignal(streamId: string, fromPeerId: string, signal: ScreenShareSignal): Promise<void> {
|
||||
const stream = screenShareStreams.find((candidate) => candidate.streamId === streamId);
|
||||
if (!stream) return;
|
||||
if (signal.kind === "close") {
|
||||
closeScreenSharePeer(fromPeerId);
|
||||
if (screenShareViewingStreamId.value === streamId) {
|
||||
screenShareViewing.value = false;
|
||||
screenShareViewingStreamId.value = "";
|
||||
screenShareRemoteStream.value = null;
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (signal.kind === "iceCandidate") {
|
||||
if (!signal.candidate) return;
|
||||
const peer = screenSharePeers.get(fromPeerId);
|
||||
const candidate: RTCIceCandidateInit = {
|
||||
candidate: signal.candidate,
|
||||
...(signal.sdpMid !== undefined ? { sdpMid: signal.sdpMid } : {}),
|
||||
...(signal.sdpMLineIndex !== undefined ? { sdpMLineIndex: signal.sdpMLineIndex } : {}),
|
||||
};
|
||||
if (!peer?.remoteDescription) {
|
||||
screenSharePendingIce.set(fromPeerId, [...(screenSharePendingIce.get(fromPeerId) ?? []), candidate]);
|
||||
return;
|
||||
}
|
||||
try { await peer.addIceCandidate(candidate); } catch { /* stale ICE is not fatal */ }
|
||||
return;
|
||||
}
|
||||
|
||||
if (stream.source === "browser" && stream.ownerPeerId === fromPeerId && signal.kind === "answer") {
|
||||
const peer = screenSharePeers.get(fromPeerId);
|
||||
if (!peer || !signal.sdp) return;
|
||||
try {
|
||||
await peer.setRemoteDescription({ type: "answer", sdp: signal.sdp });
|
||||
await flushScreenShareCandidates(fromPeerId, peer);
|
||||
} catch {
|
||||
setScreenShareP2PError("观看端无法完成屏幕共享直连协商");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (stream.source === "teamspeak" && screenShareViewingStreamId.value === streamId && signal.kind === "offer") {
|
||||
const peer = screenSharePeers.get(fromPeerId) ?? createScreenSharePeer(streamId, fromPeerId, "viewer");
|
||||
if (!signal.sdp) return;
|
||||
try {
|
||||
await peer.setRemoteDescription({ type: "offer", sdp: signal.sdp });
|
||||
await flushScreenShareCandidates(fromPeerId, peer);
|
||||
const answer = await peer.createAnswer();
|
||||
await peer.setLocalDescription(answer);
|
||||
sendScreenShareMessage({ type: "screenShareSignal", streamId, targetPeerId: fromPeerId, signal: { kind: "answer", sdp: answer.sdp ?? "" } });
|
||||
} catch {
|
||||
setScreenShareP2PError("无法回复 TeamSpeak 屏幕共享的直连请求");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (screenShareActiveStreamId.value === streamId && stream.ownerPeerId === screenShareLocalPeerId()) {
|
||||
const peer = screenSharePeers.get(fromPeerId) ?? createScreenSharePeer(streamId, fromPeerId, "owner");
|
||||
if (signal.kind !== "offer" || !signal.sdp) return;
|
||||
try {
|
||||
await peer.setRemoteDescription({ type: "offer", sdp: signal.sdp });
|
||||
await flushScreenShareCandidates(fromPeerId, peer);
|
||||
const answer = await peer.createAnswer();
|
||||
await peer.setLocalDescription(answer);
|
||||
sendScreenShareMessage({ type: "screenShareSignal", streamId, targetPeerId: fromPeerId, signal: { kind: "answer", sdp: answer.sdp ?? "" } });
|
||||
} catch {
|
||||
setScreenShareP2PError("共享端无法完成观看者的直连协商");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// The owner peer id is generated by the gateway and is returned in the
|
||||
// screenShareStarted event; the active stream's owner id is therefore the
|
||||
// only stable local-owner marker available to the browser.
|
||||
function screenShareLocalPeerId(): string {
|
||||
const active = screenShareStreams.find((stream) => stream.streamId === screenShareActiveStreamId.value);
|
||||
return active?.ownerPeerId ?? "";
|
||||
}
|
||||
|
||||
async function startScreenShare(audio = true): Promise<void> {
|
||||
if (ws.value?.readyState !== WebSocket.OPEN || screenShareActive.value) return;
|
||||
if (!navigator.mediaDevices?.getDisplayMedia) {
|
||||
screenShareError.value = "当前浏览器不支持屏幕共享";
|
||||
return;
|
||||
}
|
||||
screenShareError.value = "";
|
||||
try {
|
||||
const stream = await navigator.mediaDevices.getDisplayMedia({ video: { frameRate: { ideal: 30, max: 60 } }, audio });
|
||||
if (!stream.getVideoTracks().length) throw new Error("NO_VIDEO_TRACK");
|
||||
screenShareLocalStream = stream;
|
||||
screenShareActive.value = true;
|
||||
for (const track of stream.getTracks()) track.addEventListener("ended", () => { void stopScreenShare(); }, { once: true });
|
||||
sendScreenShareMessage({ type: "screenShareStart", audio: stream.getAudioTracks().length > 0, name: "我的屏幕" });
|
||||
} catch (error: unknown) {
|
||||
screenShareLocalStream?.getTracks().forEach((track) => track.stop());
|
||||
screenShareLocalStream = null;
|
||||
if (error instanceof DOMException && error.name === "NotAllowedError") screenShareError.value = "你取消了屏幕共享或浏览器未授予权限";
|
||||
else screenShareError.value = "无法开始屏幕共享,请检查浏览器权限";
|
||||
}
|
||||
}
|
||||
|
||||
function stopScreenShare(): void {
|
||||
if (screenShareActive.value && screenShareActiveStreamId.value) sendScreenShareMessage({ type: "screenShareStop", streamId: screenShareActiveStreamId.value });
|
||||
closeAllScreenSharePeers();
|
||||
screenShareLocalStream?.getTracks().forEach((track) => track.stop());
|
||||
screenShareLocalStream = null;
|
||||
screenShareActive.value = false;
|
||||
screenShareActiveStreamId.value = "";
|
||||
}
|
||||
|
||||
function joinScreenShare(streamId: string): void {
|
||||
screenShareError.value = "";
|
||||
sendScreenShareMessage({ type: "screenShareJoin", streamId });
|
||||
}
|
||||
|
||||
function leaveScreenShare(): void {
|
||||
if (screenShareViewingStreamId.value) sendScreenShareMessage({ type: "screenShareLeave", streamId: screenShareViewingStreamId.value });
|
||||
closeAllScreenSharePeers();
|
||||
screenShareViewing.value = false;
|
||||
screenShareViewingStreamId.value = "";
|
||||
screenShareRemoteStream.value = null;
|
||||
}
|
||||
|
||||
function stopScreenShareTransport(sendStop: boolean): void {
|
||||
if (sendStop && screenShareActive.value && screenShareActiveStreamId.value) sendScreenShareMessage({ type: "screenShareStop", streamId: screenShareActiveStreamId.value });
|
||||
closeAllScreenSharePeers();
|
||||
screenShareLocalStream?.getTracks().forEach((track) => track.stop());
|
||||
screenShareLocalStream = null;
|
||||
screenShareActive.value = false;
|
||||
screenShareActiveStreamId.value = "";
|
||||
screenShareViewing.value = false;
|
||||
screenShareViewingStreamId.value = "";
|
||||
screenShareRemoteStream.value = null;
|
||||
screenShareStreams.length = 0;
|
||||
}
|
||||
|
||||
function upsertScreenShareStream(raw: unknown): ScreenShareStream | null {
|
||||
if (!raw || typeof raw !== "object") return null;
|
||||
const value = raw as Partial<ScreenShareStream>;
|
||||
if (typeof value.streamId !== "string" || typeof value.ownerPeerId !== "string") return null;
|
||||
const stream: ScreenShareStream = {
|
||||
streamId: value.streamId,
|
||||
source: value.source === "teamspeak" ? "teamspeak" : "browser",
|
||||
ownerPeerId: value.ownerPeerId,
|
||||
ownerNickname: typeof value.ownerNickname === "string" ? value.ownerNickname : "TeamSpeak 用户",
|
||||
name: typeof value.name === "string" ? value.name : "屏幕共享",
|
||||
audio: value.audio === true,
|
||||
createdAt: typeof value.createdAt === "number" ? value.createdAt : Date.now(),
|
||||
viewerCount: typeof value.viewerCount === "number" ? value.viewerCount : 0,
|
||||
};
|
||||
const index = screenShareStreams.findIndex((candidate) => candidate.streamId === stream.streamId);
|
||||
if (index >= 0) screenShareStreams.splice(index, 1, stream);
|
||||
else screenShareStreams.push(stream);
|
||||
return stream;
|
||||
}
|
||||
|
||||
function handleMessage(msg: any): void {
|
||||
switch (msg.type) {
|
||||
case "connected":
|
||||
@@ -1634,6 +1917,64 @@ export function useVoiceWebSocket() {
|
||||
} else {
|
||||
void ensureMicrophone().catch((error: unknown) => { setMicrophoneError(error); });
|
||||
}
|
||||
sendScreenShareMessage({ type: "screenShareList" });
|
||||
break;
|
||||
case "screenShareList":
|
||||
screenShareStreams.length = 0;
|
||||
if (Array.isArray(msg.streams)) for (const raw of msg.streams) upsertScreenShareStream(raw);
|
||||
break;
|
||||
case "screenShareStarted": {
|
||||
const stream = upsertScreenShareStream(msg.stream);
|
||||
if (!stream) break;
|
||||
if (msg.owner === true) {
|
||||
screenShareActive.value = true;
|
||||
screenShareActiveStreamId.value = stream.streamId;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "screenShareViewerCount": {
|
||||
const stream = screenShareStreams.find((candidate) => candidate.streamId === String(msg.streamId || ""));
|
||||
if (stream && typeof msg.viewerCount === "number") stream.viewerCount = Math.max(0, Math.floor(msg.viewerCount));
|
||||
break;
|
||||
}
|
||||
case "screenShareStopped": {
|
||||
const streamId = String(msg.streamId || "");
|
||||
const index = screenShareStreams.findIndex((candidate) => candidate.streamId === streamId);
|
||||
if (index >= 0) screenShareStreams.splice(index, 1);
|
||||
if (screenShareActiveStreamId.value === streamId) {
|
||||
closeAllScreenSharePeers();
|
||||
screenShareActive.value = false;
|
||||
screenShareActiveStreamId.value = "";
|
||||
screenShareLocalStream?.getTracks().forEach((track) => track.stop());
|
||||
screenShareLocalStream = null;
|
||||
}
|
||||
if (screenShareViewingStreamId.value === streamId) {
|
||||
closeAllScreenSharePeers();
|
||||
screenShareViewing.value = false;
|
||||
screenShareViewingStreamId.value = "";
|
||||
screenShareRemoteStream.value = null;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "screenShareJoined": {
|
||||
const stream = upsertScreenShareStream(msg.stream);
|
||||
if (!stream) break;
|
||||
void startScreenShareViewer(stream);
|
||||
break;
|
||||
}
|
||||
case "screenShareSignal":
|
||||
if (typeof msg.streamId === "string" && typeof msg.fromPeerId === "string" && msg.signal) {
|
||||
void handleScreenShareSignal(msg.streamId, msg.fromPeerId, msg.signal as ScreenShareSignal);
|
||||
}
|
||||
break;
|
||||
case "screenShareViewerLeft":
|
||||
if (typeof msg.viewerPeerId === "string") closeScreenSharePeer(msg.viewerPeerId);
|
||||
break;
|
||||
case "screenShareLeft":
|
||||
if (screenShareViewingStreamId.value === String(msg.streamId || "")) leaveScreenShare();
|
||||
break;
|
||||
case "screenShareError":
|
||||
screenShareError.value = String(msg.message || "屏幕共享操作失败");
|
||||
break;
|
||||
case "memberEnter":
|
||||
if (!members.some((member) => member.id === msg.id)) {
|
||||
@@ -1730,6 +2071,7 @@ export function useVoiceWebSocket() {
|
||||
state.reconnectFailed = false;
|
||||
if (!state.reconnecting) state.error = "TeamSpeak 连接已断开";
|
||||
stopWebRtcTransport();
|
||||
stopScreenShareTransport(false);
|
||||
stopMicrophone();
|
||||
whisperTargetIds.clear();
|
||||
whisperActive.value = false;
|
||||
@@ -1742,6 +2084,7 @@ export function useVoiceWebSocket() {
|
||||
state.reconnectFailed = false;
|
||||
state.reconnectAttempt = Number(msg.attempt) || state.reconnectAttempt + 1;
|
||||
stopWebRtcTransport();
|
||||
stopScreenShareTransport(false);
|
||||
stopMicrophone();
|
||||
whisperTargetIds.clear();
|
||||
whisperActive.value = false;
|
||||
@@ -1758,6 +2101,7 @@ export function useVoiceWebSocket() {
|
||||
state.reconnectFailed = true;
|
||||
state.errorCode = normalizedClientErrorCode(msg.code);
|
||||
state.error = connectionFailureMessage(state.errorCode, msg.detail);
|
||||
stopScreenShareTransport(false);
|
||||
whisperTargetIds.clear();
|
||||
whisperActive.value = false;
|
||||
break;
|
||||
@@ -1771,6 +2115,7 @@ export function useVoiceWebSocket() {
|
||||
state.reconnectFailed = false;
|
||||
state.errorCode = normalizedClientErrorCode(msg.code);
|
||||
state.error = connectionFailureMessage(state.errorCode, msg.detail);
|
||||
stopScreenShareTransport(false);
|
||||
whisperTargetIds.clear();
|
||||
whisperActive.value = false;
|
||||
break;
|
||||
@@ -2102,6 +2447,14 @@ export function useVoiceWebSocket() {
|
||||
accompanimentActive,
|
||||
accompanimentSupported,
|
||||
accompanimentErrorCode,
|
||||
screenShareStreams,
|
||||
screenShareActive,
|
||||
screenShareActiveStreamId,
|
||||
screenShareViewing,
|
||||
screenShareViewingStreamId,
|
||||
screenShareRemoteStream,
|
||||
screenShareError,
|
||||
screenShareRemoteVolume,
|
||||
setVolume,
|
||||
setInputVolume,
|
||||
setNoiseSuppressionEnabled,
|
||||
@@ -2132,6 +2485,10 @@ export function useVoiceWebSocket() {
|
||||
ensureMicrophone,
|
||||
startAccompaniment,
|
||||
stopAccompaniment,
|
||||
startScreenShare,
|
||||
stopScreenShare,
|
||||
joinScreenShare,
|
||||
leaveScreenShare,
|
||||
checkSupport,
|
||||
clearError,
|
||||
measureLatency,
|
||||
|
||||
@@ -110,6 +110,7 @@
|
||||
</section>
|
||||
</div>
|
||||
<button class="header-action" :title="t('copyInvite')" @click="doShare"><Icon name="share" :size="18" /></button>
|
||||
<button type="button" class="header-action screen-share-header-button" :class="{ active: screenShareActive || screenShareViewing }" :title="t('screenShare')" :aria-label="t('screenShare')" :aria-pressed="screenSharePanelOpen" @click.stop="screenSharePanelOpen = !screenSharePanelOpen"><Icon name="monitor" :size="18" /></button>
|
||||
<button v-if="isMobileViewport" class="header-action microphone-header-toggle" :class="{ muted: microphoneMuted }" :title="microphoneMuted ? t('unmuteMic') : t('muteMic')" :aria-label="microphoneMuted ? t('microphoneMuted') : t('microphoneActive')" :aria-pressed="!microphoneMuted" @click="toggleMicrophone"><Icon :name="microphoneMuted ? 'mic-off' : 'mic'" :size="18" /></button>
|
||||
<button v-if="isMobileViewport" class="header-action" :title="t('audioSettings')" :aria-label="t('audioSettings')" @click="settingsOpen = true"><Icon name="settings" :size="18" /></button>
|
||||
<button type="button" class="header-action theme-toggle" :title="themeLabel" :aria-label="themeLabel" @click="cycleTheme"><Icon :name="themeIcon" :size="17" /></button>
|
||||
@@ -138,6 +139,17 @@
|
||||
<div class="hero-visual" aria-hidden="true"><div class="orbit orbit-a"></div><div class="orbit orbit-b"></div><div class="hero-wave"><i v-for="bar in heroBars" :key="bar" :style="{ height: `${bar}px` }"></i></div></div>
|
||||
</section>
|
||||
|
||||
<section v-if="screenSharePanelOpen || screenShareStreams.length || screenShareActive || screenShareViewing" class="screen-share-section">
|
||||
<header class="screen-share-header"><div><span class="section-kicker">{{ t('screenShare') }}</span><h2><Icon name="monitor" :size="20" /> {{ t('screenShareTitle') }}</h2></div><button v-if="screenShareActive" type="button" class="secondary-button" @click="stopScreenShare"><Icon name="close" :size="15" /> {{ t('stopScreenShare') }}</button><button v-else type="button" class="primary-button screen-share-start" @click="startScreenShare(true)"><Icon name="monitor" :size="15" /> {{ t('startScreenShare') }}</button></header>
|
||||
<div v-if="screenShareError" class="screen-share-error" role="status"><Icon name="info" :size="16" /> {{ screenShareError }}</div>
|
||||
<div v-if="screenShareViewing" class="screen-share-viewer-card">
|
||||
<div class="screen-share-video-wrap"><video ref="screenVideoEl" class="screen-share-video" autoplay playsinline :muted="screenShareRemoteVolume === 0"></video><div class="screen-share-viewer-badge"><Icon name="users" :size="14" /> {{ t('watchingScreenShare') }}</div></div>
|
||||
<div class="screen-share-viewer-controls"><span>{{ t('screenShareVolume') }}</span><input type="range" min="0" max="100" :value="screenShareRemoteVolume * 100" :aria-label="t('screenShareVolume')" @input="onScreenShareVolume" /><strong>{{ Math.round(screenShareRemoteVolume * 100) }}%</strong><button type="button" class="text-button" @click="leaveScreenShare">{{ t('leaveScreenShare') }}</button></div>
|
||||
</div>
|
||||
<div v-if="screenShareActive" class="screen-share-owner-status"><span class="live-pill"><i></i> {{ t('sharingScreen') }}</span><span>{{ t('directP2POnly') }}</span></div>
|
||||
<div v-if="screenShareStreams.length" class="screen-share-stream-list"><article v-for="stream in screenShareStreams" :key="stream.streamId" class="screen-share-stream-item"><div class="screen-share-stream-icon"><Icon name="monitor" :size="18" /></div><div class="screen-share-stream-copy"><strong>{{ stream.name }}</strong><span>{{ stream.ownerNickname }} · {{ stream.source === 'teamspeak' ? t('teamSpeakSource') : t('browserSource') }}<small v-if="stream.audio"> · {{ t('sharedAudio') }}</small></span></div><button v-if="!screenShareViewing && stream.streamId !== screenShareActiveStreamId" type="button" class="secondary-button" @click="joinScreenShare(stream.streamId)">{{ t('watchScreenShare') }}</button><span v-else-if="stream.streamId === screenShareViewingStreamId" class="screen-share-watching-label">{{ t('watching') }}</span></article></div><div v-else-if="!screenShareActive" class="screen-share-empty"><Icon name="monitor" :size="18" /> {{ t('noScreenShares') }}</div>
|
||||
</section>
|
||||
|
||||
<section :class="['voice-section', { 'mobile-section-hidden': mobileSection !== 'voice' }]">
|
||||
<div class="section-heading"><div><span class="section-kicker">{{ t('voiceActivity') }}</span><h2>{{ t('speakingNow') }}</h2></div><span class="section-counter">{{ t('onlineShort', { count: currentMembers.length }) }}</span></div>
|
||||
<div v-if="currentMembers.length" class="voice-grid">
|
||||
@@ -406,8 +418,20 @@ const {
|
||||
setMicrophoneMuted,
|
||||
accompanimentActive,
|
||||
accompanimentErrorCode,
|
||||
screenShareStreams,
|
||||
screenShareActive,
|
||||
screenShareActiveStreamId,
|
||||
screenShareViewing,
|
||||
screenShareViewingStreamId,
|
||||
screenShareRemoteStream,
|
||||
screenShareError,
|
||||
screenShareRemoteVolume,
|
||||
startAccompaniment,
|
||||
stopAccompaniment,
|
||||
startScreenShare,
|
||||
stopScreenShare,
|
||||
joinScreenShare,
|
||||
leaveScreenShare,
|
||||
checkSupport,
|
||||
clearError,
|
||||
measureLatency,
|
||||
@@ -450,6 +474,8 @@ const qqJoinUrl = "http://qm.qq.com/cgi-bin/qm/qr?_wv=1027&k=yhumUMDD9PmyYFWdXWU
|
||||
const audioSettingsError = ref("");
|
||||
const toast = ref("");
|
||||
const chatListEl = ref<HTMLElement | null>(null);
|
||||
const screenVideoEl = ref<HTMLVideoElement | null>(null);
|
||||
const screenSharePanelOpen = ref(false);
|
||||
const localPersistenceAvailable = isLocalPersistenceAvailable();
|
||||
const identityReady = ref(!localPersistenceAvailable);
|
||||
const chatTab = ref<"channel" | "server" | "private" | "events">("channel");
|
||||
@@ -581,6 +607,21 @@ const translations: Record<string, Record<string, string>> = {
|
||||
accompanimentNoAudio: "所选来源没有可共享音频,请重新选择并勾选共享音频",
|
||||
accompanimentPermissionDenied: "无法获取伴奏音频,请允许屏幕共享并勾选共享音频",
|
||||
accompanimentUnsupported: "当前浏览器不支持伴奏共享",
|
||||
screenShare: "屏幕共享",
|
||||
screenShareTitle: "屏幕共享",
|
||||
startScreenShare: "共享屏幕",
|
||||
stopScreenShare: "停止共享",
|
||||
sharingScreen: "正在共享屏幕",
|
||||
watchingScreenShare: "正在观看",
|
||||
watchScreenShare: "观看",
|
||||
leaveScreenShare: "停止观看",
|
||||
screenShareVolume: "共享音量",
|
||||
browserSource: "浏览器来源",
|
||||
teamSpeakSource: "TeamSpeak 客户端来源",
|
||||
sharedAudio: "含共享音频",
|
||||
noScreenShares: "当前没有正在进行的屏幕共享",
|
||||
directP2POnly: "直连 P2P · 不使用 STUN/TURN",
|
||||
watching: "观看中",
|
||||
serverPassword: "服务器密码",
|
||||
optionalPassword: "没有密码可留空",
|
||||
serverPasswordTitle: "服务器需要密码",
|
||||
@@ -868,6 +909,21 @@ const translations: Record<string, Record<string, string>> = {
|
||||
accompanimentNoAudio: "The selected source has no shareable audio. Select it again and enable audio sharing",
|
||||
accompanimentPermissionDenied: "Could not access accompaniment audio. Allow screen sharing and enable audio sharing",
|
||||
accompanimentUnsupported: "This browser does not support accompaniment sharing",
|
||||
screenShare: "Screen sharing",
|
||||
screenShareTitle: "Screen sharing",
|
||||
startScreenShare: "Share screen",
|
||||
stopScreenShare: "Stop sharing",
|
||||
sharingScreen: "Sharing screen",
|
||||
watchingScreenShare: "Watching",
|
||||
watchScreenShare: "Watch",
|
||||
leaveScreenShare: "Stop watching",
|
||||
screenShareVolume: "Share volume",
|
||||
browserSource: "Browser source",
|
||||
teamSpeakSource: "TeamSpeak client source",
|
||||
sharedAudio: "with shared audio",
|
||||
noScreenShares: "No active screen shares",
|
||||
directP2POnly: "Direct P2P · no STUN/TURN",
|
||||
watching: "Watching",
|
||||
serverPassword: "Server password",
|
||||
optionalPassword: "Leave blank if not required",
|
||||
serverPasswordTitle: "Server password required",
|
||||
@@ -2018,6 +2074,15 @@ watch(settingsOpen, (open) => {
|
||||
stopMicrophoneTest();
|
||||
}
|
||||
});
|
||||
watch([screenShareRemoteStream, screenShareRemoteVolume], ([stream, volume]) => {
|
||||
void nextTick(() => {
|
||||
const video = screenVideoEl.value;
|
||||
if (!video) return;
|
||||
if (video.srcObject !== stream) video.srcObject = stream;
|
||||
video.volume = Math.max(0, Math.min(1, volume ?? 1));
|
||||
if (stream) void video.play().catch(() => undefined);
|
||||
});
|
||||
});
|
||||
watch(rememberIdentity, (remember) => {
|
||||
localStorage.setItem("webspeak:remember-identity", remember ? "1" : "0");
|
||||
if (!remember) {
|
||||
@@ -2567,6 +2632,10 @@ function toggleMicrophone(): void {
|
||||
showToast(microphoneMuted.value ? t("microphoneMuted") : t("microphoneActive"));
|
||||
}
|
||||
|
||||
function onScreenShareVolume(event: Event): void {
|
||||
screenShareRemoteVolume.value = Math.max(0, Math.min(1, Number((event.target as HTMLInputElement).value) / 100));
|
||||
}
|
||||
|
||||
async function toggleAccompaniment(): Promise<void> {
|
||||
try {
|
||||
if (accompanimentActive.value) {
|
||||
@@ -3503,4 +3572,43 @@ function stopWhisperTalk(): void {
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
.dock-hover-panel, .dock-switch-row input, .mobile-noise-toggle input { transition-duration: .01ms; }
|
||||
}
|
||||
|
||||
.screen-share-header-button.active { color: var(--accent); background: color-mix(in srgb, var(--accent) 15%, transparent); }
|
||||
.screen-share-section { margin-top: 28px; padding: 18px; border: 1px solid var(--border); border-radius: 16px; background: var(--surface-1); box-shadow: 0 8px 20px color-mix(in srgb, var(--text-primary) 5%, transparent); }
|
||||
.screen-share-header { display: flex; align-items: center; justify-content: space-between; gap: 14px; }
|
||||
.screen-share-header h2 { display: flex; align-items: center; gap: 7px; margin: 6px 0 0; color: var(--text-primary); font-size: 20px; }
|
||||
.screen-share-header h2 .ui-icon { color: var(--accent); }
|
||||
.screen-share-start, .screen-share-header .secondary-button { min-height: 33px; padding-inline: 12px; font-size: 11px; }
|
||||
.screen-share-error { display: flex; align-items: flex-start; gap: 8px; margin-top: 14px; padding: 10px 12px; color: #a64d47; border: 1px solid color-mix(in srgb, #d96b62 28%, var(--border)); border-radius: 10px; background: color-mix(in srgb, #f7d9d5 45%, var(--surface-1)); font-size: 11px; line-height: 1.45; }
|
||||
.screen-share-owner-status { display: flex; align-items: center; gap: 10px; margin-top: 14px; color: var(--text-muted); font-size: 11px; }
|
||||
.screen-share-owner-status .live-pill { padding: 4px 8px; }
|
||||
.screen-share-stream-list { display: grid; gap: 8px; margin-top: 14px; }
|
||||
.screen-share-stream-item { display: flex; align-items: center; gap: 10px; min-width: 0; padding: 10px 11px; border: 1px solid var(--border); border-radius: 11px; background: var(--surface-2); }
|
||||
.screen-share-stream-icon { display: grid; place-items: center; width: 32px; height: 32px; flex: 0 0 32px; color: var(--accent); border-radius: 9px; background: color-mix(in srgb, var(--accent) 12%, var(--surface-1)); }
|
||||
.screen-share-stream-copy { min-width: 0; flex: 1; }
|
||||
.screen-share-stream-copy strong, .screen-share-stream-copy span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
||||
.screen-share-stream-copy strong { color: var(--text-primary); font-size: 12px; }
|
||||
.screen-share-stream-copy span { margin-top: 3px; color: var(--text-muted); font-size: 10px; }
|
||||
.screen-share-stream-copy small { font-size: inherit; }
|
||||
.screen-share-stream-item .secondary-button { min-height: 30px; padding-inline: 11px; font-size: 10px; }
|
||||
.screen-share-watching-label { flex: 0 0 auto; color: var(--accent); font-size: 10px; font-weight: 700; }
|
||||
.screen-share-empty { display: flex; align-items: center; gap: 8px; margin-top: 14px; padding: 13px; color: var(--text-muted); border: 1px dashed var(--border); border-radius: 10px; font-size: 11px; }
|
||||
.screen-share-viewer-card { margin-top: 14px; overflow: hidden; border: 1px solid var(--border); border-radius: 13px; background: #0e1516; }
|
||||
.screen-share-video-wrap { position: relative; display: grid; min-height: 220px; place-items: center; background: #0a1011; }
|
||||
.screen-share-video { display: block; width: 100%; max-height: min(58vh, 560px); object-fit: contain; background: #0a1011; }
|
||||
.screen-share-viewer-badge { position: absolute; top: 10px; right: 10px; display: inline-flex; align-items: center; gap: 5px; padding: 5px 8px; color: #eefefd; border: 1px solid rgba(255,255,255,.14); border-radius: 999px; background: rgba(0,0,0,.5); font-size: 10px; }
|
||||
.screen-share-viewer-controls { display: flex; align-items: center; gap: 10px; padding: 10px 12px; color: #e4f1ef; font-size: 10px; }
|
||||
.screen-share-viewer-controls input { width: min(180px, 35vw); accent-color: #75d7cd; }
|
||||
.screen-share-viewer-controls strong { min-width: 34px; color: #9beee5; font-size: 10px; }
|
||||
.screen-share-viewer-controls .text-button { margin-left: auto; color: #b4d7d3; font-size: 10px; }
|
||||
@media (max-width: 740px) {
|
||||
.screen-share-section { margin-top: 21px; padding: 14px; }
|
||||
.screen-share-header { align-items: flex-start; }
|
||||
.screen-share-header h2 { font-size: 18px; }
|
||||
.screen-share-header .primary-button, .screen-share-header .secondary-button { min-height: 31px; padding-inline: 9px; }
|
||||
.screen-share-video-wrap { min-height: 170px; }
|
||||
.screen-share-viewer-controls { flex-wrap: wrap; }
|
||||
.screen-share-viewer-controls input { order: 4; width: 100%; }
|
||||
.screen-share-viewer-controls .text-button { margin-left: 0; }
|
||||
}
|
||||
</style>
|
||||
Reference in new issue
Block a user