Skip to content

Commit

Permalink
allow worklet-based effects to be used with native contexts (#1131)
Browse files Browse the repository at this point in the history
* check for native context when creating AudioWorkletNode

* better context check per @chrisguttandin

---------

Co-authored-by: Yotam Mann <[email protected]>
  • Loading branch information
marcelblum and tambien authored May 6, 2024
1 parent 56fea7c commit f06ff17
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions Tone/core/context/AudioContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand All @@ -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);
}

/**
Expand Down

0 comments on commit f06ff17

Please sign in to comment.