From 53081c5f3124fcf4b7f403559f7a53f3febcd991 Mon Sep 17 00:00:00 2001 From: Pavle Goloskokovic Date: Tue, 24 Dec 2024 16:23:06 +0100 Subject: [PATCH 1/4] added mousedown and mouseup event listeners for unlocking web audio --- src/sound/webaudio/WebAudioSoundManager.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/sound/webaudio/WebAudioSoundManager.js b/src/sound/webaudio/WebAudioSoundManager.js index 90860ba6de..244ee22cd6 100644 --- a/src/sound/webaudio/WebAudioSoundManager.js +++ b/src/sound/webaudio/WebAudioSoundManager.js @@ -320,14 +320,19 @@ var WebAudioSoundManager = new Class({ { bodyRemove('touchstart', unlockHandler); bodyRemove('touchend', unlockHandler); + bodyRemove('mousedown', unlockHandler); + bodyRemove('mouseup', unlockHandler); bodyRemove('click', unlockHandler); bodyRemove('keydown', unlockHandler); _this.unlocked = true; + }, function () { bodyRemove('touchstart', unlockHandler); bodyRemove('touchend', unlockHandler); + bodyRemove('mousedown', unlockHandler); + bodyRemove('mouseup', unlockHandler); bodyRemove('click', unlockHandler); bodyRemove('keydown', unlockHandler); }); @@ -338,6 +343,8 @@ var WebAudioSoundManager = new Class({ { body.addEventListener('touchstart', unlockHandler, false); body.addEventListener('touchend', unlockHandler, false); + body.addEventListener('mousedown', unlockHandler, false); + body.addEventListener('mouseup', unlockHandler, false); body.addEventListener('click', unlockHandler, false); body.addEventListener('keydown', unlockHandler, false); } From 95a981d86ccb0706e7a3f4c0a8f116e59a59262d Mon Sep 17 00:00:00 2001 From: Pavle Goloskokovic Date: Fri, 27 Dec 2024 12:44:58 +0100 Subject: [PATCH 2/4] removed 'click' handler for unlocking --- src/sound/webaudio/WebAudioSoundManager.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/sound/webaudio/WebAudioSoundManager.js b/src/sound/webaudio/WebAudioSoundManager.js index 244ee22cd6..ef7a2267a2 100644 --- a/src/sound/webaudio/WebAudioSoundManager.js +++ b/src/sound/webaudio/WebAudioSoundManager.js @@ -322,7 +322,6 @@ var WebAudioSoundManager = new Class({ bodyRemove('touchend', unlockHandler); bodyRemove('mousedown', unlockHandler); bodyRemove('mouseup', unlockHandler); - bodyRemove('click', unlockHandler); bodyRemove('keydown', unlockHandler); _this.unlocked = true; @@ -333,7 +332,6 @@ var WebAudioSoundManager = new Class({ bodyRemove('touchend', unlockHandler); bodyRemove('mousedown', unlockHandler); bodyRemove('mouseup', unlockHandler); - bodyRemove('click', unlockHandler); bodyRemove('keydown', unlockHandler); }); } @@ -345,7 +343,6 @@ var WebAudioSoundManager = new Class({ body.addEventListener('touchend', unlockHandler, false); body.addEventListener('mousedown', unlockHandler, false); body.addEventListener('mouseup', unlockHandler, false); - body.addEventListener('click', unlockHandler, false); body.addEventListener('keydown', unlockHandler, false); } }, From 5dab6964829751bba52fb0f1939e8906c5100a9f Mon Sep 17 00:00:00 2001 From: Pavle Goloskokovic Date: Fri, 27 Dec 2024 12:46:21 +0100 Subject: [PATCH 3/4] updated locked condition to only depend on audio context state --- src/sound/webaudio/WebAudioSoundManager.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sound/webaudio/WebAudioSoundManager.js b/src/sound/webaudio/WebAudioSoundManager.js index ef7a2267a2..2e8b1b8082 100644 --- a/src/sound/webaudio/WebAudioSoundManager.js +++ b/src/sound/webaudio/WebAudioSoundManager.js @@ -77,7 +77,7 @@ var WebAudioSoundManager = new Class({ */ this.destination = this.masterMuteNode; - this.locked = this.context.state === 'suspended' && ('ontouchstart' in window || 'onclick' in window); + this.locked = this.context.state === 'suspended'; BaseSoundManager.call(this, game); From 42979bbe16e88d531209511ca2dd0741245dbe57 Mon Sep 17 00:00:00 2001 From: Pavle Goloskokovic Date: Fri, 27 Dec 2024 12:47:10 +0100 Subject: [PATCH 4/4] unlock condition fix --- src/sound/webaudio/WebAudioSoundManager.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/sound/webaudio/WebAudioSoundManager.js b/src/sound/webaudio/WebAudioSoundManager.js index 2e8b1b8082..53bbae9c0b 100644 --- a/src/sound/webaudio/WebAudioSoundManager.js +++ b/src/sound/webaudio/WebAudioSoundManager.js @@ -81,13 +81,16 @@ var WebAudioSoundManager = new Class({ BaseSoundManager.call(this, game); - if (this.locked && game.isBooted) + if (this.locked) { - this.unlock(); - } - else - { - game.events.once(GameEvents.BOOT, this.unlock, this); + if (game.isBooted) + { + this.unlock(); + } + else + { + game.events.once(GameEvents.BOOT, this.unlock, this); + } } },