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,22 +126,25 @@ 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() {
await initAudio();
resolve();
document.removeEventListener('click', listener); document.removeEventListener('click', listener);
}); });
});
} }
function gainNode(value) { function gainNode(value) {