mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-09-03 04:38:33 +00:00
feat(slideshow): per-slide autoplay (manual-advance, opt-in) (#1708)
* feat(slideshow): per-slide autoplay (manual-advance, opt-in) Adds an opt-in `autoplay` flag to slideshow slides: when the presenter lands on a video slide, its `<video>` plays from the start. The slideshow still holds and never auto-advances — the presenter clicks Next when ready. This covers compositions whose own controls can't be clicked (the player renders the composition pointer-events:none). Plumbing (done, tested): - core: `SlideRef.autoplay?: boolean`, parsed + validated in parseSlideshow (a non-boolean autoplay rejects the manifest); carried through resolve. - controller: optional `PlayerPort.playSceneMedia(sceneId)`, fired only on forward `enterSlide` for autoplay slides (not resume/back/sync, so the audience — which mirrors the presenter's media events — isn't double-driven). - component: `playSceneDocumentMedia` reaches the same-origin composition iframe, finds the scene's `<video>`, and asserts playback; `stopMedia` (already wired on slide change) resets it. An autoplay token cancels a pending start when the slide changes. - tests: controller autoplay behavior + parser flag round-trip/validation (131 player + 22 core slideshow tests pass). KNOWN LIMITATION — runtime media-start needs the player media model (@vance): On current main the clip<->timeline binding from #1601 keeps every clip synced and *paused* to the held timeline frame, which wins against playSceneMedia's play() — so the clip does not actually start on main yet (it does on the pre-#1601 player). The correct fix is a sanctioned "let this clip free-run while the timeline holds" path in the player/runtime media controller. Flagging for Vance to wire the start into the #1601 media model (or rebase onto it) when back. The plumbing above is the stable surface that hook plugs into. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * refactor(slideshow): address code-review on per-slide autoplay - guard playSceneDocumentMedia behind resolveMode() !== "audience": the audience mirrors the presenter's media events, so it must not independently drive its own copy of the clip. - drop the per-enter window pointerdown/keydown "gesture retry" listeners, which leaked when muted autoplay succeeded without a gesture. The poll already re-asserts play(), so a gesture within the window is picked up next tick. - stop polling once the clip is advancing across two ticks (was re-asserting play() for the full window even after playback was confirmed). - cancel any in-flight autoplay loop on disconnectedCallback (bump the token). - split the poll into findSceneVideo + stepAutoplay helpers (keeps each small). - fix the enterSlide comment: autoplay fires from enterSlide (next/prev/ goToSlide), not resumeSlide (back/backToMain/syncTo). - parser: isOptionalBoolean type guard instead of a one-off helper; drop `as` assertions in the new controller test. 131 player + 22 core slideshow tests pass; lint/format/typecheck/fallow clean. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * docs(slideshow): autoplay skill guidance + address review nits Addresses review feedback on #1708: - skill: document per-slide `autoplay` in the slideshow standalone-harness reference — when to use it (video is the slide's primary content, its end is the advance cue) vs not (background/ambient loops, footage talked over), per Vance's guidance, before merge. - play() rejection is no longer blanket-swallowed: AbortError (timeline-sync seek interrupt) and NotAllowedError (gesture-gated autoplay) are expected and ignored; any other rejection is surfaced once via console.warn (Via nit 1). - clarify in the SlideRef.autoplay doc that it plays the scene's FIRST <video> (Via nit 2). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.8
parent
041f2fa196
commit
7517f6ac86
@@ -196,4 +196,23 @@ describe("resolveSlideshow", () => {
|
||||
expect(resolved.slides[0].start).toBe(1);
|
||||
expect(resolved.slides[0].end).toBe(4);
|
||||
});
|
||||
|
||||
it("parses and carries through the per-slide autoplay flag", () => {
|
||||
const island = `<script type="application/hyperframes-slideshow+json">
|
||||
{ "slides": [ { "sceneId": "a", "autoplay": true }, { "sceneId": "b" } ] }
|
||||
</script>`;
|
||||
const m = parseSlideshowManifest(island);
|
||||
expect(m?.slides[0].autoplay).toBe(true);
|
||||
expect(m?.slides[1].autoplay).toBeUndefined();
|
||||
const { resolved } = resolveSlideshow(m!, SCENES);
|
||||
expect(resolved.slides[0].autoplay).toBe(true);
|
||||
expect(resolved.slides[1].autoplay).toBeUndefined();
|
||||
});
|
||||
|
||||
it("rejects a manifest whose slide autoplay is not a boolean", () => {
|
||||
const island = `<script type="application/hyperframes-slideshow+json">
|
||||
{ "slides": [ { "sceneId": "a", "autoplay": "yes" } ] }
|
||||
</script>`;
|
||||
expect(() => parseSlideshowManifest(island)).toThrow();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -44,16 +44,21 @@ export function parseSlideshowManifest(html: string): SlideshowManifest | null {
|
||||
return parsed;
|
||||
}
|
||||
|
||||
function isOptionalNumberArray(v: unknown): boolean {
|
||||
return v === undefined || (Array.isArray(v) && v.every((n) => typeof n === "number"));
|
||||
}
|
||||
|
||||
function isOptionalBoolean(v: unknown): v is boolean | undefined {
|
||||
return v === undefined || typeof v === "boolean";
|
||||
}
|
||||
|
||||
function isSlideRef(v: unknown): v is SlideRef {
|
||||
if (typeof v !== "object" || v === null) return false;
|
||||
const r = v as Record<string, unknown>;
|
||||
if (typeof r["sceneId"] !== "string") return false;
|
||||
if (
|
||||
r["fragments"] !== undefined &&
|
||||
!(Array.isArray(r["fragments"]) && r["fragments"].every((n) => typeof n === "number"))
|
||||
)
|
||||
return false;
|
||||
if (!isOptionalNumberArray(r["fragments"])) return false;
|
||||
if (r["hotspots"] !== undefined && !Array.isArray(r["hotspots"])) return false;
|
||||
if (!isOptionalBoolean(r["autoplay"])) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -19,6 +19,14 @@ export interface SlideRef {
|
||||
notes?: string;
|
||||
fragments?: number[];
|
||||
hotspots?: SlideHotspot[];
|
||||
/**
|
||||
* When true, the slide's first `<video>` plays automatically on enter (the
|
||||
* presenter lands on the slide and the clip plays). The slideshow still holds
|
||||
* — it never auto-advances — so the presenter clicks Next when ready.
|
||||
* Defaults to false. Use it when the video is the slide's primary content and
|
||||
* its natural end is the cue to advance, not for background/ambient clips.
|
||||
*/
|
||||
autoplay?: boolean;
|
||||
// Reserved — TTS deferred. Parsed and carried, never consumed.
|
||||
ttsScript?: string;
|
||||
ttsAudioUrl?: string;
|
||||
|
||||
Reference in New Issue
Block a user