Early video retransmissions could be rejected before an SFU publication admitted its primary stream. The shared RTP reader now restores the associated primary identity before admission. A repository audit also found ownership omissions in Viewer input retirement, queued route work, partially constructed connections and sender-evidence cleanup; each is corrected at its existing owner without changing routing or adaptation policy. The same phase fixes bounded Linux diagnostic encoding, picker/tooltip keyboard and touch behavior, and stale-language notices. Documentation now reflects current App, room and media lifecycles. Theme-role consolidation remains deferred. Validation: complete Web check (1,685 tests, type-check and build); Windows Go core tests/vet/cross-builds; Linux CI race/vulnerability checks and all seven package targets; native Linux diagnostic fixtures on both architectures; actual Chromium/Pion SFU decode, live settings, reload/recovery and resource-retirement gate; documentation and website builds. Confirmed defects were compared against their baseline and independently reviewed. No protocol, configuration or persistence migration is required. Physical device limits and unmatched field reports remain open. ## Release notes ### 中文 这是一次分享稳定性与交互细节维护更新,兼容现有 2.x 客户端和站点。 - 修复部分服务器中转开播失败:较早到达的视频重传包不再被误判,导致媒体发布提前结束。 - 修复停播后快速重新分享时,旧任务可能拖延新线路准备的问题。 - 撤销邀请或替换观众会话时,同步清理对应的远控输入身份,保留其他观众的正常使用。 - 改善连接失败、观众反复加入退出后的资源回收;避免 Linux 单路输出的错误信息意外中断整个分享。 - 修正选源、互动和线路提示的键盘/触屏操作;切换语言后,当前校验与错误提示会同步更新。 ### English This maintenance update improves sharing reliability and interaction details. It remains compatible with existing 2.x Apps and Sites. - Fix an SFU startup failure caused by video retransmissions arriving before the primary stream was admitted. - Prevent retired sharing tasks from delaying route preparation after a quick stop and restart. - Retire remote-input identities when invitations are revoked or Viewer sessions are replaced, while preserving other participants. - Release resources correctly after connection failures and repeated Viewer churn; prevent Linux output diagnostics from unexpectedly ending the whole share. - Improve keyboard and touch behavior in source selection, interactions and route help. Active validation and error messages now follow language changes.
466 lines
19 KiB
TypeScript
466 lines
19 KiB
TypeScript
import { useCallback, useEffect, useId, useRef, useState, type CSSProperties } from "react";
|
|
|
|
import type { NativeCaptureTarget } from "../../native/wire";
|
|
import { audioApplicationKey, audioApplications, nativeCaptureTargetKey } from "../../native/capture-selection";
|
|
import { useCopy } from "../../ui/copy";
|
|
import { Glyph, type GlyphName } from "../../ui/icons";
|
|
import { navigateTabs } from "../../ui/tab-navigation";
|
|
import { Tooltip } from "./Tooltip";
|
|
import { HintComic } from "./hints";
|
|
import { Pill } from "./primitives";
|
|
import { CameraSources, useCameraSources } from "./CameraSources";
|
|
import { CaptureSourceCard } from "./CaptureSourceCard";
|
|
import { AudioExclusionSelect } from "./AudioExclusionSelect";
|
|
import { AppConnectionButton } from "./AppConnectionButton";
|
|
import type { loadCameraPreviews } from "../../media/camera-previews";
|
|
|
|
const SOURCE_TABS = ["browser", "camera", "window", "display"] as const;
|
|
type SourceTab = (typeof SOURCE_TABS)[number];
|
|
const SOURCE_ICONS = {
|
|
browser: "globe",
|
|
window: "window",
|
|
display: "display",
|
|
camera: "camera",
|
|
} satisfies Record<SourceTab, GlyphName>;
|
|
|
|
export type NativeSourceList =
|
|
| { kind: "browser" }
|
|
| { kind: "loading" }
|
|
| { kind: "unavailable" }
|
|
| { kind: "incompatible" }
|
|
| { kind: "unsupported" }
|
|
| { kind: "failed" }
|
|
| {
|
|
kind: "ready";
|
|
sources: NativeCaptureTarget[];
|
|
processAudio: boolean;
|
|
systemAudio: boolean;
|
|
processAudioExclusion?: boolean;
|
|
captureBorderControl?: boolean;
|
|
};
|
|
|
|
export function CaptureSourcePicker({
|
|
nativeSources,
|
|
onBrowser,
|
|
onCamera,
|
|
onNative,
|
|
onPreview,
|
|
onRefresh,
|
|
onCancel,
|
|
onAppConnected,
|
|
browserAvailable = true,
|
|
cameraAvailable = !!onCamera,
|
|
initialTab = "window",
|
|
initialCamera = "",
|
|
activeCameraVideo,
|
|
loadCameras,
|
|
initialAudio = true,
|
|
initialShowCaptureBorder = false,
|
|
initialExcludeAudio,
|
|
audioLocked = false,
|
|
selectionDisabled = false,
|
|
}: {
|
|
nativeSources: NativeSourceList;
|
|
onBrowser: () => void;
|
|
onCamera?: (deviceId: string) => void;
|
|
initialCamera?: string;
|
|
activeCameraVideo?: HTMLVideoElement | null;
|
|
loadCameras?: typeof loadCameraPreviews;
|
|
onNative: (target: NativeCaptureTarget, audio: boolean, showCaptureBorder: boolean, excludeAudio?: NativeCaptureTarget) => void;
|
|
onPreview: (
|
|
target: NativeCaptureTarget,
|
|
signal?: AbortSignal,
|
|
) => Promise<string | null>;
|
|
onRefresh: () => void;
|
|
onCancel: () => void;
|
|
onAppConnected?: () => void;
|
|
browserAvailable?: boolean;
|
|
cameraAvailable?: boolean;
|
|
initialTab?: SourceTab;
|
|
initialAudio?: boolean;
|
|
initialShowCaptureBorder?: boolean;
|
|
initialExcludeAudio?: NativeCaptureTarget;
|
|
audioLocked?: boolean;
|
|
selectionDisabled?: boolean;
|
|
}) {
|
|
const { vis, t } = useCopy();
|
|
const pickerId = useId();
|
|
const panelRef = useRef<HTMLDivElement>(null);
|
|
const [tab, setTab] = useState<SourceTab | null>(null);
|
|
const [shareAudio, setShareAudio] = useState(initialAudio);
|
|
const [showCaptureBorder, setShowCaptureBorder] = useState(initialShowCaptureBorder);
|
|
const [excludeAudio, setExcludeAudio] = useState(initialExcludeAudio);
|
|
const appDetected = nativeSources.kind === "ready" || nativeSources.kind === "failed" ||
|
|
nativeSources.kind === "unsupported" || nativeSources.kind === "incompatible";
|
|
const tabs = SOURCE_TABS.filter((value) => appDetected || value === "browser" || value === "camera");
|
|
const preferredTab = tab ?? initialTab;
|
|
const tabAvailable = (value: SourceTab) => value === "camera" ? cameraAvailable
|
|
: value === "browser" || nativeSources.kind === "browser" ? browserAvailable : true;
|
|
const activeTab = tabs.includes(preferredTab) && tabAvailable(preferredTab)
|
|
? preferredTab : tabs.find(tabAvailable) ?? "browser";
|
|
const nativeTab = activeTab === "window" || activeTab === "display";
|
|
const browserCapture = activeTab === "browser";
|
|
const cameraSources = useCameraSources(activeTab === "camera", activeCameraVideo, loadCameras);
|
|
const supportsCaptureBorder = nativeTab && nativeSources.kind === "ready" && nativeSources.captureBorderControl === true;
|
|
const issueKey = !nativeTab ? null : nativeSources.kind === "incompatible" ? "native.incompatible"
|
|
: (nativeSources.kind === "unsupported" || nativeSources.kind === "failed")
|
|
? `host.sourcePicker.${nativeSources.kind}` as const
|
|
: null;
|
|
|
|
useEffect(() => {
|
|
const cancelOnEscape = (event: KeyboardEvent) => {
|
|
if (event.key !== "Escape" || event.defaultPrevented || event.isComposing ||
|
|
panelRef.current?.querySelector('[popover="auto"]:popover-open') ||
|
|
!panelRef.current?.contains(event.target as Node | null)) return;
|
|
event.preventDefault();
|
|
onCancel();
|
|
};
|
|
window.addEventListener("keydown", cancelOnEscape);
|
|
return () => window.removeEventListener("keydown", cancelOnEscape);
|
|
}, [onCancel]);
|
|
|
|
const sources =
|
|
nativeTab && nativeSources.kind === "ready"
|
|
? nativeSources.sources.filter(
|
|
(target) => target.kind === activeTab || target.kind === "picker",
|
|
)
|
|
: [];
|
|
const supportsAudio = (target: NativeCaptureTarget): boolean =>
|
|
nativeSources.kind === "ready" &&
|
|
(target.kind === "window"
|
|
? nativeSources.processAudio
|
|
: nativeSources.systemAudio);
|
|
const anyNativeAudio = sources.some(supportsAudio);
|
|
// Source enumeration already owns process identity; do not create a second app scanner.
|
|
const applications = nativeSources.kind === "ready" ? audioApplications(nativeSources.sources) : [];
|
|
const exclusionKey = excludeAudio ? audioApplicationKey(excludeAudio) : "";
|
|
const canExcludeAudio = activeTab === "display" && nativeSources.kind === "ready" && nativeSources.processAudioExclusion;
|
|
const missingExclusion = !!excludeAudio && !applications.some(target => audioApplicationKey(target) === exclusionKey);
|
|
const exclusionUnavailable = activeTab === "display" && shareAudio && !!excludeAudio && (!canExcludeAudio || missingExclusion);
|
|
const refreshing = activeTab === "camera" ? cameraSources.busy : nativeSources.kind === "loading";
|
|
const refreshLabel = t(refreshing ? "host.sourcePicker.loading" : "host.sourcePicker.refresh");
|
|
const audioAction = t(!anyNativeAudio ? "host.noAudio" : audioLocked
|
|
? "host.sourcePicker.audioLocked"
|
|
: shareAudio ? "host.sourcePicker.audioOff" : "host.sourcePicker.audioOn");
|
|
const audioLabel = t(
|
|
activeTab === "window" && sources.some((target) => target.kind === "window")
|
|
? "host.sourcePicker.windowAudio"
|
|
: "host.sourcePicker.systemAudio",
|
|
);
|
|
const refreshButton = (
|
|
<button
|
|
type="button"
|
|
className="lr-source-picker-refresh"
|
|
aria-label={refreshLabel}
|
|
disabled={refreshing}
|
|
onClick={activeTab === "camera" ? cameraSources.refresh : onRefresh}
|
|
>
|
|
<Glyph name="refresh" size={18} className={refreshing ? "lr-spin" : undefined} />
|
|
</button>
|
|
);
|
|
const closeButton = (
|
|
<button
|
|
type="button"
|
|
className="lr-source-picker-close"
|
|
aria-label={t("common.cancel")}
|
|
onClick={onCancel}
|
|
autoFocus
|
|
>
|
|
<Glyph name="x" size={18} />
|
|
</button>
|
|
);
|
|
const audioSwitch = (
|
|
<button
|
|
type="button"
|
|
className="lr-switch"
|
|
role="switch"
|
|
aria-checked={shareAudio && anyNativeAudio}
|
|
aria-label={audioLabel}
|
|
disabled={audioLocked || !anyNativeAudio}
|
|
onClick={() => setShareAudio((current) => !current)}
|
|
/>
|
|
);
|
|
|
|
return (
|
|
<div
|
|
ref={panelRef}
|
|
className={`lr-tv-overlay lr-source-picker${vis ? " is-visual" : ""}`}
|
|
role="dialog"
|
|
aria-label={t("host.sourcePicker.title")}
|
|
onKeyDown={event => {
|
|
if (event.key !== "Tab" || event.defaultPrevented || event.nativeEvent.isComposing) return;
|
|
// This TV-local task keeps its keyboard loop without making the room
|
|
// modal; pointer users can still reach the surrounding room controls.
|
|
const controls = [...event.currentTarget.querySelectorAll<HTMLElement>(
|
|
'button, input, select, textarea, a[href], summary, [tabindex]',
|
|
)].filter(element => element.tabIndex >= 0 && !element.matches(":disabled") && element.getClientRects().length);
|
|
const next = event.shiftKey && event.target === controls[0] ? controls.at(-1)
|
|
: !event.shiftKey && event.target === controls.at(-1) ? controls[0] : undefined;
|
|
if (next) { event.preventDefault(); next.focus(); }
|
|
}}
|
|
>
|
|
<div className="lr-source-picker-panel">
|
|
<header className="lr-source-picker-head">
|
|
<span className="lr-source-picker-mark" aria-hidden="true">
|
|
<Glyph name="window" size={22} draw="capture-source" />
|
|
</span>
|
|
{vis ? null : (
|
|
<span className="lr-source-picker-copy">
|
|
<strong>{t("host.sourcePicker.title")}</strong>
|
|
</span>
|
|
)}
|
|
{activeTab === "camera" || nativeSources.kind !== "browser" ? <Tooltip kind="hint-refresh-sources" text={vis ? undefined : refreshLabel}
|
|
tone={refreshing ? "busy" : undefined}
|
|
motion={refreshing ? "progress" : undefined}
|
|
place="below" align="end">
|
|
{refreshButton}
|
|
</Tooltip> : null}
|
|
<Tooltip kind="hint-close" text={vis ? undefined : t("common.cancel")} place="below" align="end">
|
|
{closeButton}
|
|
</Tooltip>
|
|
</header>
|
|
|
|
<div
|
|
className="lr-toggle lr-source-picker-tabs"
|
|
style={{ "--lr-segments": tabs.length, "--lr-selected-index": tabs.indexOf(activeTab) } as CSSProperties}
|
|
role="tablist"
|
|
aria-label={t("host.sourcePicker.title")}
|
|
onKeyDown={navigateTabs}
|
|
>
|
|
{tabs.map((value) => {
|
|
const button = (
|
|
<button
|
|
type="button"
|
|
role="tab"
|
|
id={`${pickerId}-${value}`}
|
|
className={activeTab === value ? "is-selected" : undefined}
|
|
data-source-tab={value}
|
|
aria-controls={`${pickerId}-panel`}
|
|
aria-selected={activeTab === value}
|
|
aria-label={t(`host.sourcePicker.tab.${value}`)}
|
|
tabIndex={activeTab === value ? 0 : -1}
|
|
disabled={!tabAvailable(value)}
|
|
onClick={() => setTab(value)}
|
|
>
|
|
<Glyph
|
|
name={SOURCE_ICONS[value]}
|
|
size={20}
|
|
draw={`source-tab-${value}`}
|
|
/>
|
|
{vis ? null : (
|
|
<span>{t(`host.sourcePicker.tab.${value}`)}</span>
|
|
)}
|
|
</button>
|
|
);
|
|
return (
|
|
<Tooltip
|
|
key={value}
|
|
kind={`hint-capture-${value}`}
|
|
text={vis ? undefined : t(value === "browser" ? "host.sourcePicker.browserHint" : `host.sourcePicker.tab.${value}`)}
|
|
place="below"
|
|
>
|
|
{button}
|
|
</Tooltip>
|
|
);
|
|
})}
|
|
</div>
|
|
|
|
<div
|
|
className="lr-source-picker-body"
|
|
role="tabpanel"
|
|
id={`${pickerId}-panel`}
|
|
aria-labelledby={`${pickerId}-${activeTab}`}
|
|
>
|
|
{nativeTab &&
|
|
nativeSources.kind === "ready" &&
|
|
(supportsCaptureBorder || sources.length > 0) ? (
|
|
<div className="lr-source-picker-options">
|
|
{supportsCaptureBorder ? (
|
|
<div className="lr-source-picker-option">
|
|
<span aria-hidden="true"><Glyph name="window" size={19} /></span>
|
|
{vis ? null : <span>{t("host.sourcePicker.showCaptureBorder")}</span>}
|
|
<Tooltip kind={showCaptureBorder ? "hint-hide-capture-border" : "hint-show-capture-border"}
|
|
text={vis ? undefined : t("host.sourcePicker.showCaptureBorderHint")} place="below">
|
|
<button
|
|
type="button"
|
|
className="lr-switch"
|
|
role="switch"
|
|
aria-checked={showCaptureBorder}
|
|
aria-label={t("host.sourcePicker.showCaptureBorder")}
|
|
aria-description={t("host.sourcePicker.showCaptureBorderHint")}
|
|
onClick={() => setShowCaptureBorder((current) => !current)}
|
|
/>
|
|
</Tooltip>
|
|
</div>
|
|
) : null}
|
|
{sources.length > 0 ? (
|
|
<div className="lr-source-picker-option">
|
|
<span aria-hidden="true">
|
|
<Glyph name="speaker" size={19} />
|
|
</span>
|
|
{vis ? null : <span>{audioLabel}</span>}
|
|
<Tooltip
|
|
kind={!anyNativeAudio ? "no-audio" : audioLocked
|
|
? (shareAudio ? "hint-share-audio-fixed" : "hint-silent-share-fixed")
|
|
: shareAudio ? "hint-stop-audio" : "hint-share-audio"}
|
|
text={vis ? undefined : `${audioAction} · ${t("host.sourcePicker.audioHint")}`}
|
|
place="below"
|
|
>
|
|
{audioSwitch}
|
|
</Tooltip>
|
|
</div>
|
|
) : null}
|
|
{canExcludeAudio && shareAudio && anyNativeAudio ? (
|
|
<details className="lr-source-exclusion" onToggle={event => {
|
|
if (event.currentTarget.open) event.currentTarget.scrollIntoView({ block: "nearest" });
|
|
}}>
|
|
<summary aria-label={vis ? t("host.sourcePicker.excludeAudio") : undefined}>
|
|
<Glyph name="speakerOff" size={18} />
|
|
{!vis && <span>{t("host.sourcePicker.excludeAudio")}{excludeAudio ? ` · ${excludeAudio.title}` : ""}</span>}
|
|
<Glyph name="chevron" size={14} />
|
|
</summary>
|
|
<AudioExclusionSelect sources={applications} value={excludeAudio}
|
|
showLabel={false} disabled={selectionDisabled} onChange={setExcludeAudio} />
|
|
</details>
|
|
) : null}
|
|
</div>
|
|
) : null}
|
|
|
|
{activeTab === "camera" ? <CameraSources {...cameraSources} selected={initialCamera}
|
|
disabled={selectionDisabled} onSelect={id => {
|
|
cameraSources.cancel();
|
|
onCamera?.(id);
|
|
}} /> : <>
|
|
<div className="lr-source-picker-list">
|
|
{browserCapture ? (
|
|
<button
|
|
type="button"
|
|
className="lr-source-option is-browser"
|
|
aria-label={t("host.sourcePicker.browser")}
|
|
disabled={selectionDisabled || !tabAvailable(activeTab)}
|
|
onClick={onBrowser}
|
|
>
|
|
<span className="lr-source-option-icon" aria-hidden="true">
|
|
<Glyph name={SOURCE_ICONS[activeTab]} size={23} />
|
|
</span>
|
|
{vis ? (
|
|
<span className="visually-hidden">
|
|
{t(`host.sourcePicker.tab.${activeTab}`)}
|
|
</span>
|
|
) : (
|
|
<span className="lr-source-option-copy">
|
|
<strong>{t("host.sourcePicker.browser")}</strong>
|
|
<small>{t("host.sourcePicker.browserHint")}</small>
|
|
</span>
|
|
)}
|
|
</button>
|
|
) : null}
|
|
|
|
{nativeTab && !browserCapture
|
|
? sources.map((target) => (
|
|
<CaptureSourceOption
|
|
key={nativeCaptureTargetKey(target)}
|
|
target={target}
|
|
disabled={
|
|
selectionDisabled || exclusionUnavailable || (audioLocked && shareAudio && !supportsAudio(target))
|
|
}
|
|
onPreview={onPreview}
|
|
onSelect={() =>
|
|
onNative(target, shareAudio && supportsAudio(target),
|
|
supportsCaptureBorder && showCaptureBorder, target.kind === "display" ? excludeAudio : undefined)
|
|
}
|
|
/>
|
|
))
|
|
: null}
|
|
</div>
|
|
</>}
|
|
|
|
{onAppConnected && (nativeSources.kind === "browser" || nativeSources.kind === "unavailable") && (
|
|
<AppConnectionButton sourcePicker onConnected={onAppConnected} />
|
|
)}
|
|
|
|
{issueKey ? (
|
|
<Pill icon="alert" label={t(issueKey)} comic="warning" />
|
|
) : browserCapture || activeTab === "camera" ? null : sources.length === 0 ? (
|
|
<span
|
|
className="lr-source-picker-status"
|
|
role="status"
|
|
aria-label={t("host.sourcePicker.empty")}
|
|
>
|
|
<HintComic kind="hint-no-sources" size={240} />
|
|
{vis ? null : t("host.sourcePicker.empty")}
|
|
</span>
|
|
) : null}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
function CaptureSourceOption({
|
|
target,
|
|
disabled,
|
|
onPreview,
|
|
onSelect,
|
|
}: {
|
|
target: NativeCaptureTarget;
|
|
disabled: boolean;
|
|
onPreview: (
|
|
target: NativeCaptureTarget,
|
|
signal?: AbortSignal,
|
|
) => Promise<string | null>;
|
|
onSelect: () => void;
|
|
}) {
|
|
const { t } = useCopy();
|
|
const buttonRef = useRef<HTMLButtonElement | null>(null);
|
|
const previewRequestRef = useRef<AbortController | null>(null);
|
|
const [preview, setPreview] = useState<string | null>(null);
|
|
const requestPreview = useCallback(() => {
|
|
if (target.kind === "picker" || previewRequestRef.current) return;
|
|
const request = new AbortController();
|
|
previewRequestRef.current = request;
|
|
void onPreview(target, request.signal).then((value) => {
|
|
if (!request.signal.aborted && value) setPreview(value);
|
|
});
|
|
}, [onPreview, target]);
|
|
|
|
useEffect(
|
|
() => () => {
|
|
previewRequestRef.current?.abort();
|
|
previewRequestRef.current = null;
|
|
},
|
|
[],
|
|
);
|
|
|
|
useEffect(() => {
|
|
const button = buttonRef.current;
|
|
if (!button || typeof IntersectionObserver === "undefined") return;
|
|
const observer = new IntersectionObserver((entries) => {
|
|
if (entries.some((entry) => entry.isIntersecting)) {
|
|
requestPreview();
|
|
observer.disconnect();
|
|
}
|
|
});
|
|
observer.observe(button);
|
|
return () => observer.disconnect();
|
|
}, [requestPreview]);
|
|
|
|
const title =
|
|
target.kind === "picker" ? t("host.sourcePicker.system") : target.title;
|
|
const action =
|
|
target.kind === "picker"
|
|
? t("host.sourcePicker.systemAction")
|
|
: t(
|
|
target.kind === "display"
|
|
? "host.sourcePicker.display"
|
|
: "host.sourcePicker.window",
|
|
{ title },
|
|
);
|
|
|
|
return <CaptureSourceCard title={title} action={action}
|
|
icon={target.kind === "picker" ? "share" : target.kind}
|
|
hint={target.kind === "picker" ? "hint-source-picker" : target.kind === "display" ? "hint-capture-display" : "hint-capture-window"}
|
|
preview={preview} nativeKey={nativeCaptureTargetKey(target)} buttonRef={buttonRef}
|
|
disabled={disabled} onPreview={requestPreview} onSelect={onSelect} />;
|
|
}
|