can now await initAudio + initAudioOnFirstClick

This commit is contained in:
Felix Roos 2023-02-01 22:42:25 +01:00
parent 1457eb9d19
commit 014ae2107e

View File

@ -126,21 +126,24 @@ function getWorklet(ac, processor, params) {
} }
// this function should be called on first user interaction (to avoid console warning) // this function should be called on first user interaction (to avoid console warning)
export function initAudio() { export async function initAudio() {
if (typeof window !== 'undefined') { if (typeof window !== 'undefined') {
try { try {
getAudioContext().resume(); await getAudioContext().resume();
loadWorklets(); await loadWorklets();
} catch (err) { } catch (err) {
console.warn('could not load AudioWorklet effects coarse, crush and shape', err); console.warn('could not load AudioWorklet effects coarse, crush and shape', err);
} }
} }
} }
export function initAudioOnFirstClick() { export async function initAudioOnFirstClick() {
document.addEventListener('click', function listener() { return new Promise((resolve) => {
initAudio(); document.addEventListener('click', async function listener() {
document.removeEventListener('click', listener); await initAudio();
resolve();
document.removeEventListener('click', listener);
});
}); });
} }