From d2993438351d2ac785a5a7bc70b491a76b2e3865 Mon Sep 17 00:00:00 2001 From: Moepchi Date: Thu, 5 Nov 2026 11:28:51 +0000 Subject: [PATCH] stream: add webcam as a stream source The stream dialog gets a source choice: screen/window via the browser picker, or the camera via getUserMedia, announced to TS6 as type=1 (CAMERA). Camera streams send no audio track, since that would be the microphone a second time. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Hu2cuPLqpuKVfd9wWFFakU --- web/src/App.tsx | 38 ++++++++++++++++++++++++++++++-------- web/src/locales/cs-CZ.json | 6 +++++- web/src/locales/de.json | 6 +++++- web/src/locales/en.json | 6 +++++- web/src/locales/fa.json | 6 +++++- web/src/locales/ru.json | 6 +++++- web/src/locales/zh-CN.json | 6 +++++- web/src/publish.ts | 24 +++++++++++++++--------- 8 files changed, 75 insertions(+), 23 deletions(-) diff --git a/web/src/App.tsx b/web/src/App.tsx index 7638c04..6c3d8a0 100644 --- a/web/src/App.tsx +++ b/web/src/App.tsx @@ -2588,17 +2588,18 @@ function SegmentedChoice({ } function StreamSettingsDialog({ - defaultName, + ownName, onStart, onCancel, }: { - defaultName: string; + ownName: string; onStart: (options: StreamPublishOptions) => void; onCancel: () => void; }) { const t = useT(); const backdrop = useBackdropDismiss(onCancel); const [preset, setPreset] = useState("720"); + const [source, setSource] = useState<"display" | "camera">("display"); const [audio, setAudio] = useState(true); const [accessibility, setAccessibility] = useState(StreamAccess.PUBLIC); const [advanced, setAdvanced] = useState(false); @@ -2644,6 +2645,18 @@ function StreamSettingsDialog({

{t("publish.alphaNote")}

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

+
+ {t("publish.kind")} + +
+
{t("publish.preset")} {t("publish.audio")} -
@@ -2731,7 +2752,7 @@ function StreamSettingsDialog({ ({ value: v, label: String(v) }))} /> @@ -2787,8 +2808,9 @@ function StreamSettingsDialog({ className="ts-stream-settings-go" onClick={() => onStart({ - name: defaultName, - audio, + name: `${ownName} - ${t(source === "camera" ? "publish.camera" : "publish.screen")}`, + source, + audio: audio && source === "display", accessibility, mode, viewerLimit, @@ -13976,7 +13998,7 @@ function AppInner() { {streamSettingsOpen && ( setStreamSettingsOpen(false)} /> diff --git a/web/src/locales/cs-CZ.json b/web/src/locales/cs-CZ.json index 6b99dcd..4c4cbdc 100644 --- a/web/src/locales/cs-CZ.json +++ b/web/src/locales/cs-CZ.json @@ -490,10 +490,13 @@ "publish.alphaTitle": "Alfa – nestabilní, může se kdykoli změnit nebo přestat fungovat", "publish.demoUnavailable": "Streamování není v demu dostupné – vyžaduje skutečný server TeamSpeak 6.", "publish.alphaNote": "Streamování je ve fázi alfa. Používá nezdokumentovaný protokol Stream/Call služby TeamSpeak 6, takže připojení, kvalita obrazu i práce s diváky mohou selhat nebo se bez upozornění změnit. Není určeno pro produkční použití.", - "publish.start": "Sdílet obrazovku", + "publish.start": "Sdílet obrazovku nebo kameru", "publish.stop": "Zastavit sdílení", "publish.title": "Vaše vysílání", "publish.screen": "Obrazovka", + "publish.camera": "Kamera", + "publish.kind": "Sdílet", + "publish.kind.display": "Obrazovka / okno", "publish.starting": "Spouštění…", "publish.viewers": "Sleduje {count} diváků", "publish.request.allow": "Povolit", @@ -508,6 +511,7 @@ "publish.preset": "Předvolba", "publish.preset.presentation": "Prezentace", "publish.audio": "Snímat zvuk", + "publish.audio.cameraHint": "U kamery jde tvůj zvuk jako obvykle přes mikrofon.", "publish.privacy": "Soukromí", "publish.privacy.public": "Veřejné", "publish.privacy.contacts": "Kontakty", diff --git a/web/src/locales/de.json b/web/src/locales/de.json index 34f66a5..227498f 100644 --- a/web/src/locales/de.json +++ b/web/src/locales/de.json @@ -490,10 +490,13 @@ "publish.alphaTitle": "Alpha – instabil, kann sich jederzeit ändern oder brechen", "publish.demoUnavailable": "Übertragen ist in der Demo nicht verfügbar – dafür braucht es einen echten TeamSpeak-6-Server.", "publish.alphaNote": "Streaming ist Alpha. Es spricht TeamSpeak 6s Stream/Call-Protokoll, das nicht dokumentiert ist – Verbindungsaufbau, Bildqualität und Zuschauerverwaltung können fehlschlagen oder sich ohne Vorankündigung ändern. Nicht für produktive Nutzung gedacht.", - "publish.start": "Bildschirm übertragen", + "publish.start": "Bildschirm oder Kamera übertragen", "publish.stop": "Übertragung beenden", "publish.title": "Deine Übertragung", "publish.screen": "Bildschirm", + "publish.camera": "Kamera", + "publish.kind": "Übertragen", + "publish.kind.display": "Bildschirm / Fenster", "publish.starting": "Wird gestartet…", "publish.viewers": "{count} Zuschauer", "publish.request.allow": "Zulassen", @@ -508,6 +511,7 @@ "publish.preset": "Voreinstellung", "publish.preset.presentation": "Präsentation", "publish.audio": "Audio aufnehmen", + "publish.audio.cameraHint": "Bei der Kamera läuft dein Ton wie gewohnt übers Mikrofon.", "publish.privacy": "Privatsphäre", "publish.privacy.public": "Öffentlich", "publish.privacy.contacts": "Kontakte", diff --git a/web/src/locales/en.json b/web/src/locales/en.json index 1016f36..30a8da5 100644 --- a/web/src/locales/en.json +++ b/web/src/locales/en.json @@ -490,10 +490,13 @@ "publish.alphaTitle": "Alpha - unstable, may change or break at any time", "publish.demoUnavailable": "Streaming is not available in the demo - it needs a real TeamSpeak 6 server.", "publish.alphaNote": "Streaming is alpha. It speaks TeamSpeak 6's undocumented Stream/Call protocol, so connecting, picture quality and viewer handling can fail or change without notice. Not meant for production use.", - "publish.start": "Share your screen", + "publish.start": "Share your screen or camera", "publish.stop": "Stop sharing", "publish.title": "Your broadcast", "publish.screen": "Screen", + "publish.camera": "Camera", + "publish.kind": "Share", + "publish.kind.display": "Screen / window", "publish.starting": "Starting…", "publish.viewers": "{count} watching", "publish.request.allow": "Allow", @@ -508,6 +511,7 @@ "publish.preset": "Preset", "publish.preset.presentation": "Presentation", "publish.audio": "Capture audio", + "publish.audio.cameraHint": "With the camera, your sound goes out through your microphone as usual.", "publish.privacy": "Privacy", "publish.privacy.public": "Public", "publish.privacy.contacts": "Contacts", diff --git a/web/src/locales/fa.json b/web/src/locales/fa.json index 3f3929e..095a91c 100644 --- a/web/src/locales/fa.json +++ b/web/src/locales/fa.json @@ -489,10 +489,13 @@ "publish.alphaTitle": "آلفا - ناپایدار، ممکن است هر زمان تغییر کند یا از کار بیفتد", "publish.demoUnavailable": "پخش زنده در حالت دمو در دسترس نیست - به یک سرور واقعی TeamSpeak 6 نیاز دارد.", "publish.alphaNote": "پخش زنده در مرحله آلفا است. این ویژگی از پروتکل مستندنشده Stream/Call در TeamSpeak 6 استفاده می‌کند، بنابراین اتصال، کیفیت تصویر و مدیریت بینندگان ممکن است بدون اطلاع قبلی دچار خطا شوند یا تغییر کنند. برای استفاده تولیدی مناسب نیست.", - "publish.start": "اشتراک‌گذاری صفحه", + "publish.start": "اشتراک‌گذاری صفحه یا دوربین", "publish.stop": "توقف اشتراک‌گذاری", "publish.title": "پخش زنده تو", "publish.screen": "صفحه نمایش", + "publish.camera": "دوربین", + "publish.kind": "اشتراک‌گذاری", + "publish.kind.display": "صفحه / پنجره", "publish.starting": "در حال شروع…", "publish.viewers": "{count} بیننده", "publish.request.allow": "اجازه دادن", @@ -507,6 +510,7 @@ "publish.preset": "پیش‌تنظیم", "publish.preset.presentation": "ارائه", "publish.audio": "ضبط صدا", + "publish.audio.cameraHint": "با دوربین، صدای شما مثل همیشه از طریق میکروفون ارسال می‌شود.", "publish.privacy": "حریم خصوصی", "publish.privacy.public": "عمومی", "publish.privacy.contacts": "مخاطبین", diff --git a/web/src/locales/ru.json b/web/src/locales/ru.json index 75de22e..05881d8 100644 --- a/web/src/locales/ru.json +++ b/web/src/locales/ru.json @@ -490,10 +490,13 @@ "publish.alphaTitle": "Альфа - нестабильно, может измениться или сломаться в любой момент", "publish.demoUnavailable": "Трансляция недоступна в демо - нужен настоящий сервер TeamSpeak 6.", "publish.alphaNote": "Трансляция находится в альфе. Она использует недокументированный протокол Stream/Call TeamSpeak 6, поэтому подключение, качество изображения и работа со зрителями могут сбоить или меняться без предупреждения. Не для рабочего использования.", - "publish.start": "Показать экран", + "publish.start": "Показать экран или камеру", "publish.stop": "Остановить показ", "publish.title": "Ваша трансляция", "publish.screen": "Экран", + "publish.camera": "Камера", + "publish.kind": "Показать", + "publish.kind.display": "Экран / окно", "publish.starting": "Запуск…", "publish.viewers": "Смотрят: {count}", "publish.request.allow": "Разрешить", @@ -508,6 +511,7 @@ "publish.preset": "Пресет", "publish.preset.presentation": "Презентация", "publish.audio": "Захватывать звук", + "publish.audio.cameraHint": "С камерой звук, как обычно, идёт через микрофон.", "publish.privacy": "Приватность", "publish.privacy.public": "Публичная", "publish.privacy.contacts": "Контакты", diff --git a/web/src/locales/zh-CN.json b/web/src/locales/zh-CN.json index f8083fd..63061d9 100644 --- a/web/src/locales/zh-CN.json +++ b/web/src/locales/zh-CN.json @@ -702,10 +702,13 @@ "publish.alphaTitle": "内测阶段 —— 不稳定,可能随时变更或失效", "publish.demoUnavailable": "演示模式下无法使用直播功能 —— 需要真实的 TeamSpeak 6 服务器。", "publish.alphaNote": "直播功能处于内测阶段,使用的是 TeamSpeak 6 未公开文档的 Stream/Call 协议,因此连接、画质和观众处理可能会出错或在无预警的情况下发生变化,不建议用于正式场合。", - "publish.start": "共享屏幕", + "publish.start": "共享屏幕或摄像头", "publish.stop": "停止共享", "publish.title": "你的直播", "publish.screen": "屏幕", + "publish.camera": "摄像头", + "publish.kind": "共享内容", + "publish.kind.display": "屏幕 / 窗口", "publish.starting": "启动中…", "publish.viewers": "{count} 人观看", "publish.request.allow": "允许", @@ -720,6 +723,7 @@ "publish.preset": "预设", "publish.preset.presentation": "演示", "publish.audio": "采集音频", + "publish.audio.cameraHint": "使用摄像头时,你的声音照常通过麦克风发送。", "publish.privacy": "可见范围", "publish.privacy.public": "公开", "publish.privacy.contacts": "联系人", diff --git a/web/src/publish.ts b/web/src/publish.ts index 82bd30d..b1a846a 100644 --- a/web/src/publish.ts +++ b/web/src/publish.ts @@ -46,6 +46,8 @@ export const StreamMode = { export interface StreamPublishOptions { name: string; + /** Screen/window via the browser's picker, or the webcam. */ + source: "display" | "camera"; /** Send the capture's audio track too, when the source has one. */ audio: boolean; /** One of StreamAccess. */ @@ -112,15 +114,16 @@ export class StreamPublisher { } /** - * Captures a screen and announces the stream. + * Captures a screen or the webcam and announces the stream. * - * `getDisplayMedia` is secure-context-only, so this throws on a plain-http + * Both capture APIs are secure-context-only, so this fails on a plain-http * origin - the same limitation the microphone already has. */ async start(options: StreamPublishOptions): Promise { if (this.state === "live" || this.state === "starting") return; - if (!navigator.mediaDevices?.getDisplayMedia) { - this.fail("Screen sharing requires HTTPS (or localhost) - the site is not a secure context."); + const camera = options.source === "camera"; + if (!(camera ? navigator.mediaDevices?.getUserMedia : navigator.mediaDevices?.getDisplayMedia)) { + this.fail("Streaming requires HTTPS (or localhost) - the site is not a secure context."); return; } @@ -132,13 +135,15 @@ export class StreamPublisher { if (options.fps > 0) video.frameRate = { ideal: options.fps }; try { - this.media = await navigator.mediaDevices.getDisplayMedia({ - video: Object.keys(video).length > 0 ? video : true, - audio: options.audio, - }); + const constraints = { video: Object.keys(video).length > 0 ? video : true }; + // A camera's "audio" would be the microphone, which already goes out as + // voice - sending it again would only echo. + this.media = camera + ? await navigator.mediaDevices.getUserMedia({ ...constraints, audio: false }) + : await navigator.mediaDevices.getDisplayMedia({ ...constraints, audio: options.audio }); } catch (err) { this.setState("idle"); - this.fail(`Could not capture the screen: ${describe(err)}`); + this.fail(`Could not capture the ${camera ? "camera" : "screen"}: ${describe(err)}`); return; } @@ -423,6 +428,7 @@ export class StreamPublisher { * advance. A browser tab has no TS6 equivalent and reads closest to a window. */ private detectSourceType(): number { + if (this.options?.source === "camera") return StreamSource.CAMERA; const surface = this.media?.getVideoTracks()[0]?.getSettings().displaySurface; return surface === "monitor" ? StreamSource.SCREEN : StreamSource.WINDOW; }