fix(player): version runtime protocol

This commit is contained in:
James
2026-07-13 13:28:11 -04:00
parent 95fa14b2c2
commit dcefdd98ca
32 changed files with 683 additions and 78 deletions
+43 -2
View File
@@ -19,6 +19,7 @@ function createMockDeps() {
onSetRootDuration: vi.fn(),
onEnablePickMode: vi.fn(),
onDisablePickMode: vi.fn(),
getCanonicalFps: vi.fn(() => 30),
};
}
@@ -54,7 +55,22 @@ describe("installRuntimeControlBridge", () => {
const deps = createMockDeps();
const handler = installRuntimeControlBridge(deps);
handler(makeControlMessage("seek", { frame: 150, seekMode: "drag" }));
expect(deps.onSeek).toHaveBeenCalledWith(150, "drag");
expect(deps.onSeek).toHaveBeenCalledWith(5, "drag");
});
it("prefers canonical seconds in protocol v1 seek messages", () => {
const deps = createMockDeps();
const handler = installRuntimeControlBridge(deps);
handler(
makeControlMessage("seek", {
protocolVersion: 1,
capabilities: ["seconds-time", "rational-fps", "seek-keep-playing"],
fps: { numerator: 60, denominator: 1 },
timeSeconds: 2.5,
frame: 999,
}),
);
expect(deps.onSeek).toHaveBeenCalledWith(2.5, "commit");
});
it("seek defaults frame to 0 and seekMode to commit", () => {
@@ -245,7 +261,32 @@ describe("installRuntimeControlBridge", () => {
const postSpy = vi.spyOn(window.parent, "postMessage");
const deps = createMockDeps();
installRuntimeControlBridge(deps);
expect(postSpy).toHaveBeenCalledWith({ source: "hf-preview", type: "ready" }, "*");
expect(postSpy).toHaveBeenCalledWith(
expect.objectContaining({
source: "hf-preview",
type: "ready",
protocolVersion: 1,
fps: { numerator: 30, denominator: 1 },
}),
"*",
);
postSpy.mockRestore();
});
it("rejects an unknown protocol major with a diagnostic", () => {
const postSpy = vi.spyOn(window.parent, "postMessage");
const deps = createMockDeps();
const handler = installRuntimeControlBridge(deps);
handler(makeControlMessage("play", { protocolVersion: 2 }));
expect(deps.onPlay).not.toHaveBeenCalled();
expect(postSpy).toHaveBeenCalledWith(
expect.objectContaining({
type: "diagnostic",
code: "runtime.protocol.unsupported_protocol_version",
}),
"*",
);
postSpy.mockRestore();
});
});