updated to return promise on first click

This commit is contained in:
Jade (Rose) Rowland 2024-05-30 18:52:28 -04:00
parent c0c54c21e3
commit af3d32a493
2 changed files with 16 additions and 14 deletions

View file

@ -64,15 +64,18 @@ export async function initAudio(options = {}) {
}
}
}
let audioReady = false;
export async function initAudioOnFirstClick(options) {
return new Promise((resolve) => {
document.addEventListener('click', async function listener() {
await initAudio(options);
resolve();
document.removeEventListener('click', listener);
if (!audioReady) {
audioReady = new Promise((resolve) => {
document.addEventListener('click', async function listener() {
await initAudio(options);
resolve();
document.removeEventListener('click', listener);
});
});
});
}
return audioReady;
}
let delays = {};