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 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Hu2cuPLqpuKVfd9wWFFakU
This commit is contained in:
MoepchiandClaude Opus 5.5 committed 2026-11-30 21:38:18 +00:00
1 parent 73ae268dfb
commit 8fbd591efa
5 files changed
+167 -16

No files matched your search

+54 -6
View File
@@ -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;
+75 -9
View File
@@ -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<Record<number, WatchedStream>>({});
const streamViewersRef = useRef<Map<number, 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);
/** Separate browser window the stream grid is portalled into, if popped out. */
const [streamPopout, setStreamPopout] = useState<Window | null>(null);
const [publishState, setPublishState] = useState<PublishState>("idle");
const [publishViewers, setPublishViewers] = useState<number[]>([]);
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) => (
<button
className="ts-stream-panel-close"
onClick={() => setFocusedStream((cur) => (cur === id ? null : id))}
title={t(focusedStream === id ? "stream.unfocus" : "stream.focus")}
>
{focusedStream === id ? "⤡" : "⤢"}
</button>
);
return (
<DisplayPrefsContext.Provider value={displayPrefs}>
<div
className={`ts-app ts-theme-${theme}${designThemeClassName(designTheme)}${
activeCustomTheme ? " ts-design-custom" : ""
}${demoForceMobile ? " ts-force-mobile" : ""}${mobile ? ` ts-mobile ts-mobile-tab-${mobileTab}` : ""}${novaSplash ? " ts-nova-splash" : ""}${
className={`${themeClassName}${demoForceMobile ? " ts-force-mobile" : ""}${mobile ? ` ts-mobile ts-mobile-tab-${mobileTab}` : ""}${novaSplash ? " ts-nova-splash" : ""}${
designTheme === "ide" && !idePixelFont ? " ts-ide-plain-font" : ""
}`}
data-custom-theme={activeCustomTheme?.id}
@@ -14274,10 +14325,19 @@ function AppInner() {
onCancel={() => setStreamSettingsOpen(false)}
/>
)}
{(Object.keys(watchedStreams).length > 0 || (publishState !== "idle" && publishState !== "stopped")) && (
<div className="ts-stream-panels">
{streamTileCount > 0 && (() => {
const grid = (
<div
className={`ts-stream-panels${streamPopout ? " ts-stream-panels-popout" : ""}`}
style={{ "--stream-cols": Math.min(streamTileCount, 2) } as React.CSSProperties}
>
<div className="ts-stream-toolbar">
<button onClick={streamPopout ? closeStreamPopout : openStreamPopout}>
{streamPopout ? `⇲ ${t("stream.popin")}` : `⧉ ${t("stream.popout")}`}
</button>
</div>
{publishState !== "idle" && publishState !== "stopped" && (
<div className="ts-stream-panel ts-stream-panel-publish">
<div className={`ts-stream-panel ts-stream-panel-publish${focusedStream === -1 ? " ts-stream-panel-focused" : ""}`}>
<div className="ts-stream-panel-header">
<span className="ts-stream-panel-title">
🖥️ {t("publish.title")} <AlphaBadge />
@@ -14287,6 +14347,7 @@ function AppInner() {
? t("publish.viewers", { count: String(publishViewers.length) })
: t("publish.starting")}
</span>
{streamToggle(-1)}
<button
className="ts-stream-panel-close"
onClick={handleStopPublishing}
@@ -14325,7 +14386,7 @@ function AppInner() {
</div>
)}
{Object.entries(watchedStreams).map(([clid, watched]) => (
<div className="ts-stream-panel" key={clid}>
<div className={`ts-stream-panel${focusedStream === Number(clid) ? " ts-stream-panel-focused" : ""}`} key={clid}>
<div className="ts-stream-panel-header">
<span className="ts-stream-panel-title">
📺 {watched.info.name || t("stream.untitled")} <AlphaBadge />
@@ -14333,6 +14394,7 @@ function AppInner() {
<span className="ts-stream-panel-state">
{watched.state === "connected" ? t("stream.live") : t(`stream.state.${watched.state}`)}
</span>
{streamToggle(Number(clid))}
<button
className="ts-stream-panel-close"
onClick={() => handleStopWatchingStream(Number(clid))}
@@ -14355,7 +14417,11 @@ function AppInner() {
</div>
))}
</div>
)}
);
return streamPopout
? createPortal(<div className={`${themeClassName} ts-stream-popout-root`}>{grid}</div>, streamPopout.document.body)
: grid;
})()}
{clientContextMenu && (
<div
ref={clientContextMenuRef}
+4
View File
@@ -533,6 +533,10 @@
"publish.mode.server": "Server",
"publish.mode.serverUnavailable": "Der Server-Modus läuft über TS6s SFU und ist noch nicht implementiert.",
"stream.untitled": "Stream",
"stream.popout": "In eigenem Fenster",
"stream.popin": "Zurück ins Hauptfenster",
"stream.focus": "Vergrößern",
"stream.unfocus": "Zurück zum Raster",
"stream.stop": "Stream schließen",
"stream.live": "Live",
"stream.state.new": "Warte auf Angebot…",
+4
View File
@@ -533,6 +533,10 @@
"publish.mode.server": "Server",
"publish.mode.serverUnavailable": "Server mode goes through TS6's SFU and is not implemented yet.",
"stream.untitled": "Stream",
"stream.popout": "Open in own window",
"stream.popin": "Back to main window",
"stream.focus": "Enlarge",
"stream.unfocus": "Back to grid",
"stream.stop": "Close stream",
"stream.live": "Live",
"stream.state.new": "Waiting for offer…",
+30 -1
View File
@@ -22,8 +22,37 @@ const root = createRoot(document.getElementById('root')!)
// App reads its stored identities/favorites while loading, so it's imported only after the vault is open
// and the sync account (Options -> 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(
<StrictMode>