allow worklet-based effects to be used with native contexts (#1131)

* check for native context when creating AudioWorkletNode

* better context check per @chrisguttandin

---------

Co-authored-by: Yotam Mann <hi@yotammann.info>
This commit is contained in:
Marcel Blum 2024-05-06 11:25:17 -04:00 committed by GitHub
parent 56fea7cb70
commit f06ff17f06
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -41,6 +41,8 @@ export type AnyAudioContext = AudioContext | OfflineAudioContext;
interface ToneWindow extends Window {
TONE_SILENCE_LOGGING?: boolean;
TONE_DEBUG_CLASS?: string;
BaseAudioContext: any;
AudioWorkletNode: any;
}
/**
@ -66,10 +68,13 @@ export function createAudioWorkletNode(
): AudioWorkletNode {
assert(
isDefined(stdAudioWorkletNode),
"This node only works in a secure context (https or localhost)"
"AudioWorkletNode only works in a secure context (https or localhost)"
);
// @ts-ignore
return new stdAudioWorkletNode(context, name, options);
return new (
context instanceof theWindow?.BaseAudioContext
? theWindow?.AudioWorkletNode
: stdAudioWorkletNode
)(context, name, options);
}
/**