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
+162 -45

No files matched your search

+28
View File
@@ -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);
+125 -45
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 }) {
const t = useT();
const { tree } = useContext(DisplayPrefsContext);
@@ -1499,7 +1543,6 @@ function ClientStatusIcons({ client }: { client: ClientInfo }) {
{!client.inputMuted && client.inputHardwareEnabled && !client.hasTalkPower && (
<span title={t("tree.noTalkPower")}>🔒</span>
)}
{client.isStreaming && <span title={t("tree.streaming")}>📺</span>}
</span>
);
}
@@ -1889,6 +1932,7 @@ function ChannelTree({
<span className="ts-client-away-message">({c.awayMessage})</span>
)}
<span className="ts-client-icons">
<ClientStreamIcons client={c} isSelf={c.id === ownClientId} />
{clientGroupBadges(c).map((g) => (
<GroupIcon key={g.id} group={g} images={groupIconImages} />
))}
@@ -9025,12 +9069,13 @@ function AppInner() {
const [treeFilter, setTreeFilter] = useState("");
const [clientVolumes, setClientVolumes] = useState<Record<string, number>>(loadClientVolumes);
/** 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. */
const [watchedStreams, setWatchedStreams] = useState<Record<number, WatchedStream>>({});
const streamViewersRef = useRef<Map<number, StreamViewer>>(new Map());
/** Keyed by stream id: one client can send screen and camera at once. */
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). */
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. */
const [streamPopout, setStreamPopout] = useState<Window | null>(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<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 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<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, {
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) => (
<>
<button
className="ts-stream-panel-close"
@@ -14388,7 +14449,7 @@ function AppInner() {
style={{ "--stream-cols": Math.min(streamTileCount, 2), ...popoutGridStyle } as React.CSSProperties}
>
{activePublishes.map(([source, tile]) => {
const focusId = source === "camera" ? -2 : -1;
const focusId = `publish-${source}`;
const publisher = publishersRef.current.get(source);
return (
<div
@@ -14451,19 +14512,19 @@ function AppInner() {
</div>
);
})}
{Object.entries(watchedStreams).map(([clid, watched]) => (
<div className={`ts-stream-panel${focusedStream === Number(clid) ? " ts-stream-panel-focused" : ""}`} key={clid}>
{Object.entries(watchedStreams).map(([streamId, watched]) => (
<div className={`ts-stream-panel${focusedStream === streamId ? " ts-stream-panel-focused" : ""}`} key={streamId}>
<div className="ts-stream-panel-header">
<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 className="ts-stream-panel-state">
{watched.state === "connected" ? t("stream.live") : t(`stream.state.${watched.state}`)}
</span>
{streamToggle(Number(clid))}
{streamToggle(streamId)}
<button
className="ts-stream-panel-close"
onClick={() => handleStopWatchingStream(Number(clid))}
onClick={() => handleStopWatchingStream(streamId)}
title={t("stream.stop")}
>
✕
@@ -14482,6 +14543,19 @@ function AppInner() {
{watched.error && <div className="ts-stream-panel-error">{watched.error}</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>
);
return streamPopout
@@ -14554,18 +14628,22 @@ function AppInner() {
</label>
);
})()}
{!clientContextMenu.isSelf && streamInfos[clientContextMenu.clientId] && (
<button
className="ts-menu-item"
onClick={() => {
handleWatchStream(clientContextMenu.clientId);
setClientContextMenu(null);
}}
>
<span className="ts-menu-item-icon">📺</span>
<span className="ts-menu-item-label">{t("clientContext.watchStream")}</span>
</button>
)}
{!clientContextMenu.isSelf &&
(streamsByClient[clientContextMenu.clientId] ?? []).map((info) => (
<button
key={info.id}
className="ts-menu-item"
onClick={() => {
handleWatchStream(info.id);
setClientContextMenu(null);
}}
>
<span className="ts-menu-item-icon">{streamIcon(info)}</span>
<span className="ts-menu-item-label">
{t(info.camera ? "clientContext.watchCamera" : "clientContext.watchStream")}
</span>
</button>
))}
{!clientContextMenu.isSelf && (
<button
className="ts-menu-item"
@@ -14857,6 +14935,7 @@ function AppInner() {
{treeSearch && treeSearch.channels.length === 0 && (
<div className="ts-tree-empty">{t("tree.noMatches")}</div>
)}
<StreamsContext.Provider value={{ byClient: streamsByClient, watch: handleWatchStream }}>
<ChannelTree
channels={treeSearch?.channels ?? channels}
clients={treeSearch?.clients ?? treeClients}
@@ -14876,6 +14955,7 @@ function AppInner() {
onClientContextMenu={handleClientContextMenu}
onChannelContextMenu={handleChannelContextMenu}
/>
</StreamsContext.Provider>
</>
) : (
<div className="ts-tree-empty">
+3
View File
@@ -533,6 +533,9 @@
"publish.mode.server": "Server",
"publish.mode.serverUnavailable": "Der Server-Modus läuft über TS6s SFU und ist noch nicht implementiert.",
"stream.untitled": "Stream",
"tree.streamingCamera": "Kamera",
"clientContext.watchCamera": "Kamera ansehen",
"stream.watch": "Ansehen",
"stream.popout": "In eigenem Fenster",
"stream.popin": "Zurück ins Hauptfenster",
"stream.focus": "Vergrößern",
+3
View File
@@ -533,6 +533,9 @@
"publish.mode.server": "Server",
"publish.mode.serverUnavailable": "Server mode goes through TS6's SFU and is not implemented yet.",
"stream.untitled": "Stream",
"tree.streamingCamera": "Camera",
"clientContext.watchCamera": "Watch camera",
"stream.watch": "Watch",
"stream.popout": "Open in own window",
"stream.popin": "Back to main window",
"stream.focus": "Enlarge",
+3
View File
@@ -43,6 +43,8 @@ export interface StreamInfo {
viewers: number;
hasAudio: boolean;
bitrate: number;
/** `type` 1 (CAMERA) vs. screen/window; undefined when the notify left it out. */
camera?: boolean;
}
export interface StreamViewerOptions {
@@ -86,6 +88,7 @@ export function parseStreamInfo(args: Record<string, string>): StreamInfo | null
viewers: Number(args.viewer ?? 0) || 0,
hasAudio: args.audio === "1",
bitrate: Number(args.bitrate ?? 0) || 0,
camera: args.type === undefined ? undefined : args.type === "1",
};
}