mirror of
https://github.com/Tonejs/Tone.js
synced 2024-11-16 00:27:58 +00:00
using TONE_AUDIO_CONTEXT if it exists
This commit is contained in:
parent
5cc56cbea1
commit
9ac9de5b12
1 changed files with 7 additions and 0 deletions
|
@ -6,12 +6,17 @@ import { version } from "../version";
|
|||
*/
|
||||
let globalContext: BaseAudioContext;
|
||||
|
||||
// @ts-ignore
|
||||
globalContext = window.TONE_AUDIO_CONTEXT;
|
||||
|
||||
/**
|
||||
* Returns the default system-wide AudioContext
|
||||
*/
|
||||
export function getContext(): BaseAudioContext {
|
||||
if (!globalContext) {
|
||||
globalContext = new AudioContext();
|
||||
// @ts-ignore
|
||||
window.TONE_AUDIO_CONTEXT = globalContext;
|
||||
}
|
||||
return globalContext;
|
||||
}
|
||||
|
@ -21,6 +26,8 @@ export function getContext(): BaseAudioContext {
|
|||
*/
|
||||
export function setContext(context: BaseAudioContext): void {
|
||||
globalContext = context;
|
||||
// @ts-ignore
|
||||
window.TONE_AUDIO_CONTEXT = globalContext;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue