## Problem and outcome / 问题与结果 Compatible Native receiver renegotiation rebuilt the encoded source and its playback/relay consumers. Replacement backends could also lose committed-route recovery ownership, while queued events and unfinished SFU cleanup could reach a replacement with the same logical identity. Retain compatible receivers, keep recovery on the committed route, and validate physical ownership through final control delivery. SFU activation waits for the existing retirement barrier. This phase also consumes renewed same-page invitations through the existing grant owner and avoids closing uninitialized Windows capture objects after preview failure. Camera, microphone, interaction and control redesign remain outside this patch. ## Release notes ### 中文 这是一次以连接稳定性为重点的小修复更新。 - 修复 App 接收端重新协商时不必要地中断播放和中继的问题,并保留正确的连接恢复行为。 - 修复旧连接的迟到事件及关闭时序干扰替代连接的问题。 - 修复重新打开同页邀请链接后仍沿用旧邀请的问题。 - 修复 Windows 选源预览失败时的一处异常退出。 更新 App 并刷新网页即可使用这些修复,无需修改配置。 ### English This maintenance update focuses on connection stability. - Preserve App playback, relay connections and recovery behavior during compatible renegotiation. - Prevent delayed events and cleanup from retired connections from disrupting their replacements. - Use the new invitation when another invite link opens in the same page. - Fix a Windows crash during failed source-preview cleanup. Update Piik App and refresh the page to use these fixes. No configuration changes are required. ## Verification / 验证 - TypeScript type checking, 71 Vitest files / 1,015 tests and Web production build. - Go core tests, vet and supported cross-target builds; receiver tests exercise H.264/VP8/Opus, ICE restart, fresh gathering and retained downstream media. - Windows native compile/probe and deterministic capture checks, including failed-preview cleanup. - Documentation and repository hygiene checks; independent review of the extracted patch and old/new Web/App capability negotiation. - Local full-suite runs reached the unchanged Git fixture's 5-second timeout; that suite passed alone. The complete suite was rerun with two workers and a 15-second test deadline. ## Impact / 影响 Planned version: v1.5.6. Existing public wire versions and configuration are retained. Receiver reuse is capability-negotiated: old Apps receive no new request field, and old pages receive no new answer field. Room authority, routing policy and retry budgets are unchanged. The established-viewing interruption report still lacks paired diagnostics; these reproduced defects do not establish that reporter's exact cause. Physical device/network endurance remains outside local deterministic acceptance. Git/PRs retain this repair history; the TODO ledger retains outstanding reports and separate feature candidates.
454 lines
14 KiB
TypeScript
454 lines
14 KiB
TypeScript
import {
|
|
Component,
|
|
Suspense,
|
|
lazy,
|
|
useEffect,
|
|
useState,
|
|
type FormEvent,
|
|
type ReactNode,
|
|
} from "react";
|
|
import {
|
|
ApiError,
|
|
authenticateSiteAccess,
|
|
getRuntimeCapabilities,
|
|
getSiteAccess,
|
|
type SiteAccessStatus,
|
|
} from "./lib/api";
|
|
import type { RuntimeCapabilities } from "../shared/protocol";
|
|
import {
|
|
parseAppRoute,
|
|
readViewerRoute,
|
|
watchViewerInvites,
|
|
takeClientLaunchBootstrap,
|
|
type ViewerRoute,
|
|
} from "./lib/session";
|
|
import { AppHeader } from "./components/living/Header";
|
|
import { Btn, Pill } from "./components/living/primitives";
|
|
import { Comic, type ComicKind } from "./components/living/Comic";
|
|
import { LoadingStatus } from "./components/living/WaitingStatus";
|
|
import { Glyph } from "./ui/icons";
|
|
import { applyLaunchCopy, useCopy } from "./ui/copy";
|
|
import { consoleLanguage } from "./locales";
|
|
import { initTheme } from "./ui/theme";
|
|
import { installBrowserDebug, withBrowserDebug } from "./lib/debug";
|
|
|
|
const TooltipPreviewPage = import.meta.env.DEV
|
|
? lazy(() => import("./pages/TooltipPreviewPage").then((module) => ({ default: module.TooltipPreviewPage })))
|
|
: null;
|
|
|
|
const StatusPreviewPage = import.meta.env.DEV
|
|
? lazy(() => import("./pages/StatusPreviewPage").then((module) => ({ default: module.StatusPreviewPage })))
|
|
: null;
|
|
const PlaybackPreviewPage = import.meta.env.DEV
|
|
? lazy(() => import("./pages/PlaybackPreviewPage").then((module) => ({ default: module.PlaybackPreviewPage })))
|
|
: null;
|
|
|
|
const appRoute = parseAppRoute(window.location.pathname);
|
|
const clientLaunchBootstrap =
|
|
appRoute.kind === "host" || appRoute.kind === "viewer"
|
|
? takeClientLaunchBootstrap()
|
|
: null;
|
|
initTheme(clientLaunchBootstrap?.presentation?.theme,
|
|
clientLaunchBootstrap?.presentation?.explicit?.includes("theme") ?? false);
|
|
if (clientLaunchBootstrap?.presentation) {
|
|
applyLaunchCopy(clientLaunchBootstrap.presentation,
|
|
clientLaunchBootstrap.presentation.explicit?.includes("copy") ?? false);
|
|
}
|
|
const clientAccessBootstrap = clientLaunchBootstrap?.accessToken ?? null;
|
|
const initialViewerRoute = appRoute.kind === "viewer" ? readViewerRoute() : null;
|
|
const hostPageModule =
|
|
appRoute.kind === "host" ? import("./pages/HostPage") : null;
|
|
const joinPageModule =
|
|
appRoute.kind === "join" ? import("./pages/JoinPage") : null;
|
|
const viewerPageModule =
|
|
appRoute.kind === "viewer" ? import("./pages/ViewerPage") : null;
|
|
const appLauncherPageModule =
|
|
appRoute.kind === "client" ? import("./pages/AppLauncherPage") : null;
|
|
const HostPage = lazy(async () => ({
|
|
default: (await (hostPageModule ?? import("./pages/HostPage"))).HostPage,
|
|
}));
|
|
const JoinPage = lazy(async () => ({
|
|
default: (await (joinPageModule ?? import("./pages/JoinPage"))).JoinPage,
|
|
}));
|
|
const ViewerPage = lazy(async () => ({
|
|
default: (await (viewerPageModule ?? import("./pages/ViewerPage")))
|
|
.ViewerPage,
|
|
}));
|
|
const AppLauncherPage = lazy(async () => ({
|
|
default: (await (
|
|
appLauncherPageModule ?? import("./pages/AppLauncherPage")
|
|
)).AppLauncherPage,
|
|
}));
|
|
const SITE_ACCESS_RENEWAL_INTERVAL_MS = 60 * 60 * 1_000;
|
|
|
|
type AccessState =
|
|
| { kind: "checking" }
|
|
| { kind: "ready"; renewalRequired: boolean }
|
|
| { kind: "required"; error: string | null }
|
|
| { kind: "unavailable"; message: string };
|
|
|
|
function stateFromStatus(status: SiteAccessStatus): AccessState {
|
|
return !status.required || status.authenticated
|
|
? { kind: "ready", renewalRequired: status.required }
|
|
: { kind: "required", error: null };
|
|
}
|
|
|
|
function readableError(error: unknown, t: (key: "gate.connectFailed") => string): string {
|
|
return error instanceof ApiError ? error.message : t("gate.connectFailed");
|
|
}
|
|
|
|
export function App() {
|
|
const { lang, vis } = useCopy();
|
|
useEffect(installBrowserDebug, []);
|
|
useEffect(() => {
|
|
if (appRoute.kind !== "client" && !clientLaunchBootstrap?.launchedByClient) return;
|
|
const controller = new AbortController();
|
|
void import("./native/client")
|
|
.then(({ notifyNativePresentation }) =>
|
|
notifyNativePresentation(consoleLanguage(lang, vis), controller.signal))
|
|
.catch(() => undefined);
|
|
return () => controller.abort();
|
|
}, [lang, vis]);
|
|
|
|
return (
|
|
<RouteBoundary>
|
|
<Suspense fallback={<RouteLoader />}>
|
|
<AppRoute />
|
|
</Suspense>
|
|
</RouteBoundary>
|
|
);
|
|
}
|
|
|
|
// A page chunk that fails to load (offline, stale deploy) throws during render;
|
|
// without this the root unmounts to a blank page with no way back.
|
|
class RouteBoundary extends Component<
|
|
{ children: ReactNode },
|
|
{ failed: boolean }
|
|
> {
|
|
state = { failed: false };
|
|
|
|
static getDerivedStateFromError(): { failed: boolean } {
|
|
return { failed: true };
|
|
}
|
|
|
|
render(): ReactNode {
|
|
return this.state.failed ? (
|
|
<StaticRoute
|
|
comic="warning"
|
|
titleKey="gate.unavailableRoute"
|
|
action="reload"
|
|
/>
|
|
) : (
|
|
this.props.children
|
|
);
|
|
}
|
|
}
|
|
|
|
function AppRoute() {
|
|
const [viewerRoute, setViewerRoute] = useState(initialViewerRoute);
|
|
useEffect(() => {
|
|
if (appRoute.kind === "viewer") return watchViewerInvites(setViewerRoute);
|
|
}, []);
|
|
if (PlaybackPreviewPage && window.location.pathname === "/__playback-preview") {
|
|
return <PlaybackPreviewPage />;
|
|
}
|
|
if (StatusPreviewPage && window.location.pathname === "/__status-preview") {
|
|
return <StatusPreviewPage />;
|
|
}
|
|
if (TooltipPreviewPage && window.location.pathname === "/__tooltip-preview") {
|
|
return <TooltipPreviewPage />;
|
|
}
|
|
if (appRoute.kind === "client") {
|
|
return <AppLauncherPage />;
|
|
}
|
|
if (appRoute.kind === "viewer" && viewerRoute) {
|
|
return viewerRoute.viewerGrant ? (
|
|
<ViewerPage
|
|
key={viewerRoute.viewerGrant}
|
|
{...viewerRoute}
|
|
launchedByClient={clientLaunchBootstrap?.launchedByClient}
|
|
/>
|
|
) : (
|
|
<SiteAccessGate key={viewerRoute.invalidGrant ? "invalid" : "code"}
|
|
surface="viewer" viewerRoute={viewerRoute} />
|
|
);
|
|
}
|
|
if (appRoute.kind === "host") {
|
|
return <SiteAccessGate surface="host" />;
|
|
}
|
|
if (appRoute.kind === "join") {
|
|
return <SiteAccessGate surface="join" />;
|
|
}
|
|
return appRoute.kind === "malformed-room" ? (
|
|
<StaticRoute
|
|
comic="room-code-invalid"
|
|
titleKey="gate.malformed"
|
|
hintKey="gate.malformedHint"
|
|
action="join"
|
|
/>
|
|
) : (
|
|
<StaticRoute comic="warning" titleKey="gate.unavailableRoute" />
|
|
);
|
|
}
|
|
|
|
function RouteLoader() {
|
|
return (
|
|
<div className="lr-app">
|
|
<AppHeader />
|
|
<main className="lr-join">
|
|
<LoadingStatus label="common.loading" />
|
|
</main>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
function StaticRoute({
|
|
comic,
|
|
titleKey,
|
|
hintKey,
|
|
action,
|
|
}: {
|
|
comic: ComicKind;
|
|
titleKey: "gate.malformed" | "gate.unavailableRoute";
|
|
hintKey?: "gate.malformedHint";
|
|
action?: "join" | "reload";
|
|
}) {
|
|
const { t, vis } = useCopy();
|
|
return (
|
|
<div className="lr-app">
|
|
<AppHeader />
|
|
<main className="lr-join">
|
|
<div className="lr-join-panel">
|
|
<Comic kind={comic} theme="paper" tone="bad" />
|
|
{vis ? null : (
|
|
<div className="lr-access-text">
|
|
<h1>{t(titleKey)}</h1>
|
|
{hintKey ? <p>{t(hintKey)}</p> : null}
|
|
</div>
|
|
)}
|
|
<span className="visually-hidden" role="alert">
|
|
{hintKey ? [t(titleKey), t(hintKey)].join(" · ") : t(titleKey)}
|
|
</span>
|
|
{action === "join" ? (
|
|
<Btn
|
|
icon="door"
|
|
title="join.title"
|
|
cap="join.title"
|
|
hint="hint-join-go"
|
|
onClick={() => window.location.assign(withBrowserDebug("/join"))}
|
|
/>
|
|
) : action === "reload" ? (
|
|
<Btn
|
|
icon="refresh"
|
|
title="common.refresh"
|
|
cap="common.refresh"
|
|
hint="page-refresh"
|
|
onClick={() => window.location.reload()}
|
|
/>
|
|
) : null}
|
|
</div>
|
|
</main>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
function SiteAccessGate({
|
|
surface,
|
|
viewerRoute,
|
|
}: {
|
|
surface: "host" | "join" | "viewer";
|
|
viewerRoute?: ViewerRoute;
|
|
}) {
|
|
const { t, vis } = useCopy();
|
|
const [access, setAccess] = useState<AccessState>({ kind: "checking" });
|
|
const [capabilities, setCapabilities] =
|
|
useState<RuntimeCapabilities | null>(null);
|
|
const [password, setPassword] = useState("");
|
|
const [submitting, setSubmitting] = useState(false);
|
|
|
|
function loadAccess(password?: string) {
|
|
return Promise.all([
|
|
password ? authenticateSiteAccess(password) : getSiteAccess(),
|
|
surface === "host" ? getRuntimeCapabilities() : Promise.resolve(null),
|
|
]);
|
|
}
|
|
|
|
useEffect(() => {
|
|
let active = true;
|
|
void loadAccess(clientAccessBootstrap ?? undefined).then(
|
|
([status, nextCapabilities]) => {
|
|
if (!active) return;
|
|
setCapabilities(nextCapabilities);
|
|
const next = stateFromStatus(status);
|
|
setAccess(
|
|
next.kind === "required" && viewerRoute?.invalidGrant
|
|
? { kind: "required", error: t("viewer.msg.invalidInvite") }
|
|
: next,
|
|
);
|
|
},
|
|
(error: unknown) => {
|
|
if (!active) return;
|
|
// A rejected bootstrap credential is an access problem, not an outage:
|
|
// the passphrase form is the recovery, not a retry of the same token.
|
|
setAccess(
|
|
error instanceof ApiError && error.status === 401
|
|
? { kind: "required", error: t("gate.expired") }
|
|
: { kind: "unavailable", message: readableError(error, t) },
|
|
);
|
|
},
|
|
);
|
|
return () => {
|
|
active = false;
|
|
};
|
|
}, []);
|
|
|
|
useEffect(() => {
|
|
if (access.kind !== "ready" || !access.renewalRequired) {
|
|
return;
|
|
}
|
|
let active = true;
|
|
let checking = false;
|
|
const timer = window.setInterval(() => {
|
|
if (checking) {
|
|
return;
|
|
}
|
|
checking = true;
|
|
void getSiteAccess()
|
|
.then((status) => {
|
|
if (active && (!status.required || !status.authenticated)) {
|
|
setAccess(stateFromStatus(status));
|
|
}
|
|
})
|
|
.catch(() => undefined)
|
|
.finally(() => {
|
|
if (active) {
|
|
checking = false;
|
|
}
|
|
});
|
|
}, SITE_ACCESS_RENEWAL_INTERVAL_MS);
|
|
return () => {
|
|
active = false;
|
|
window.clearInterval(timer);
|
|
};
|
|
}, [access]);
|
|
|
|
async function retry(): Promise<void> {
|
|
setAccess({ kind: "checking" });
|
|
try {
|
|
const [status, nextCapabilities] = await loadAccess();
|
|
setCapabilities(nextCapabilities);
|
|
setAccess(stateFromStatus(status));
|
|
} catch (error) {
|
|
setAccess({ kind: "unavailable", message: readableError(error, t) });
|
|
}
|
|
}
|
|
|
|
async function submit(event: FormEvent<HTMLFormElement>): Promise<void> {
|
|
event.preventDefault();
|
|
const submittedPassword = password;
|
|
setPassword("");
|
|
if (!submittedPassword) {
|
|
setAccess({ kind: "required", error: t("gate.hint") });
|
|
return;
|
|
}
|
|
|
|
setSubmitting(true);
|
|
try {
|
|
const [status, nextCapabilities] = await loadAccess(submittedPassword);
|
|
setCapabilities(nextCapabilities);
|
|
setAccess(stateFromStatus(status));
|
|
} catch (error) {
|
|
setAccess(
|
|
error instanceof ApiError && error.status === 401
|
|
? { kind: "required", error: t("gate.wrong") }
|
|
: { kind: "unavailable", message: readableError(error, t) },
|
|
);
|
|
} finally {
|
|
setSubmitting(false);
|
|
}
|
|
}
|
|
|
|
if (access.kind === "ready") {
|
|
if (surface === "viewer" && viewerRoute) {
|
|
return (
|
|
<ViewerPage
|
|
{...viewerRoute}
|
|
launchedByClient={clientLaunchBootstrap?.launchedByClient}
|
|
/>
|
|
);
|
|
}
|
|
if (surface === "join") {
|
|
return <JoinPage />;
|
|
}
|
|
return (
|
|
<HostPage
|
|
launchedByClient={clientLaunchBootstrap?.launchedByClient}
|
|
sfuAvailable={capabilities?.sfu === true}
|
|
natPredictionAvailable={capabilities?.natPrediction === true}
|
|
onAuthorizationRequired={() =>
|
|
setAccess({ kind: "required", error: t("gate.expired") })
|
|
}
|
|
/>
|
|
);
|
|
}
|
|
|
|
return (
|
|
<div className="lr-app">
|
|
<AppHeader />
|
|
<main className="lr-join">
|
|
{access.kind === "checking" ? (
|
|
<LoadingStatus label="gate.checking" />
|
|
) : access.kind === "unavailable" ? (
|
|
<div className="lr-join-panel">
|
|
<Comic kind="signal-failed" theme="paper" />
|
|
{vis ? (
|
|
<span className="visually-hidden" role="alert">{access.message}</span>
|
|
) : (
|
|
<div className="lr-access-text">
|
|
<h1>{t("gate.unavailable")}</h1>
|
|
<p role="alert">{access.message}</p>
|
|
</div>
|
|
)}
|
|
<Btn icon="refresh" title="common.retry" cap="common.retry" hint="signal-connecting" hintTone="off" hintMotion="demo" onClick={() => void retry()} />
|
|
</div>
|
|
) : (
|
|
<form className="lr-join-panel" onSubmit={(event) => void submit(event)}>
|
|
<Comic kind="site-access" theme="paper" />
|
|
{vis ? null : (
|
|
<div className="lr-access-text">
|
|
<h1>{t("gate.title")}</h1>
|
|
<p>{t("gate.hint")}</p>
|
|
</div>
|
|
)}
|
|
<span className="lr-input" style={{ minWidth: 240 }}>
|
|
<Glyph name="key" size={17} />
|
|
<input
|
|
type="password"
|
|
value={password}
|
|
disabled={submitting}
|
|
autoComplete="current-password"
|
|
autoFocus
|
|
aria-label={t("gate.password")}
|
|
placeholder={vis ? "····" : t("gate.password")}
|
|
onChange={(event) => setPassword(event.target.value)}
|
|
/>
|
|
</span>
|
|
{access.error ? (
|
|
<Pill icon="alert" tone="bad" label={access.error} alert comic="access-denied" />
|
|
) : null}
|
|
<Btn
|
|
icon="arrowRight"
|
|
title="gate.submit"
|
|
cap="gate.submit"
|
|
tone="primary"
|
|
type="submit"
|
|
hint="hint-password"
|
|
disabled={submitting}
|
|
/>
|
|
</form>
|
|
)}
|
|
</main>
|
|
</div>
|
|
);
|
|
}
|