fix(playback): read output failure from the actual video sink
PageSuppliedMedia wraps an HTMLVideoMedia player, so a source-level optional failure flag missed its underlying output. Query the shared playback-output owner with the actual video element and remove the extra media-adapter field. The wrapper regression fails on the previous candidate and passes with this change. The production 320-pixel preview exposes device recovery and preserves the chosen output; 100 focused tests and the full TypeScript check pass.
This commit is contained in:
1 parent
6f98d93c36
commit
df2acc0893
5 files changed
+70
-10
No files matched your search
@@ -110,7 +110,7 @@ export function ChannelWatchVideo({ player, owned, paused, label, presentation,
|
||||
track.channels ? t("watch.forward.channels", { count: track.channels }) : undefined].filter(Boolean).join(" · ") }));
|
||||
const localSeek = player.blockedReason === "local-seek";
|
||||
const resumeLabel = localSeek ? "watch.resync" : "watch.resume";
|
||||
const outputFailed = useSyncExternalStore(playbackOutput.subscribe, () => Boolean(player.media.outputFailed), () => false);
|
||||
const outputFailed = useSyncExternalStore(playbackOutput.subscribe, () => playbackOutput.failedFor(player.video), () => false);
|
||||
const waiting = player.waitingForPicture && !player.error && !player.blocked;
|
||||
const ownerPaused = player.video?.paused ?? mediaState?.paused ?? paused;
|
||||
const audioAvailable = player.media.audioAvailable?.() !== false;
|
||||
|
||||
@@ -30,7 +30,6 @@ export type WatchPresentation = { kind: "video"; element: HTMLVideoElement }
|
||||
export interface WatchMedia {
|
||||
readonly page?: AppPagePort | null;
|
||||
readonly retainedByteSource?: WatchByteSource;
|
||||
readonly outputFailed?: boolean;
|
||||
audioAvailable?(): boolean | undefined;
|
||||
readonly presentation?: WatchPresentation;
|
||||
readonly seekTolerance?: number;
|
||||
@@ -94,7 +93,6 @@ export class HTMLVideoMedia implements WatchMedia {
|
||||
readonly video = document.createElement("video");
|
||||
private pendingOutputPlay?: object;
|
||||
private readonly detachOutput = playbackOutput.attach(this.video);
|
||||
get outputFailed() { return this.detachOutput.getFailed(); }
|
||||
readonly presentation = { kind: "video" as const, element: this.video };
|
||||
private lifetime = new AbortController();
|
||||
private setup: Promise<void>;
|
||||
|
||||
@@ -10,6 +10,9 @@ let pending = Promise.resolve();
|
||||
export const playbackOutput = {
|
||||
get selected() { return selected; },
|
||||
get failed() { return changeFailed || failedTargets.size > 0; },
|
||||
failedFor(target: HTMLMediaElement | AudioContext | null | undefined) {
|
||||
return !!target && failedTargets.has(target as Sink);
|
||||
},
|
||||
subscribe(listener: () => void) {
|
||||
events.addEventListener("change", listener);
|
||||
return () => events.removeEventListener("change", listener);
|
||||
@@ -25,7 +28,7 @@ export const playbackOutput = {
|
||||
const wasFailed = failedTargets.has(sink);
|
||||
applied();
|
||||
if (wasFailed) events.dispatchEvent(new Event("change"));
|
||||
}, { ready, getWaiting: () => waiting, getFailed: () => failedTargets.has(sink) });
|
||||
}, { ready, getWaiting: () => waiting });
|
||||
if (!waiting) resolve();
|
||||
if (!sink.setSinkId) return detach;
|
||||
targets.set(sink, applied);
|
||||
|
||||
@@ -43,22 +43,24 @@ it("keeps healthy outputs on the chosen device when a retiring output rejects la
|
||||
|
||||
it.each(["reselect", "close"])("clears one failed initial output on %s while keeping healthy outputs ready", async action => {
|
||||
await playbackOutput.choose("headphones");
|
||||
const refused = playbackOutput.attach({ setSinkId: async (id: string) => {
|
||||
const refusedElement = { setSinkId: async (id: string) => {
|
||||
if (id === "headphones") throw Error("unavailable");
|
||||
} } as unknown as HTMLMediaElement);
|
||||
const healthy = playbackOutput.attach({ setSinkId: async () => {} } as unknown as HTMLMediaElement);
|
||||
} } as unknown as HTMLMediaElement;
|
||||
const healthyElement = { setSinkId: async () => {} } as unknown as HTMLMediaElement;
|
||||
const refused = playbackOutput.attach(refusedElement);
|
||||
const healthy = playbackOutput.attach(healthyElement);
|
||||
try {
|
||||
await healthy.ready;
|
||||
expect(refused.getWaiting()).toBe(true);
|
||||
expect(playbackOutput.failed).toBe(true);
|
||||
expect(refused.getFailed()).toBe(true);
|
||||
expect(playbackOutput.failedFor(refusedElement)).toBe(true);
|
||||
expect(healthy.getWaiting()).toBe(false);
|
||||
expect(healthy.getFailed()).toBe(false);
|
||||
expect(playbackOutput.failedFor(healthyElement)).toBe(false);
|
||||
if (action === "reselect") await playbackOutput.choose("alternate");
|
||||
else refused();
|
||||
await refused.ready;
|
||||
expect(refused.getWaiting()).toBe(false);
|
||||
expect(refused.getFailed()).toBe(false);
|
||||
expect(playbackOutput.failedFor(refusedElement)).toBe(false);
|
||||
expect(healthy.getWaiting()).toBe(false);
|
||||
expect(playbackOutput.selected).toBe(action === "reselect" ? "alternate" : "headphones");
|
||||
expect(playbackOutput.failed).toBe(false);
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
import { createElement } from "react";
|
||||
import { renderToStaticMarkup } from "react-dom/server";
|
||||
import { expect, it, vi } from "vitest";
|
||||
import { AppPage } from "../src/client/channel/app-link";
|
||||
import { ChannelWatchVideo } from "../src/client/channel/components/ChannelMedia";
|
||||
import { HTMLVideoMedia } from "../src/client/channel/watch-media";
|
||||
import { PageSuppliedMedia } from "../src/client/channel/watch-page-media";
|
||||
import { WatchPlayer } from "../src/client/channel/watch-playback";
|
||||
import { playbackOutput } from "../src/client/media/playback-output";
|
||||
import { setCopy, t } from "../src/client/ui/copy";
|
||||
|
||||
// Read the output store's client snapshot with the static renderer.
|
||||
vi.mock("react", async importOriginal => {
|
||||
const react = await importOriginal<typeof import("react")>();
|
||||
const { playbackOutput } = await import("../src/client/media/playback-output");
|
||||
return {
|
||||
...react,
|
||||
useSyncExternalStore: ((subscribe, getSnapshot, getServerSnapshot) =>
|
||||
react.useSyncExternalStore(subscribe, getSnapshot, subscribe === playbackOutput.subscribe ? getSnapshot : getServerSnapshot)
|
||||
) as typeof react.useSyncExternalStore,
|
||||
};
|
||||
});
|
||||
|
||||
it("offers output recovery for the actual video of a page-supplied player", async () => {
|
||||
setCopy({ lang: "en" });
|
||||
const video = Object.assign(new EventTarget(), {
|
||||
readyState: 0, paused: true, ended: false, duration: 0, currentTime: 0,
|
||||
pause: vi.fn(), removeAttribute: vi.fn(), load: vi.fn(), remove: vi.fn(),
|
||||
setSinkId: vi.fn(async (id: string) => {
|
||||
if (id === "missing") throw new DOMException("Device went away", "NotFoundError");
|
||||
}),
|
||||
});
|
||||
vi.stubGlobal("document", { createElement: () => video });
|
||||
Object.assign(video, { ownerDocument: document });
|
||||
vi.stubGlobal("HTMLMediaElement", class { setSinkId = video.setSinkId; });
|
||||
await playbackOutput.choose("missing");
|
||||
const page = new AppPage(crypto.randomUUID(), "https://source.test/player", vi.fn(), vi.fn(), vi.fn());
|
||||
const media = new PageSuppliedMedia(page, new HTMLVideoMedia(() => new Promise(() => {})),
|
||||
{ sessionId: crypto.randomUUID(), resourceId: crypto.randomUUID(), format: "file" });
|
||||
const player = new WatchPlayer("fixture", false, media, vi.fn());
|
||||
const render = () => renderToStaticMarkup(createElement(ChannelWatchVideo, {
|
||||
player, owned: false, paused: true, label: "Page", presentation: "full", disabled: false,
|
||||
website: true, originalPageAvailable: true, theaterMode: false, onToggleTheater: vi.fn(),
|
||||
onPlayback: vi.fn(), onResume: vi.fn(), onFocusWindow: vi.fn(),
|
||||
}));
|
||||
try {
|
||||
await vi.waitFor(() => expect(playbackOutput.failed).toBe(true));
|
||||
expect(render()).toContain("c3-watch-output");
|
||||
await playbackOutput.choose("alternate");
|
||||
expect(render()).not.toContain("c3-watch-output");
|
||||
expect(render()).toContain(t("en", "watch.waiting"));
|
||||
} finally {
|
||||
player.close();
|
||||
await playbackOutput.choose("");
|
||||
vi.unstubAllGlobals();
|
||||
}
|
||||
});
|
||||
Reference in new issue
Block a user