From 8fbd591efae9e6306fee37a469cf14b2dce678b5 Mon Sep 17 00:00:00 2001 From: Moepchi Date: Mon, 30 Nov 2026 21:38:18 +0000 Subject: [PATCH] web: Discord-style stream grid, focus and pop-out window Watched streams and our own broadcast are tiles in one grid (two columns in the corner), any tile can be enlarged across the grid, and the whole grid can move into its own browser window via a React portal; closing that window brings it back. main.tsx now reloads once when the App chunk (or a lazy chunk) fails to load, which is what left a black screen right after the last deploy. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Hu2cuPLqpuKVfd9wWFFakU --- web/src/App.css | 60 ++++++++++++++++++++++++++--- web/src/App.tsx | 84 ++++++++++++++++++++++++++++++++++++----- web/src/locales/de.json | 4 ++ web/src/locales/en.json | 4 ++ web/src/main.tsx | 31 ++++++++++++++- 5 files changed, 167 insertions(+), 16 deletions(-) diff --git a/web/src/App.css b/web/src/App.css index 151aae3..3640992 100644 --- a/web/src/App.css +++ b/web/src/App.css @@ -1480,7 +1480,7 @@ .ts-stream-panel { display: flex; flex-direction: column; - width: min(480px, calc(100vw - 2rem)); + min-width: 0; background: var(--bg-toolbar-1); border: 1px solid var(--border); border-radius: 6px; @@ -1661,21 +1661,69 @@ border-color: var(--accent); } -/* Watching and broadcasting can run at the same time, so the two panels stack - instead of each anchoring itself to the same corner. */ +/* Every watched stream (and our own broadcast) is a tile in one grid, like + Discord: up to two columns in the corner, as many as fit when popped out. */ .ts-stream-panels { position: fixed; right: 1rem; bottom: 1rem; z-index: 29; - display: flex; - flex-direction: column; + display: grid; + grid-template-columns: repeat(var(--stream-cols, 1), minmax(0, 1fr)); + align-content: end; gap: 0.5rem; - align-items: flex-end; + width: min(calc(var(--stream-cols, 1) * 480px), calc(100vw - 2rem)); max-height: calc(100vh - 2rem); overflow-y: auto; } +.ts-stream-toolbar { + grid-column: 1 / -1; + order: -2; + display: flex; + justify-content: flex-end; +} + +.ts-stream-toolbar button { + padding: 0.15rem 0.5rem; + background: var(--bg-toolbar-1); + border: 1px solid var(--border); + border-radius: 4px; + color: inherit; + font-size: 0.85em; + cursor: pointer; +} + +.ts-stream-panel-focused { + grid-column: 1 / -1; +} + +/* Inside the separate window the grid owns the whole viewport. */ +.ts-stream-panels-popout { + position: static; + width: auto; + max-height: none; + padding: 0.5rem; + grid-template-columns: repeat(auto-fit, minmax(360px, 1fr)); + align-content: start; +} + +/* Discord-style focus: the enlarged stream on top, the rest below it. */ +.ts-stream-panels-popout .ts-stream-panel-focused { + order: -1; +} + +.ts-stream-panels-popout .ts-stream-panel-focused video { + max-height: calc(100vh - 6rem); +} + +/* Wraps the grid in the popped-out window; carries the theme variables. */ +.ts-stream-popout-root { + min-height: 100vh; + background: var(--bg); + color: var(--text); +} + .ts-context-menu { position: fixed; z-index: 30; diff --git a/web/src/App.tsx b/web/src/App.tsx index ebbd40d..9030cb3 100644 --- a/web/src/App.tsx +++ b/web/src/App.tsx @@ -9,6 +9,7 @@ import { useSyncExternalStore, type ReactNode, } from "react"; +import { createPortal } from "react-dom"; import { identityUid } from "./identityUid"; import qrcode from "qrcode-generator"; import { useRegisterSW } from "virtual:pwa-register/react"; @@ -9017,6 +9018,10 @@ function AppInner() { /** Streams being watched, keyed by the publisher's clid - several at once, like Discord. */ 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); + /** Separate browser window the stream grid is portalled into, if popped out. */ + const [streamPopout, setStreamPopout] = useState(null); const [publishState, setPublishState] = useState("idle"); const [publishViewers, setPublishViewers] = useState([]); const [publishPending, setPublishPending] = useState<[number, string][]>([]); @@ -12151,7 +12156,41 @@ function AppInner() { if (!video) return; const media = publisherRef.current?.previewStream ?? null; if (video.srcObject !== media) video.srcObject = media; - }, [publishState, publishViewers]); + }, [publishState, publishViewers, streamPopout]); + + const streamTileCount = + Object.keys(watchedStreams).length + (publishState !== "idle" && publishState !== "stopped" ? 1 : 0); + + const openStreamPopout = () => { + const win = window.open("", "webspeak3-streams", "popup,width=1280,height=760"); + if (!win) return; + win.document.title = "WebSpeak3 – Streams"; + win.document.head.replaceChildren( + ...[...document.querySelectorAll('link[rel="stylesheet"], style')].map((node) => node.cloneNode(true)), + ); + win.document.body.style.margin = "0"; + // Fires when the user closes the window; the grid then moves back in here. + win.addEventListener("pagehide", () => setStreamPopout(null)); + setStreamPopout(win); + }; + + const closeStreamPopout = () => { + streamPopout?.close(); + setStreamPopout(null); + }; + + useEffect(() => { + // Nothing left to show (or the tab goes away): don't leave an empty window behind. + if (!streamPopout) return; + if (streamTileCount === 0) { + streamPopout.close(); + setStreamPopout(null); + return; + } + const close = () => streamPopout.close(); + window.addEventListener("pagehide", close); + return () => window.removeEventListener("pagehide", close); + }, [streamPopout, streamTileCount]); /** Stops one watched stream, or all of them without a clid. */ const handleStopWatchingStream = (clientId?: number) => { @@ -12824,12 +12863,24 @@ function AppInner() { ? t("publish.demoUnavailable") : `${publishState === "live" ? t("publish.stop") : t("publish.start")} (${t("publish.alpha")})`; + const themeClassName = `ts-app ts-theme-${theme}${designThemeClassName(designTheme)}${ + activeCustomTheme ? " ts-design-custom" : "" + }`; + + const streamToggle = (id: number) => ( + + ); + return (
setStreamSettingsOpen(false)} /> )} - {(Object.keys(watchedStreams).length > 0 || (publishState !== "idle" && publishState !== "stopped")) && ( -
+ {streamTileCount > 0 && (() => { + const grid = ( +
+
+ +
{publishState !== "idle" && publishState !== "stopped" && ( -
+
🖥️ {t("publish.title")} @@ -14287,6 +14347,7 @@ function AppInner() { ? t("publish.viewers", { count: String(publishViewers.length) }) : t("publish.starting")} + {streamToggle(-1)}
))}
- )} + ); + return streamPopout + ? createPortal(
{grid}
, streamPopout.document.body) + : grid; + })()} {clientContextMenu && (
Konto) had its chance to bring in newer data. +// After a deploy, a page (or the service worker cache) can still point at +// chunk files that no longer exist, which used to leave a black screen. One +// fresh load fixes that; the flag stops a reload loop if the server is broken. +const RELOAD_FLAG = 'ws3-chunk-reload' +function reloadOnceForStaleChunks(): boolean { + try { + if (sessionStorage.getItem(RELOAD_FLAG)) return false + sessionStorage.setItem(RELOAD_FLAG, '1') + } catch { + return false + } + location.reload() + return true +} +window.addEventListener('vite:preloadError', (event) => { + if (reloadOnceForStaleChunks()) event.preventDefault() +}) + async function start() { - const { default: App } = await import('./App.tsx') + let App: typeof import('./App.tsx').default + try { + ;({ default: App } = await import('./App.tsx')) + } catch (error) { + if (reloadOnceForStaleChunks()) return + throw error + } + try { + sessionStorage.removeItem(RELOAD_FLAG) + } catch { + // storage blocked - nothing to clear + } startAutoSync() root.render(