web: stream tiles for the channel, clickable tree icons, camera vs. screen

- Streams in our own channel show up in the grid (corner and pop-out)
  as tiles with a "Watch" button, Discord-style, before anyone opens them.
- Stream icons moved to the right side of the client row, next to the
  group icons, and a click opens that stream; 📷 for a camera (setupstream
  type 1), 🖥️ for screen/window. Same icons in tiles and context menu.
- Stream infos and watched streams are keyed by stream id instead of
  clid, since one client can now send screen and camera at once; the
  context menu lists one entry per stream.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Hu2cuPLqpuKVfd9wWFFakU
This commit is contained in:
MoepchiandClaude Opus 5.5 committed 2026-11-30 22:07:50 +00:00
1 parent ebe162fafb
commit e923181e14
5 files changed
+155 -38

No files matched your search

+28
View File
@@ -1551,6 +1551,34 @@
object-fit: contain; 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 { .ts-stream-panel-error {
padding: 0.35rem 0.5rem; padding: 0.35rem 0.5rem;
color: var(--danger, #e05a5a); color: var(--danger, #e05a5a);
+118 -38
View File
@@ -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<number, StreamInfo[]>;
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 ? <span className="ts-stream-icon" title={t("tree.streaming")}>📺</span> : null;
}
return (
<>
{streams.map((info) => {
const label = `${t(info.camera ? "tree.streamingCamera" : "tree.streaming")}${info.name ? `: ${info.name}` : ""}`;
return isSelf ? (
<span key={info.id} className="ts-stream-icon" title={label}>{streamIcon(info)}</span>
) : (
<button
key={info.id}
type="button"
className="ts-stream-icon ts-plain-button"
title={label}
aria-label={label}
onClick={(e) => {
e.stopPropagation();
watch(info.id);
}}
onDoubleClick={(e) => e.stopPropagation()}
>
{streamIcon(info)}
</button>
);
})}
</>
);
}
function ClientStatusIcons({ client }: { client: ClientInfo }) { function ClientStatusIcons({ client }: { client: ClientInfo }) {
const t = useT(); const t = useT();
const { tree } = useContext(DisplayPrefsContext); const { tree } = useContext(DisplayPrefsContext);
@@ -1499,7 +1543,6 @@ function ClientStatusIcons({ client }: { client: ClientInfo }) {
{!client.inputMuted && client.inputHardwareEnabled && !client.hasTalkPower && ( {!client.inputMuted && client.inputHardwareEnabled && !client.hasTalkPower && (
<span title={t("tree.noTalkPower")}>🔒</span> <span title={t("tree.noTalkPower")}>🔒</span>
)} )}
{client.isStreaming && <span title={t("tree.streaming")}>📺</span>}
</span> </span>
); );
} }
@@ -1889,6 +1932,7 @@ function ChannelTree({
<span className="ts-client-away-message">({c.awayMessage})</span> <span className="ts-client-away-message">({c.awayMessage})</span>
)} )}
<span className="ts-client-icons"> <span className="ts-client-icons">
<ClientStreamIcons client={c} isSelf={c.id === ownClientId} />
{clientGroupBadges(c).map((g) => ( {clientGroupBadges(c).map((g) => (
<GroupIcon key={g.id} group={g} images={groupIconImages} /> <GroupIcon key={g.id} group={g} images={groupIconImages} />
))} ))}
@@ -9025,12 +9069,13 @@ function AppInner() {
const [treeFilter, setTreeFilter] = useState(""); const [treeFilter, setTreeFilter] = useState("");
const [clientVolumes, setClientVolumes] = useState<Record<string, number>>(loadClientVolumes); const [clientVolumes, setClientVolumes] = useState<Record<string, number>>(loadClientVolumes);
/** Stream metadata per publishing client id, keyed by clid. */ /** Stream metadata per publishing client id, keyed by clid. */
const [streamInfos, setStreamInfos] = useState<Record<number, StreamInfo>>({}); const [streamInfos, setStreamInfos] = useState<Record<string, StreamInfo>>({});
/** Streams being watched, keyed by the publisher's clid - several at once, like Discord. */ /** Streams being watched, keyed by the publisher's clid - several at once, like Discord. */
const [watchedStreams, setWatchedStreams] = useState<Record<number, WatchedStream>>({}); /** Keyed by stream id: one client can send screen and camera at once. */
const streamViewersRef = useRef<Map<number, StreamViewer>>(new Map()); const [watchedStreams, setWatchedStreams] = useState<Record<string, WatchedStream>>({});
const streamViewersRef = useRef<Map<string, StreamViewer>>(new Map());
/** Tile shown across the whole grid, Discord's "focus" (clid, or -1 for our own broadcast). */ /** Tile shown across the whole grid, Discord's "focus" (clid, or -1 for our own broadcast). */
const [focusedStream, setFocusedStream] = useState<number | null>(null); const [focusedStream, setFocusedStream] = useState<string | null>(null);
/** Separate browser window the stream grid is portalled into, if popped out. */ /** Separate browser window the stream grid is portalled into, if popped out. */
const [streamPopout, setStreamPopout] = useState<Window | null>(null); const [streamPopout, setStreamPopout] = useState<Window | null>(null);
const [popoutSize, setPopoutSize] = useState({ width: 0, height: 0 }); const [popoutSize, setPopoutSize] = useState({ width: 0, height: 0 });
@@ -10399,15 +10444,20 @@ function AppInner() {
const streamEvent = data as StreamEvent; const streamEvent = data as StreamEvent;
if (streamEvent.name === "notifystreaminfo" || streamEvent.name === "notifystreamstarted") { if (streamEvent.name === "notifystreaminfo" || streamEvent.name === "notifystreamstarted") {
const info = parseStreamInfo(streamEvent.args); 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") { if (streamEvent.name === "notifystreamstopped") {
const clid = Number(streamEvent.args.clid); const { id } = streamEvent.args;
if (Number.isFinite(clid)) { if (id) {
setStreamInfos((prev) => { setStreamInfos((prev) => {
if (!(clid in prev)) return prev; if (!(id in prev)) return prev;
const next = { ...prev }; const next = { ...prev };
delete next[clid]; delete next[id];
return next; return next;
}); });
} }
@@ -12146,10 +12196,10 @@ function AppInner() {
if (!streaming.has(id)) requestedStreamInfoRef.current.delete(id); if (!streaming.has(id)) requestedStreamInfoRef.current.delete(id);
} }
setStreamInfos((prev) => { 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; if (stale.length === 0) return prev;
const next = { ...prev }; const next = { ...prev };
for (const id of stale) delete next[Number(id)]; for (const info of stale) delete next[info.id];
return next; return next;
}); });
}, [clients]); }, [clients]);
@@ -12157,7 +12207,18 @@ function AppInner() {
const activePublishes = (Object.entries(publishes) as [PublishSource, PublishTile][]).filter( const activePublishes = (Object.entries(publishes) as [PublishSource, PublishTile][]).filter(
([, tile]) => tile.state !== "idle" && tile.state !== "stopped", ([, tile]) => tile.state !== "idle" && tile.state !== "stopped",
); );
const streamTileCount = Object.keys(watchedStreams).length + activePublishes.length; const streamsByClient: Record<number, StreamInfo[]> = {};
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 openStreamPopout = () => {
const win = window.open("", "webspeak3-streams", "popup,width=1280,height=760"); const win = window.open("", "webspeak3-streams", "popup,width=1280,height=760");
@@ -12193,10 +12254,10 @@ function AppInner() {
return () => window.removeEventListener("pagehide", close); return () => window.removeEventListener("pagehide", close);
}, [streamPopout, streamTileCount]); }, [streamPopout, streamTileCount]);
/** Stops one watched stream, or all of them without a clid. */ /** Stops one watched stream, or all of them without an id. */
const handleStopWatchingStream = (clientId?: number) => { const handleStopWatchingStream = (streamId?: string) => {
const viewers = streamViewersRef.current; const viewers = streamViewersRef.current;
const ids = clientId === undefined ? [...viewers.keys()] : [clientId]; const ids = streamId === undefined ? [...viewers.keys()] : [streamId];
for (const id of ids) { for (const id of ids) {
// close() sends leaveStream; delete first so its onClosed is a no-op. // close() sends leaveStream; delete first so its onClosed is a no-op.
const viewer = viewers.get(id); const viewer = viewers.get(id);
@@ -12204,18 +12265,18 @@ function AppInner() {
viewer?.close(); viewer?.close();
} }
setWatchedStreams((prev) => { setWatchedStreams((prev) => {
if (clientId === undefined) return {}; if (streamId === undefined) return {};
const next = { ...prev }; const next = { ...prev };
delete next[clientId]; delete next[streamId];
return next; return next;
}); });
}; };
const handleWatchStream = (clientId: number) => { const handleWatchStream = (streamId: string) => {
const info = streamInfos[clientId]; const info = streamInfos[streamId];
if (!info || streamViewersRef.current.has(clientId)) return; if (!info || streamViewersRef.current.has(streamId)) return;
const patch = (change: Partial<WatchedStream>) => const patch = (change: Partial<WatchedStream>) =>
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, { const viewer = new StreamViewer(info.id, info.clientId, {
send: (message) => socketRef.current?.send(JSON.stringify(message)), send: (message) => socketRef.current?.send(JSON.stringify(message)),
onTrack: (media) => patch({ media }), onTrack: (media) => patch({ media }),
@@ -12224,12 +12285,12 @@ function AppInner() {
onError: (error) => patch({ error }), onError: (error) => patch({ error }),
onClosed: () => { onClosed: () => {
// Also reached when the publisher stops, not just via the close button. // Also reached when the publisher stops, not just via the close button.
if (streamViewersRef.current.get(clientId) !== viewer) return; if (streamViewersRef.current.get(streamId) !== viewer) return;
handleStopWatchingStream(clientId); handleStopWatchingStream(streamId);
}, },
}); });
streamViewersRef.current.set(clientId, viewer); streamViewersRef.current.set(streamId, viewer);
setWatchedStreams((prev) => ({ ...prev, [clientId]: { info, media: null, state: "new", error: null } })); setWatchedStreams((prev) => ({ ...prev, [streamId]: { info, media: null, state: "new", error: null } }));
viewer.join(); viewer.join();
}; };
@@ -12912,7 +12973,7 @@ function AppInner() {
}; };
})(); })();
const streamToggle = (id: number) => ( const streamToggle = (id: string) => (
<> <>
<button <button
className="ts-stream-panel-close" className="ts-stream-panel-close"
@@ -14388,7 +14449,7 @@ function AppInner() {
style={{ "--stream-cols": Math.min(streamTileCount, 2), ...popoutGridStyle } as React.CSSProperties} style={{ "--stream-cols": Math.min(streamTileCount, 2), ...popoutGridStyle } as React.CSSProperties}
> >
{activePublishes.map(([source, tile]) => { {activePublishes.map(([source, tile]) => {
const focusId = source === "camera" ? -2 : -1; const focusId = `publish-${source}`;
const publisher = publishersRef.current.get(source); const publisher = publishersRef.current.get(source);
return ( return (
<div <div
@@ -14451,19 +14512,19 @@ function AppInner() {
</div> </div>
); );
})} })}
{Object.entries(watchedStreams).map(([clid, watched]) => ( {Object.entries(watchedStreams).map(([streamId, watched]) => (
<div className={`ts-stream-panel${focusedStream === Number(clid) ? " ts-stream-panel-focused" : ""}`} key={clid}> <div className={`ts-stream-panel${focusedStream === streamId ? " ts-stream-panel-focused" : ""}`} key={streamId}>
<div className="ts-stream-panel-header"> <div className="ts-stream-panel-header">
<span className="ts-stream-panel-title"> <span className="ts-stream-panel-title">
📺 {watched.info.name || t("stream.untitled")} <AlphaBadge /> {streamIcon(watched.info)} {watched.info.name || t("stream.untitled")} <AlphaBadge />
</span> </span>
<span className="ts-stream-panel-state"> <span className="ts-stream-panel-state">
{watched.state === "connected" ? t("stream.live") : t(`stream.state.${watched.state}`)} {watched.state === "connected" ? t("stream.live") : t(`stream.state.${watched.state}`)}
</span> </span>
{streamToggle(Number(clid))} {streamToggle(streamId)}
<button <button
className="ts-stream-panel-close" className="ts-stream-panel-close"
onClick={() => handleStopWatchingStream(Number(clid))} onClick={() => handleStopWatchingStream(streamId)}
title={t("stream.stop")} title={t("stream.stop")}
> >
✕ ✕
@@ -14482,6 +14543,19 @@ function AppInner() {
{watched.error && <div className="ts-stream-panel-error">{watched.error}</div>} {watched.error && <div className="ts-stream-panel-error">{watched.error}</div>}
</div> </div>
))} ))}
{availableStreams.map((info) => (
<div className="ts-stream-panel" key={info.id}>
<div className="ts-stream-panel-header">
<span className="ts-stream-panel-title">
{streamIcon(info)} {info.name || t("stream.untitled")} <AlphaBadge />
</span>
<span className="ts-stream-panel-state">{publishClientName(info.clientId)}</span>
</div>
<button className="ts-stream-panel-watch" onClick={() => handleWatchStream(info.id)}>
▶ {t("stream.watch")}
</button>
</div>
))}
</div> </div>
); );
return streamPopout return streamPopout
@@ -14554,18 +14628,22 @@ function AppInner() {
</label> </label>
); );
})()} })()}
{!clientContextMenu.isSelf && streamInfos[clientContextMenu.clientId] && ( {!clientContextMenu.isSelf &&
(streamsByClient[clientContextMenu.clientId] ?? []).map((info) => (
<button <button
key={info.id}
className="ts-menu-item" className="ts-menu-item"
onClick={() => { onClick={() => {
handleWatchStream(clientContextMenu.clientId); handleWatchStream(info.id);
setClientContextMenu(null); setClientContextMenu(null);
}} }}
> >
<span className="ts-menu-item-icon">📺</span> <span className="ts-menu-item-icon">{streamIcon(info)}</span>
<span className="ts-menu-item-label">{t("clientContext.watchStream")}</span> <span className="ts-menu-item-label">
{t(info.camera ? "clientContext.watchCamera" : "clientContext.watchStream")}
</span>
</button> </button>
)} ))}
{!clientContextMenu.isSelf && ( {!clientContextMenu.isSelf && (
<button <button
className="ts-menu-item" className="ts-menu-item"
@@ -14857,6 +14935,7 @@ function AppInner() {
{treeSearch && treeSearch.channels.length === 0 && ( {treeSearch && treeSearch.channels.length === 0 && (
<div className="ts-tree-empty">{t("tree.noMatches")}</div> <div className="ts-tree-empty">{t("tree.noMatches")}</div>
)} )}
<StreamsContext.Provider value={{ byClient: streamsByClient, watch: handleWatchStream }}>
<ChannelTree <ChannelTree
channels={treeSearch?.channels ?? channels} channels={treeSearch?.channels ?? channels}
clients={treeSearch?.clients ?? treeClients} clients={treeSearch?.clients ?? treeClients}
@@ -14876,6 +14955,7 @@ function AppInner() {
onClientContextMenu={handleClientContextMenu} onClientContextMenu={handleClientContextMenu}
onChannelContextMenu={handleChannelContextMenu} onChannelContextMenu={handleChannelContextMenu}
/> />
</StreamsContext.Provider>
</> </>
) : ( ) : (
<div className="ts-tree-empty"> <div className="ts-tree-empty">
+3
View File
@@ -533,6 +533,9 @@
"publish.mode.server": "Server", "publish.mode.server": "Server",
"publish.mode.serverUnavailable": "Der Server-Modus läuft über TS6s SFU und ist noch nicht implementiert.", "publish.mode.serverUnavailable": "Der Server-Modus läuft über TS6s SFU und ist noch nicht implementiert.",
"stream.untitled": "Stream", "stream.untitled": "Stream",
"tree.streamingCamera": "Kamera",
"clientContext.watchCamera": "Kamera ansehen",
"stream.watch": "Ansehen",
"stream.popout": "In eigenem Fenster", "stream.popout": "In eigenem Fenster",
"stream.popin": "Zurück ins Hauptfenster", "stream.popin": "Zurück ins Hauptfenster",
"stream.focus": "Vergrößern", "stream.focus": "Vergrößern",
+3
View File
@@ -533,6 +533,9 @@
"publish.mode.server": "Server", "publish.mode.server": "Server",
"publish.mode.serverUnavailable": "Server mode goes through TS6's SFU and is not implemented yet.", "publish.mode.serverUnavailable": "Server mode goes through TS6's SFU and is not implemented yet.",
"stream.untitled": "Stream", "stream.untitled": "Stream",
"tree.streamingCamera": "Camera",
"clientContext.watchCamera": "Watch camera",
"stream.watch": "Watch",
"stream.popout": "Open in own window", "stream.popout": "Open in own window",
"stream.popin": "Back to main window", "stream.popin": "Back to main window",
"stream.focus": "Enlarge", "stream.focus": "Enlarge",
+3
View File
@@ -43,6 +43,8 @@ export interface StreamInfo {
viewers: number; viewers: number;
hasAudio: boolean; hasAudio: boolean;
bitrate: number; bitrate: number;
/** `type` 1 (CAMERA) vs. screen/window; undefined when the notify left it out. */
camera?: boolean;
} }
export interface StreamViewerOptions { export interface StreamViewerOptions {
@@ -86,6 +88,7 @@ export function parseStreamInfo(args: Record<string, string>): StreamInfo | null
viewers: Number(args.viewer ?? 0) || 0, viewers: Number(args.viewer ?? 0) || 0,
hasAudio: args.audio === "1", hasAudio: args.audio === "1",
bitrate: Number(args.bitrate ?? 0) || 0, bitrate: Number(args.bitrate ?? 0) || 0,
camera: args.type === undefined ? undefined : args.type === "1",
}; };
} }