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 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Hu2cuPLqpuKVfd9wWFFakU
This commit is contained in:
MoepchiandClaude Opus 5.5 committed 2026-11-05 11:28:51 +00:00
1 parent 10ae24a99f
commit d299343835
8 files changed
+75 -23

No files matched your search

+30 -8
View File
@@ -2588,17 +2588,18 @@ function SegmentedChoice<T extends string | number>({
}
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<string | null>("720");
const [source, setSource] = useState<"display" | "camera">("display");
const [audio, setAudio] = useState(true);
const [accessibility, setAccessibility] = useState<number>(StreamAccess.PUBLIC);
const [advanced, setAdvanced] = useState(false);
@@ -2644,6 +2645,18 @@ function StreamSettingsDialog({
<p className="ts-alpha-note">{t("publish.alphaNote")}</p>
<h4 className="ts-stream-settings-section">{t("publish.dialog.basic")}</h4>
<div className="ts-stream-settings-row">
<span>{t("publish.kind")}</span>
<SegmentedChoice
value={source}
onChange={setSource}
options={[
{ value: "display", label: `🖥️ ${t("publish.kind.display")}` },
{ value: "camera", label: `📷 ${t("publish.camera")}` },
]}
/>
</div>
<div className="ts-stream-settings-row">
<span>{t("publish.preset")}</span>
<SegmentedChoice
@@ -2659,8 +2672,16 @@ function StreamSettingsDialog({
<div className="ts-stream-settings-row">
<span>{t("publish.audio")}</span>
<label className="ts-stream-settings-toggle">
<input type="checkbox" checked={audio} onChange={(e) => setAudio(e.target.checked)} />
<label
className="ts-stream-settings-toggle"
title={source === "camera" ? t("publish.audio.cameraHint") : undefined}
>
<input
type="checkbox"
checked={audio && source === "display"}
disabled={source === "camera"}
onChange={(e) => setAudio(e.target.checked)}
/>
<span />
</label>
</div>
@@ -2731,7 +2752,7 @@ function StreamSettingsDialog({
<SegmentedChoice
value={audioBitrateKbps}
onChange={custom(setAudioBitrateKbps)}
disabled={!audio}
disabled={!audio || source === "camera"}
options={AUDIO_BITRATE_CHOICES.map((v) => ({ value: v, label: String(v) }))}
/>
</div>
@@ -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 && (
<StreamSettingsDialog
defaultName={`${ownClient?.name ?? "WebSpeak3"} - ${t("publish.screen")}`}
ownName={ownClient?.name ?? "WebSpeak3"}
onStart={handleStartPublishing}
onCancel={() => setStreamSettingsOpen(false)}
/>
+5 -1
View File
@@ -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",
+5 -1
View File
@@ -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",
+5 -1
View File
@@ -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",
+5 -1
View File
@@ -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": "مخاطبین",
+5 -1
View File
@@ -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": "Контакты",
+5 -1
View File
@@ -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": "联系人",
+15 -9
View File
@@ -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<void> {
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;
}