From b6c6d29c84ac969e6a47798e2c6b55620bb26ddd Mon Sep 17 00:00:00 2001 From: jsemu Date: Sat, 27 Apr 2019 03:50:29 -0400 Subject: [PATCH] Update XAudioServer.js --- user_scripts/XAudioJS/XAudioServer.js | 28 ++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/user_scripts/XAudioJS/XAudioServer.js b/user_scripts/XAudioJS/XAudioServer.js index 72efb7e..1f83264 100644 --- a/user_scripts/XAudioJS/XAudioServer.js +++ b/user_scripts/XAudioJS/XAudioServer.js @@ -174,15 +174,25 @@ XAudioServer.prototype.initializeWebAudio = function () { } else { var parentObj = this; - var lazyEnableWA = function () { - parentObj.setupWebAudio(); - } - try { - this.userEventLatch.addEventListener("click", lazyEnableWA, false); - this.userEventLatch.addEventListener("touchstart", lazyEnableWA, false); - this.userEventLatch.addEventListener("touchend", lazyEnableWA, false); - } - catch (e) {} + var XAudioJSWebAudioDelayedEvent = 0; + this.userEventLatch.addEventListener("click", function () { + if (XAudioJSWebAudioDelayedEvent == 0) { + parentObj.setupWebAudio(); + XAudioJSWebAudioDelayedEvent |= 1; + } + }, false); + this.userEventLatch.addEventListener("touchstart", function () { + if (XAudioJSWebAudioDelayedEvent < 2) { + parentObj.setupWebAudio(); + XAudioJSWebAudioDelayedEvent |= 2; + } + }, false); + this.userEventLatch.addEventListener("touchend", function () { + if (XAudioJSWebAudioDelayedEvent < 4) { + parentObj.setupWebAudio(); + XAudioJSWebAudioDelayedEvent |= 4; + } + }, false); //TODO: Restructure API to not have to potentially lie to end client about //the samples in buffer before user driven event callback that actually starts WA. this.resetCallbackAPIAudioBuffer(44100);