mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-09-03 04:38:33 +00:00
fix(player,studio): resolve root timeline from DOM instead of last key (#247)
Bundled previews register a master composition alongside its sub-compositions
in `window.__timelines`, e.g. { main, intro, scene2, scene5 }. Both the
player's probe and studio's getAdapter() were using `keys[keys.length - 1]`
to pick the adapter, which returned whichever timeline was registered last.
That made the player report the final sub-composition's duration as the
video length (e.g. 3.2s instead of the master's 14s) and play/pause/seek
targeted that sub-composition instead of the full composition.
Look up the outermost `[data-composition-id]` element in the iframe DOM
and use its id to select the right timeline. Falls back to last-key when
no element is present (standalone sub-composition previews) so drill-down
views keep working.
Also restores `main`/`import` entry points on @hyperframes/player to
point at compiled dist output (the src/ paths broke workspace consumers
that only receive the published tarball).
This commit is contained in:
@@ -238,7 +238,17 @@ export function useTimelinePlayer() {
|
||||
|
||||
if (win.__timelines) {
|
||||
const keys = Object.keys(win.__timelines);
|
||||
if (keys.length > 0) return wrapTimeline(win.__timelines[keys[keys.length - 1]]);
|
||||
if (keys.length > 0) {
|
||||
// Resolve the root composition id from the DOM — the outermost
|
||||
// `[data-composition-id]` element is the master. Without this,
|
||||
// Object.keys() order would let a sub-composition's timeline
|
||||
// hijack play/pause/seek and the duration readout.
|
||||
const rootId = iframe?.contentDocument
|
||||
?.querySelector("[data-composition-id]")
|
||||
?.getAttribute("data-composition-id");
|
||||
const key = rootId && rootId in win.__timelines ? rootId : keys[keys.length - 1];
|
||||
return wrapTimeline(win.__timelines[key]);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
Reference in New Issue
Block a user