mirror of
https://github.com/Tonejs/Tone.js
synced 2024-12-26 11:33:09 +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 {
|
interface ToneWindow extends Window {
|
||||||
TONE_SILENCE_LOGGING?: boolean;
|
TONE_SILENCE_LOGGING?: boolean;
|
||||||
TONE_DEBUG_CLASS?: string;
|
TONE_DEBUG_CLASS?: string;
|
||||||
|
BaseAudioContext: any;
|
||||||
|
AudioWorkletNode: any;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -66,10 +68,13 @@ export function createAudioWorkletNode(
|
||||||
): AudioWorkletNode {
|
): AudioWorkletNode {
|
||||||
assert(
|
assert(
|
||||||
isDefined(stdAudioWorkletNode),
|
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 (
|
||||||
return new stdAudioWorkletNode(context, name, options);
|
context instanceof theWindow?.BaseAudioContext
|
||||||
|
? theWindow?.AudioWorkletNode
|
||||||
|
: stdAudioWorkletNode
|
||||||
|
)(context, name, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue