From 115cd7150e240961582d86d7fd48c9f51b25640c Mon Sep 17 00:00:00 2001 From: Moepchi Date: Thu, 10 Sep 2026 20:05:56 +0000 Subject: [PATCH] web: TS6's stream-start options in the publish dialog MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit TS6 shows a settings dialog before going live; this builds the same set into webspeak3, split into Basic (preset, capture audio, privacy) and an Advanced section (resolution, FPS, bitrate, audio bitrate, viewer limit, connection mode). The three numeric setupstream fields are enums lifted out of TS6's own main.js rather than guessed (findings §10): source NONE/CAMERA/SCREEN/ WINDOW/EXISTING_SESSION, accessibility NONE/PUBLIC/CONTACTS_ONLY/PRIVATE, mode NONE/P2P/SFU. We had been sending type=3 (WINDOW) unconditionally; detectSourceType() now picks SCREEN for displaySurface === "monitor". Resolution, FPS and the two bitrates are not protocol fields. They are applied locally: capture constraints, track.contentHint, and sender.setParameters() with encoding.maxBitrate. bitrate= on the wire is advisory - the server echoes back its own number either way. Connection mode "Server" (SFU) is rendered disabled with a tooltip. That path is a separate transport (requeststreamsfuaccessinfo -> mediasoup) that we have not built, and announcing mode=2 without it would publish a stream nobody could watch. Co-Authored-By: Claude Opus 5 Claude-Session: https://claude.ai/code/session_01Hu2cuPLqpuKVfd9wWFFakU --- web/src/App.css | 100 +++++++++++++++ web/src/App.tsx | 304 +++++++++++++++++++++++++++++++++++++++++++-- web/src/i18n.tsx | 44 +++++++ web/src/publish.ts | 116 ++++++++++++++--- 4 files changed, 537 insertions(+), 27 deletions(-) diff --git a/web/src/App.css b/web/src/App.css index 9300849..ada726e 100644 --- a/web/src/App.css +++ b/web/src/App.css @@ -1464,6 +1464,106 @@ font-size: 0.85em; } +/* TS6's stream dialog, rebuilt: labelled rows with a segmented control on the + right. The segments wrap on narrow screens rather than overflowing. */ +.ts-stream-settings { + width: min(680px, calc(100vw - 2rem)); +} + +.ts-stream-settings-section { + margin: 0.9rem 0 0.4rem; + color: var(--accent); + font-size: 1rem; + font-weight: 600; +} + +.ts-stream-settings-expand { + display: flex; + width: 100%; + justify-content: space-between; + align-items: center; + padding: 0; + background: none; + border: none; + cursor: pointer; + text-align: left; +} + +.ts-stream-settings-row { + display: flex; + gap: 0.75rem; + align-items: center; + justify-content: space-between; + flex-wrap: wrap; + padding: 0.35rem 0; +} + +.ts-stream-settings-row > span:first-child { + opacity: 0.85; +} + +.ts-segmented { + display: flex; + flex-wrap: wrap; + gap: 2px; + padding: 2px; + background: var(--bg-toolbar-2, rgba(0, 0, 0, 0.2)); + border: 1px solid var(--border-soft); + border-radius: 999px; +} + +.ts-segmented button { + padding: 0.25rem 0.7rem; + background: none; + border: none; + border-radius: 999px; + color: inherit; + cursor: pointer; + white-space: nowrap; +} + +.ts-segmented button:disabled { + opacity: 0.4; + cursor: not-allowed; +} + +.ts-segmented button.ts-segmented-on { + background: color-mix(in srgb, var(--accent) 25%, transparent); + box-shadow: inset 0 0 0 1px var(--accent); +} + +.ts-stream-settings-stepper { + display: flex; + gap: 0.35rem; + align-items: center; +} + +.ts-stream-settings-stepper input { + width: 5.5rem; + text-align: center; +} + +.ts-stream-settings-stepper button { + width: 1.9rem; + border-radius: 999px; +} + +.ts-stream-settings-unit { + opacity: 0.7; +} + +.ts-stream-settings-toggle input { + width: 2.4rem; + height: 1.3rem; +} + +.ts-stream-settings-go { + border-radius: 999px; + background: var(--accent); + color: #fff; + padding-inline: 1.2rem; +} + .ts-stream-panel-publish { border-color: var(--accent); } diff --git a/web/src/App.tsx b/web/src/App.tsx index c20abcc..de0ed3d 100644 --- a/web/src/App.tsx +++ b/web/src/App.tsx @@ -26,7 +26,13 @@ import { pickAudioOutputDevice, } from "./voice"; import { LanguageProvider, useLanguage, useT, type LangPref } from "./i18n"; -import { StreamPublisher, type PublishState } from "./publish"; +import { + StreamAccess, + StreamMode, + StreamPublisher, + type PublishState, + type StreamPublishOptions, +} from "./publish"; import { StreamViewer, parseStreamInfo, type StreamEvent, type StreamInfo } from "./stream"; import { DEMO_HOST, DEMO_MODE, DemoSocket } from "./demoMode"; import { @@ -1586,6 +1592,277 @@ function ChannelPasswordDialog({ ); } +/** + * Presets from TS6's own stream dialog. Each one fills in the advanced + * fields; "source" keeps the capture's native resolution and "presentation" + * trades frame rate for sharp text, which is what the encoder's content hint + * is for. + */ +const STREAM_PRESETS: Record< + string, + { height: number; fps: number; videoBitrateKbps: number; contentHint: "motion" | "detail" } +> = { + "360": { height: 360, fps: 30, videoBitrateKbps: 1000, contentHint: "motion" }, + "480": { height: 480, fps: 30, videoBitrateKbps: 1500, contentHint: "motion" }, + "720": { height: 720, fps: 30, videoBitrateKbps: 2500, contentHint: "motion" }, + "1080": { height: 1080, fps: 30, videoBitrateKbps: 4000, contentHint: "motion" }, + "1440": { height: 1440, fps: 30, videoBitrateKbps: 6000, contentHint: "motion" }, + source: { height: 0, fps: 60, videoBitrateKbps: 8000, contentHint: "motion" }, + presentation: { height: 0, fps: 5, videoBitrateKbps: 3000, contentHint: "detail" }, +}; + +const RESOLUTION_CHOICES = [360, 480, 720, 1080, 1440, 0]; +const FPS_CHOICES = [5, 30, 60]; +const AUDIO_BITRATE_CHOICES = [64, 96, 128, 192, 256, 320]; + +function SegmentedChoice({ + value, + options, + onChange, + disabled, +}: { + value: T; + options: { value: T; label: string; title?: string; disabled?: boolean }[]; + onChange: (value: T) => void; + disabled?: boolean; +}) { + return ( +
+ {options.map((option) => ( + + ))} +
+ ); +} + +function StreamSettingsDialog({ + defaultName, + onStart, + onCancel, +}: { + defaultName: string; + onStart: (options: StreamPublishOptions) => void; + onCancel: () => void; +}) { + const t = useT(); + const backdrop = useBackdropDismiss(onCancel); + const [preset, setPreset] = useState("720"); + const [audio, setAudio] = useState(true); + const [accessibility, setAccessibility] = useState(StreamAccess.PUBLIC); + const [advanced, setAdvanced] = useState(false); + const [height, setHeight] = useState(STREAM_PRESETS["720"]!.height); + const [fps, setFps] = useState(STREAM_PRESETS["720"]!.fps); + const [videoBitrateKbps, setVideoBitrateKbps] = useState(STREAM_PRESETS["720"]!.videoBitrateKbps); + const [audioBitrateKbps, setAudioBitrateKbps] = useState(128); + const [viewerLimit, setViewerLimit] = useState(0); + const [mode, setMode] = useState(StreamMode.P2P); + const [contentHint, setContentHint] = useState<"motion" | "detail">("motion"); + + const applyPreset = (key: string) => { + const p = STREAM_PRESETS[key]; + if (!p) return; + setPreset(key); + setHeight(p.height); + setFps(p.fps); + setVideoBitrateKbps(p.videoBitrateKbps); + setContentHint(p.contentHint); + }; + + // Any hand-tuned value means the result is no longer one of the presets, so + // the highlight is dropped rather than left lying about what will be sent. + const custom = (setter: (value: T) => void) => (value: T) => { + setter(value); + setPreset(null); + }; + + const resolutionLabel = (value: number) => (value === 0 ? t("publish.res.source") : String(value)); + + return ( +
+
e.stopPropagation()}> +
+ {t("publish.dialog.title")} + +
+
+

