mirror of
https://github.com/Tonejs/Tone.js
synced 2024-12-26 03:23:11 +00:00
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:
parent
56fea7cb70
commit
f06ff17f06
1 changed files with 8 additions and 3 deletions
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue