diff --git a/web/src/App.css b/web/src/App.css index fb3c326..292aea1 100644 --- a/web/src/App.css +++ b/web/src/App.css @@ -1551,6 +1551,34 @@ object-fit: contain; } +/* A stream in our channel nobody opened yet: same 16:9 area, one click to watch. */ +.ts-stream-panel-watch { + aspect-ratio: 16 / 9; + width: 100%; + background: #000; + border: none; + color: #fff; + font-size: 1.1em; + cursor: pointer; + opacity: 0.8; +} + +.ts-stream-panel-watch:hover { + opacity: 1; +} + +/* Stream icons in the tree sit on the right with the group icons and are clickable. */ +.ts-stream-icon { + padding: 0; + font-size: 11px; + line-height: 1; + cursor: pointer; +} + +span.ts-stream-icon { + cursor: default; +} + .ts-stream-panel-error { padding: 0.35rem 0.5rem; color: var(--danger, #e05a5a); diff --git a/web/src/App.tsx b/web/src/App.tsx index 1f9eaeb..60ab22b 100644 --- a/web/src/App.tsx +++ b/web/src/App.tsx @@ -1489,6 +1489,50 @@ function TalkLamp({ ); } +/** Streams per publishing client, and how to open one - read by the channel tree. */ +const StreamsContext = createContext<{ + byClient: Record; + watch: (streamId: string) => void; +}>({ byClient: {}, watch: () => {} }); + +const streamIcon = (info: StreamInfo) => (info.camera ? "📷" : "🖥️"); + +/** Right-hand stream icons on a client row; a click opens that stream. */ +function ClientStreamIcons({ client, isSelf }: { client: ClientInfo; isSelf: boolean }) { + const t = useT(); + const { byClient, watch } = useContext(StreamsContext); + const streams = byClient[client.id] ?? []; + if (streams.length === 0) { + // Streaming, but the stream info has not arrived yet. + return client.isStreaming ? 📺 : null; + } + return ( + <> + {streams.map((info) => { + const label = `${t(info.camera ? "tree.streamingCamera" : "tree.streaming")}${info.name ? `: ${info.name}` : ""}`; + return isSelf ? ( + {streamIcon(info)} + ) : ( + + ); + })} + + ); +} + function ClientStatusIcons({ client }: { client: ClientInfo }) { const t = useT(); const { tree } = useContext(DisplayPrefsContext); @@ -1499,7 +1543,6 @@ function ClientStatusIcons({ client }: { client: ClientInfo }) { {!client.inputMuted && client.inputHardwareEnabled && !client.hasTalkPower && ( 🔒 )} - {client.isStreaming && 📺} ); } @@ -1889,6 +1932,7 @@ function ChannelTree({ ({c.awayMessage}) )} + {clientGroupBadges(c).map((g) => ( ))} @@ -9025,12 +9069,13 @@ function AppInner() { const [treeFilter, setTreeFilter] = useState(""); const [clientVolumes, setClientVolumes] = useState>(loadClientVolumes); /** Stream metadata per publishing client id, keyed by clid. */ - const [streamInfos, setStreamInfos] = useState>({}); + const [streamInfos, setStreamInfos] = useState>({}); /** Streams being watched, keyed by the publisher's clid - several at once, like Discord. */ - const [watchedStreams, setWatchedStreams] = useState>({}); - const streamViewersRef = useRef>(new Map()); + /** Keyed by stream id: one client can send screen and camera at once. */ + const [watchedStreams, setWatchedStreams] = useState>({}); + const streamViewersRef = useRef>(new Map()); /** Tile shown across the whole grid, Discord's "focus" (clid, or -1 for our own broadcast). */ - const [focusedStream, setFocusedStream] = useState(null); + const [focusedStream, setFocusedStream] = useState(null); /** Separate browser window the stream grid is portalled into, if popped out. */ const [streamPopout, setStreamPopout] = useState(null); const [popoutSize, setPopoutSize] = useState({ width: 0, height: 0 }); @@ -10399,15 +10444,20 @@ function AppInner() { 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 })); + // notifystreaminfo may leave `type` out; keep what notifystreamstarted said. + if (info) + setStreamInfos((prev) => ({ + ...prev, + [info.id]: { ...info, camera: info.camera ?? prev[info.id]?.camera }, + })); } if (streamEvent.name === "notifystreamstopped") { - const clid = Number(streamEvent.args.clid); - if (Number.isFinite(clid)) { + const { id } = streamEvent.args; + if (id) { setStreamInfos((prev) => { - if (!(clid in prev)) return prev; + if (!(id in prev)) return prev; const next = { ...prev }; - delete next[clid]; + delete next[id]; return next; }); } @@ -12146,10 +12196,10 @@ function AppInner() { if (!streaming.has(id)) requestedStreamInfoRef.current.delete(id); } setStreamInfos((prev) => { - const stale = Object.keys(prev).filter((id) => !streaming.has(Number(id))); + const stale = Object.values(prev).filter((info) => !streaming.has(info.clientId)); if (stale.length === 0) return prev; const next = { ...prev }; - for (const id of stale) delete next[Number(id)]; + for (const info of stale) delete next[info.id]; return next; }); }, [clients]); @@ -12157,7 +12207,18 @@ function AppInner() { const activePublishes = (Object.entries(publishes) as [PublishSource, PublishTile][]).filter( ([, tile]) => tile.state !== "idle" && tile.state !== "stopped", ); - const streamTileCount = Object.keys(watchedStreams).length + activePublishes.length; + const streamsByClient: Record = {}; + for (const info of Object.values(streamInfos)) (streamsByClient[info.clientId] ??= []).push(info); + // Like Discord: streams in our channel show up as tiles before anyone clicks "watch". + const ownChannel = clients.find((c) => c.id === ownClientId)?.channel; + const availableStreams = Object.values(streamInfos).filter( + (info) => + info.clientId !== ownClientId && + !watchedStreams[info.id] && + ownChannel !== undefined && + clients.find((c) => c.id === info.clientId)?.channel === ownChannel, + ); + const streamTileCount = Object.keys(watchedStreams).length + activePublishes.length + availableStreams.length; const openStreamPopout = () => { const win = window.open("", "webspeak3-streams", "popup,width=1280,height=760"); @@ -12193,10 +12254,10 @@ function AppInner() { return () => window.removeEventListener("pagehide", close); }, [streamPopout, streamTileCount]); - /** Stops one watched stream, or all of them without a clid. */ - const handleStopWatchingStream = (clientId?: number) => { + /** Stops one watched stream, or all of them without an id. */ + const handleStopWatchingStream = (streamId?: string) => { const viewers = streamViewersRef.current; - const ids = clientId === undefined ? [...viewers.keys()] : [clientId]; + const ids = streamId === undefined ? [...viewers.keys()] : [streamId]; for (const id of ids) { // close() sends leaveStream; delete first so its onClosed is a no-op. const viewer = viewers.get(id); @@ -12204,18 +12265,18 @@ function AppInner() { viewer?.close(); } setWatchedStreams((prev) => { - if (clientId === undefined) return {}; + if (streamId === undefined) return {}; const next = { ...prev }; - delete next[clientId]; + delete next[streamId]; return next; }); }; - const handleWatchStream = (clientId: number) => { - const info = streamInfos[clientId]; - if (!info || streamViewersRef.current.has(clientId)) return; + const handleWatchStream = (streamId: string) => { + const info = streamInfos[streamId]; + if (!info || streamViewersRef.current.has(streamId)) return; const patch = (change: Partial) => - setWatchedStreams((prev) => (prev[clientId] ? { ...prev, [clientId]: { ...prev[clientId], ...change } } : prev)); + setWatchedStreams((prev) => (prev[streamId] ? { ...prev, [streamId]: { ...prev[streamId], ...change } } : prev)); const viewer = new StreamViewer(info.id, info.clientId, { send: (message) => socketRef.current?.send(JSON.stringify(message)), onTrack: (media) => patch({ media }), @@ -12224,12 +12285,12 @@ function AppInner() { onError: (error) => patch({ error }), onClosed: () => { // Also reached when the publisher stops, not just via the close button. - if (streamViewersRef.current.get(clientId) !== viewer) return; - handleStopWatchingStream(clientId); + if (streamViewersRef.current.get(streamId) !== viewer) return; + handleStopWatchingStream(streamId); }, }); - streamViewersRef.current.set(clientId, viewer); - setWatchedStreams((prev) => ({ ...prev, [clientId]: { info, media: null, state: "new", error: null } })); + streamViewersRef.current.set(streamId, viewer); + setWatchedStreams((prev) => ({ ...prev, [streamId]: { info, media: null, state: "new", error: null } })); viewer.join(); }; @@ -12912,7 +12973,7 @@ function AppInner() { }; })(); - const streamToggle = (id: number) => ( + const streamToggle = (id: string) => ( <> + + ))} ); return streamPopout @@ -14554,18 +14628,22 @@ function AppInner() { ); })()} - {!clientContextMenu.isSelf && streamInfos[clientContextMenu.clientId] && ( - - )} + {!clientContextMenu.isSelf && + (streamsByClient[clientContextMenu.clientId] ?? []).map((info) => ( + + ))} {!clientContextMenu.isSelf && (