MCPcopy Create free account
hub / github.com/heygen-com/hyperframes / start

Method start

packages/player/src/composition-probe.ts:80–138  ·  view source on GitHub ↗

Start (or restart) the probe. Stops any previously running probe first.

()

Source from the content-addressed store, hash-verified

78
79 /** Start (or restart) the probe. Stops any previously running probe first. */
80 start(): void {
81 this.stop();
82 this._runtimeInjected = false;
83 let attempts = 0;
84
85 // fallow-ignore-next-line complexity
86 this._interval = setInterval(() => {
87 attempts++;
88 try {
89 const win = this._iframe.contentWindow as Window & {
90 __player?: { getDuration: () => number };
91 __timelines?: Record<string, { duration: () => number }>;
92 __hf?: unknown;
93 };
94 if (!win) return;
95
96 const hasRuntime = !!(win.__hf || win.__player);
97 const hasTimelines = !!(win.__timelines && Object.keys(win.__timelines).length > 0);
98 const hasNestedCompositions =
99 !!this._iframe.contentDocument?.querySelector("[data-composition-src]");
100
101 if (
102 shouldInjectRuntime({
103 hasRuntime,
104 hasTimelines,
105 hasNestedCompositions,
106 runtimeInjected: this._runtimeInjected,
107 attempts,
108 })
109 ) {
110 this._injectRuntime();
111 return;
112 }
113
114 if (this._runtimeInjected && !hasRuntime) return;
115
116 const adapter = this._resolvePlaybackDurationAdapter(win);
117 if (adapter && adapter.getDuration() > 0) {
118 this.stop();
119
120 const compositionSize = readCompositionSizeFromDocument(this._iframe.contentDocument);
121
122 this._callbacks.onReady({
123 duration: adapter.getDuration(),
124 adapter,
125 compositionSize,
126 });
127 return;
128 }
129 } catch {
130 /* cross-origin */
131 }
132
133 if (attempts >= 40) {
134 this.stop();
135 this._callbacks.onError("Composition timeline not found after 8s");
136 }
137 }, 200);

Callers 15

startBoundedSourceFunction · 0.45
runFunction · 0.45
runFunction · 0.45
publishReproFunction · 0.45
transcribeAudioFunction · 0.45
runEnsureFunction · 0.45
runFunction · 0.45
handleVideoFileFunction · 0.45
runFunction · 0.45
runFunction · 0.45
runFunction · 0.45
runFunction · 0.45

Calls 7

stopMethod · 0.95
_injectRuntimeMethod · 0.95
shouldInjectRuntimeFunction · 0.85
querySelectorMethod · 0.65
getDurationMethod · 0.65

Tested by

no test coverage detected