using TONE_AUDIO_CONTEXT if it exists

This commit is contained in:
tambien 2019-06-17 21:53:54 -04:00
parent 5cc56cbea1
commit 9ac9de5b12

View file

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