fix(player): treat runtime timeline as cross-origin ready (#1690)

This commit is contained in:
Miguel Ángel
2026-06-24 00:39:53 -04:00
committed by GitHub
parent 546b2d770b
commit ea23e6309f
5 changed files with 89 additions and 0 deletions
@@ -12,6 +12,7 @@ const makeCallbacks = (): MessageHandlerCallbacks => ({
updateControlsPlaying: vi.fn(),
dispatchEvent: vi.fn(),
onRuntimeReady: vi.fn(),
onRuntimeTimelineReady: vi.fn(),
seek: vi.fn(),
play: vi.fn(),
getLoop: vi.fn(() => false),
@@ -101,3 +102,29 @@ describe("handleRuntimeMessage media autoplay fallback", () => {
expect(callbacks.sendControl).not.toHaveBeenCalled();
});
});
describe("handleRuntimeMessage timeline ready", () => {
const timelineEvent = (durationInFrames: unknown, source: object): MessageEvent =>
({
source,
data: { source: "hf-preview", type: "timeline", durationInFrames, scenes: [] },
}) as unknown as MessageEvent;
it("reports a finite positive timeline duration in seconds", () => {
const frameWindow = {} as Window;
const callbacks = makeCallbacks();
handleRuntimeMessage(timelineEvent(120, frameWindow), frameWindow, callbacks);
expect(callbacks.onRuntimeTimelineReady).toHaveBeenCalledWith(4);
});
it("does not report invalid timeline durations as ready", () => {
const frameWindow = {} as Window;
const callbacks = makeCallbacks();
handleRuntimeMessage(timelineEvent(Infinity, frameWindow), frameWindow, callbacks);
expect(callbacks.onRuntimeTimelineReady).not.toHaveBeenCalled();
});
});