mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-18 16:08:56 +00:00
* fix(engine): a render no longer decodes the videos it replaces with extracted frames * fix(engine): shorten the render-frame video hold comment * fix(engine): keep the render-frame video hold comment under the line limit * fix(engine): hold only the videos whose render id is replaced by extracted frames Two scenes can share a video id. The render id tells them apart, so a live video is no longer held.
20 lines
860 B
TypeScript
20 lines
860 B
TypeScript
/** In-page, before any script: holds replaced videos at preload none from parse (Chrome ignores a later none). */
|
|
export function holdRenderFrameVideos(ids: readonly string[], renderIdAttr: string): void {
|
|
const held = new Set(ids);
|
|
(
|
|
window as Window & { __HF_RENDER_FRAME_VIDEO_IDS?: readonly string[] }
|
|
).__HF_RENDER_FRAME_VIDEO_IDS = ids;
|
|
const hold = (el: Element) => {
|
|
if (el instanceof HTMLVideoElement && held.has(el.getAttribute(renderIdAttr) || el.id))
|
|
el.preload = "none";
|
|
};
|
|
new MutationObserver((records) => {
|
|
for (const record of records)
|
|
for (const node of record.addedNodes) {
|
|
if (node.nodeType !== 1) continue;
|
|
hold(node as Element);
|
|
for (const video of (node as Element).querySelectorAll("video")) hold(video);
|
|
}
|
|
}).observe(document, { childList: true, subtree: true });
|
|
}
|