{t("publish.dialog.basic")}

+ +
+ {t("publish.preset")} + ({ value: k, label: k })), + { value: "source", label: t("publish.res.source") }, + { value: "presentation", label: t("publish.preset.presentation") }, + ]} + /> +
+ +
+ {t("publish.audio")} + +
+ +
+ {t("publish.privacy")} + +
+ + + + {advanced && ( + <> +
+ {t("publish.resolution")} + ({ value: v, label: resolutionLabel(v) }))} + /> +
+ +
+ {t("publish.fps")} + ({ value: v, label: String(v) }))} + /> +
+ +
+ {t("publish.bitrate")} +
+ + custom(setVideoBitrateKbps)(Math.max(200, Number(e.target.value) || 200))} + /> + Kbps + +
+
+ +
+ {t("publish.audioBitrate")} + ({ value: v, label: String(v) }))} + /> +
+ +
+ {t("publish.viewerLimit")} +
+ + setViewerLimit(Math.max(0, Number(e.target.value) || 0))} + /> + +
+
+ +
+ {t("publish.mode")} + +
+ + )} +
+
+
+ + +
+
+
+
+ ); +} + function UpdatePrompt() { const t = useT(); const { @@ -5386,6 +5663,7 @@ function AppInner() { const [publishError, setPublishError] = useState(null); const publisherRef = useRef(null); const publishPreviewRef = useRef(null); + const [streamSettingsOpen, setStreamSettingsOpen] = useState(false); const streamVideoRef = useRef(null); /** Clients we already pulled a `notifystreaminfo` for, so we ask only once. */ const requestedStreamInfoRef = useRef>(new Set()); @@ -7655,12 +7933,17 @@ function AppInner() { setPublishViewers([]); }; - const handleStartPublishing = () => { - if (ownClientId === null) return; + const handleStreamButton = () => { if (publisherRef.current) { handleStopPublishing(); return; } + setStreamSettingsOpen(true); + }; + + const handleStartPublishing = (options: StreamPublishOptions) => { + if (ownClientId === null) return; + setStreamSettingsOpen(false); setPublishError(null); const publisher = new StreamPublisher({ send: (message) => socketRef.current?.send(JSON.stringify(message)), @@ -7678,11 +7961,7 @@ function AppInner() { onError: setPublishError, }); publisherRef.current = publisher; - void publisher.start({ - name: `${ownClient?.name ?? "WebSpeak3"} - ${t("publish.screen")}`, - bitrate: 1_500_000, - audio: true, - }); + void publisher.start(options); }; const handleShowClientConnectionInfo = (clientId: number, clientName: string) => { @@ -8785,7 +9064,7 @@ function AppInner() {