diff --git a/connector/src/main.rs b/connector/src/main.rs index a30a4e5..f62a57b 100644 --- a/connector/src/main.rs +++ b/connector/src/main.rs @@ -108,6 +108,11 @@ struct ClientInfo { /// ServerQuery client (`ClientType::Query`). Always included in the /// snapshot; the UI hides these unless the user enables them per favorite. is_query: bool, + /// Whether this client is broadcasting a TS6 Stream/Call right now. This is + /// the only way a client that joins late learns a stream exists - the server + /// sends no stream command in that case, so the id has to be fetched with + /// `requeststreaminfo`. Always `false` on servers that don't report it. + is_streaming: bool, } /// Payload for the "serveredit " stdin command - every field is optional so @@ -621,6 +626,7 @@ fn snapshot(con: &data::Connection) -> Event { server_groups: c.server_groups.iter().map(|g| g.0).collect(), has_talk_power, is_query: matches!(c.client_type, ClientType::Query { .. }), + is_streaming: c.is_streaming.unwrap_or(false), } }) .collect::>(); diff --git a/gateway/src/index.ts b/gateway/src/index.ts index 59f566a..0354e05 100644 --- a/gateway/src/index.ts +++ b/gateway/src/index.ts @@ -415,6 +415,11 @@ wss.on("connection", (socket: WebSocket) => { await connection?.sendAudio(msg.pcm); break; } + case "requestStreamInfo": { + const clientId = Number(msg.clientId); + if (Number.isFinite(clientId)) await connection?.requestStreamInfo(clientId); + break; + } case "joinStream": { const clientId = Number(msg.clientId); if (Number.isFinite(clientId)) { diff --git a/gateway/src/ts3/connection.ts b/gateway/src/ts3/connection.ts index 509da55..d9cfdef 100644 --- a/gateway/src/ts3/connection.ts +++ b/gateway/src/ts3/connection.ts @@ -39,6 +39,8 @@ export interface ClientInfo { hasTalkPower: boolean; /** ServerQuery client; UI may hide these unless enabled per favorite. */ isQuery: boolean; + /** Broadcasting a TS6 Stream/Call. The stream id is fetched separately. */ + isStreaming: boolean; } export interface GroupEntry { @@ -184,7 +186,9 @@ export type Ts3ConnectionEvent = | { type: "fileDownloadData"; cid: number; path: string; data: string } | { type: "fileUploadDone"; cid: number; path: string } | { type: "permList"; scope: PermScope; id1: number; id2: number | null; entries: PermissionOverviewEntry[] } - | { type: "permissionCatalog"; entries: PermissionCatalogEntry[] }; + | { type: "permissionCatalog"; entries: PermissionCatalogEntry[] } + /** TS6 Stream/Call signaling, forwarded verbatim; `args` is already unescaped. */ + | { type: "streamEvent"; name: string; args: Record }; export type ServerType = "teamspeak" | "teaspeak" | "auto"; @@ -255,6 +259,7 @@ export class Ts3Connection { server_groups: number[]; has_talk_power: boolean; is_query?: boolean; + is_streaming?: boolean; } interface RawChannelInfo { @@ -384,7 +389,8 @@ export class Ts3Connection { | { type: "fileDownloadData"; cid: number; path: string; data: string } | { type: "fileUploadDone"; cid: number; path: string } | { type: "permList"; scope: PermScope; id1: number; id2: number | null; entries: PermissionOverviewEntry[] } - | { type: "permissionCatalog"; entries: PermissionCatalogEntry[] }; + | { type: "permissionCatalog"; entries: PermissionCatalogEntry[] } + | { type: "streamEvent"; name: string; args: Record }; if (event.type === "connected") { this.emit({ @@ -428,6 +434,7 @@ export class Ts3Connection { serverGroups: c.server_groups, hasTalkPower: c.has_talk_power, isQuery: Boolean(c.is_query), + isStreaming: Boolean(c.is_streaming), })), ownClientId: event.own_client_id ?? 0, serverMaxClients: event.server_max_clients ?? 0, @@ -774,6 +781,12 @@ export class Ts3Connection { this.child?.stdin.write(`audio ${pcmBase64}\n`); } + /** Pulls a streaming client's stream details; answered with a + * `notifystreaminfo` streamEvent carrying the stream id. */ + async requestStreamInfo(clientId: number): Promise { + this.child?.stdin.write(`streaminfo ${clientId}\n`); + } + /** Ask the client publishing a TS6 stream to let us watch. The answer comes * back as a `streamEvent` of type `notifyrespondjoinstreamrequest`, which * carries the SDP offer. */ diff --git a/web/src/App.css b/web/src/App.css index f48e6b6..3cf8e4c 100644 --- a/web/src/App.css +++ b/web/src/App.css @@ -1409,6 +1409,65 @@ background: var(--border-soft); } +/* Floating viewer for a TS6 Stream/Call broadcast. */ +.ts-stream-panel { + position: fixed; + right: 1rem; + bottom: 1rem; + z-index: 29; + display: flex; + flex-direction: column; + width: min(480px, calc(100vw - 2rem)); + background: var(--bg-toolbar-1); + border: 1px solid var(--border); + border-radius: 6px; + box-shadow: 0 6px 24px rgba(0, 0, 0, 0.4); + overflow: hidden; +} + +.ts-stream-panel-header { + display: flex; + align-items: center; + gap: 0.5rem; + padding: 0.35rem 0.5rem; + border-bottom: 1px solid var(--border-soft); +} + +.ts-stream-panel-title { + flex: 1; + overflow: hidden; + text-overflow: ellipsis; + white-space: nowrap; + font-weight: 600; +} + +.ts-stream-panel-state { + opacity: 0.7; + font-size: 0.85em; +} + +.ts-stream-panel-close { + padding: 0 0.35rem; + background: none; + border: none; + color: inherit; + cursor: pointer; +} + +.ts-stream-panel video { + width: 100%; + /* Letterbox rather than crop - TS6 screen shares are not always 16:9. */ + aspect-ratio: 16 / 9; + background: #000; + object-fit: contain; +} + +.ts-stream-panel-error { + padding: 0.35rem 0.5rem; + color: var(--danger, #e05a5a); + font-size: 0.85em; +} + .ts-context-menu { position: fixed; z-index: 30; diff --git a/web/src/App.tsx b/web/src/App.tsx index f6e87ce..96393c8 100644 --- a/web/src/App.tsx +++ b/web/src/App.tsx @@ -26,6 +26,7 @@ import { pickAudioOutputDevice, } from "./voice"; import { LanguageProvider, useLanguage, useT, type LangPref } from "./i18n"; +import { StreamViewer, parseStreamInfo, type StreamEvent, type StreamInfo } from "./stream"; import { DEMO_HOST, DEMO_MODE, DemoSocket } from "./demoMode"; import { SOUND_EVENTS, @@ -506,6 +507,8 @@ interface ClientInfo { channelGroup: number; serverGroups: number[]; hasTalkPower: boolean; + /** TS6 Stream/Call broadcast running; absent on servers that don't report it. */ + isStreaming?: boolean; /** ServerQuery client; filtered from the tree unless a favorite enables them. */ isQuery?: boolean; } @@ -705,6 +708,7 @@ function ClientStatusIcons({ client }: { client: ClientInfo }) { 🔒 )} {client.outputMuted && 🔕} + {client.isStreaming && 📺} ); } @@ -5355,6 +5359,16 @@ function AppInner() { const [connectError, setConnectError] = useState(null); const [channels, setChannels] = useState([]); const [clients, setClients] = useState([]); + /** Stream metadata per publishing client id, keyed by clid. */ + const [streamInfos, setStreamInfos] = useState>({}); + const [watchedStream, setWatchedStream] = useState(null); + const [streamMedia, setStreamMedia] = useState(null); + const [streamState, setStreamState] = useState("new"); + const [streamError, setStreamError] = useState(null); + const streamViewerRef = useRef(null); + const streamVideoRef = useRef(null); + /** Clients we already pulled a `notifystreaminfo` for, so we ask only once. */ + const requestedStreamInfoRef = useRef>(new Set()); /** Stable self id from the connector (`own_client_id`); nickname match is fallback only. */ const [ownClientId, setOwnClientId] = useState(null); const [serverName, setServerName] = useState(""); @@ -6228,6 +6242,26 @@ function AppInner() { case "talkers": setTalkers(new Set(data.clients)); break; + case "streamEvent": { + const streamEvent = data as StreamEvent; + if (streamEvent.name === "notifystreaminfo" || streamEvent.name === "notifystreamstarted") { + const info = parseStreamInfo(streamEvent.args); + if (info) setStreamInfos((prev) => ({ ...prev, [info.clientId]: info })); + } + if (streamEvent.name === "notifystreamstopped") { + const clid = Number(streamEvent.args.clid); + if (Number.isFinite(clid)) { + setStreamInfos((prev) => { + if (!(clid in prev)) return prev; + const next = { ...prev }; + delete next[clid]; + return next; + }); + } + } + streamViewerRef.current?.handleEvent(streamEvent); + break; + } case "poke": { const id = ++pokeIdRef.current; setPokes((prev) => [...prev, { id, from: data.from, message: data.message }]); @@ -6281,6 +6315,12 @@ function AppInner() { appendLog({ text: `Disconnected: ${data.reason}`, kind: "info" }); logClient("info", "Connection", `Disconnected: ${data.reason}`); if (wasConnected) void playSound("disconnect"); + streamViewerRef.current?.close(); + streamViewerRef.current = null; + setWatchedStream(null); + setStreamMedia(null); + setStreamInfos({}); + requestedStreamInfoRef.current.clear(); removeSession(sessionId, { skipSocketClose: true }); break; } @@ -7512,6 +7552,68 @@ function AppInner() { reader.readAsText(file); }; + // --- TS6 Stream/Call ----------------------------------------------------- + // + // A client that was already streaming when we joined announces nothing: TS6 + // only sets the `client_is_streaming` property, and the stream id has to be + // pulled with `requeststreaminfo` (ts6-re findings 6b). So whenever a + // streaming client shows up in the tree, ask once. + useEffect(() => { + const streaming = new Set(clients.filter((c) => c.isStreaming).map((c) => c.id)); + for (const id of streaming) { + if (requestedStreamInfoRef.current.has(id)) continue; + requestedStreamInfoRef.current.add(id); + socketRef.current?.send(JSON.stringify({ type: "requestStreamInfo", clientId: id })); + } + // Forget clients that stopped, so a later stream is looked up again. + for (const id of requestedStreamInfoRef.current) { + if (!streaming.has(id)) requestedStreamInfoRef.current.delete(id); + } + setStreamInfos((prev) => { + const stale = Object.keys(prev).filter((id) => !streaming.has(Number(id))); + if (stale.length === 0) return prev; + const next = { ...prev }; + for (const id of stale) delete next[Number(id)]; + return next; + }); + }, [clients]); + + useEffect(() => { + const video = streamVideoRef.current; + if (video && video.srcObject !== streamMedia) video.srcObject = streamMedia; + }, [streamMedia, watchedStream]); + + const handleStopWatchingStream = () => { + // close() sends leaveStream and fires onClosed, which clears the rest. + streamViewerRef.current?.close(); + streamViewerRef.current = null; + setWatchedStream(null); + setStreamMedia(null); + setStreamState("new"); + }; + + const handleWatchStream = (clientId: number) => { + const info = streamInfos[clientId]; + if (!info) return; + handleStopWatchingStream(); + setStreamError(null); + const viewer = new StreamViewer(info.id, info.clientId, { + send: (message) => socketRef.current?.send(JSON.stringify(message)), + onTrack: setStreamMedia, + onStateChange: setStreamState, + onError: setStreamError, + onClosed: () => { + // Also reached when the publisher stops, not just via the close button. + streamViewerRef.current = null; + setWatchedStream(null); + setStreamMedia(null); + }, + }); + streamViewerRef.current = viewer; + setWatchedStream(info); + viewer.join(); + }; + const handleShowClientConnectionInfo = (clientId: number, clientName: string) => { setClientConnectionInfoTarget({ id: clientId, name: clientName }); setClientConnectionInfo(null); @@ -9148,6 +9250,28 @@ function AppInner() { ))} + {watchedStream && ( +
+
+ + 📺 {watchedStream.name || t("stream.untitled")} + + + {streamState === "connected" ? t("stream.live") : t(`stream.state.${streamState}`)} + + +
+ {/* muted so autoplay is never blocked; the user unmutes via the controls */} +
+ )} {clientContextMenu && (
👉 {t("clientContext.poke")} + {!clientContextMenu.isSelf && streamInfos[clientContextMenu.clientId] && ( + + )} {!clientContextMenu.isSelf && (