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() {