From f06ff17f060ab44f2f848e080e98ba7b1bf7d36e Mon Sep 17 00:00:00 2001 From: Marcel Blum Date: Mon, 6 May 2024 11:25:17 -0400 Subject: [PATCH] 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 --- Tone/core/context/AudioContext.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/Tone/core/context/AudioContext.ts b/Tone/core/context/AudioContext.ts index a162fc68..5012e098 100644 --- a/Tone/core/context/AudioContext.ts +++ b/Tone/core/context/AudioContext.ts @@ -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); } /**