updated to return promise on first click
This commit is contained in:
parent
c0c54c21e3
commit
af3d32a493
2 changed files with 16 additions and 14 deletions
|
|
@ -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 = {};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue