mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-17 15:24:19 +00:00
fix(audio): let the volume probe run where there is no DOM
The unclamped-volume shim reached for `HTMLMediaElement.prototype` before checking that a DOM exists. The renderer's probe body is serialized into the page in production but executed directly by tests that stand in for a Page, so under the bun lane it threw `ReferenceError: HTMLMediaElement is not defined` instead of falling back. Both copies now degrade to the clamped path when the constructor is absent, which is the only correct answer off-browser.
This commit is contained in:
@@ -52,7 +52,13 @@ export function formatAudioGain(gain: number): string {
|
||||
* probe observes an out-of-range volume, and the shadow is removed afterwards.
|
||||
*/
|
||||
export function withUnclampedVolume<T>(el: HTMLMediaElement, probe: () => T): T {
|
||||
const descriptor = Object.getOwnPropertyDescriptor(HTMLMediaElement.prototype, "volume");
|
||||
// Guarded for non-DOM runtimes: the probe that calls this is also reachable
|
||||
// from tests and tools that run outside a browser, where the clamped path is
|
||||
// the right (and only) answer.
|
||||
const descriptor =
|
||||
typeof HTMLMediaElement === "undefined"
|
||||
? undefined
|
||||
: Object.getOwnPropertyDescriptor(HTMLMediaElement.prototype, "volume");
|
||||
const nativeGet = descriptor?.get;
|
||||
const nativeSet = descriptor?.set;
|
||||
if (!nativeGet || !nativeSet) return probe();
|
||||
|
||||
@@ -2215,10 +2215,13 @@ export async function discoverAudioVolumeAutomationFromTimeline(
|
||||
// the clamped value. Mirrors `withUnclampedVolume` in
|
||||
// packages/core/src/audioGain.ts, which the preview probe uses; this copy
|
||||
// exists only because the probe body is serialized into the page.
|
||||
const volumeDescriptor = Object.getOwnPropertyDescriptor(
|
||||
HTMLMediaElement.prototype,
|
||||
"volume",
|
||||
);
|
||||
// Guarded because this body is also executed directly by tests that
|
||||
// stand in for a Page, where there is no DOM and no HTMLMediaElement.
|
||||
// Without the descriptor the probe simply keeps the clamped path.
|
||||
const volumeDescriptor =
|
||||
typeof HTMLMediaElement === "undefined"
|
||||
? undefined
|
||||
: Object.getOwnPropertyDescriptor(HTMLMediaElement.prototype, "volume");
|
||||
const nativeVolumeGet = volumeDescriptor?.get;
|
||||
const nativeVolumeSet = volumeDescriptor?.set;
|
||||
const withUnclampedVolume = <T>(el: HTMLMediaElement, probe: () => T): T => {
|
||||
|
||||
Reference in New Issue
Block a user