Skip to content

Commit

Permalink
Merge pull request #6994 from pavle-goloskokovic/mouse-events-audio-u…
Browse files Browse the repository at this point in the history
…nlock

Mouse events for unlocking Web Audio
  • Loading branch information
photonstorm authored Jan 2, 2025
2 parents 041c90f + 42979bb commit d847fdf
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions src/sound/webaudio/WebAudioSoundManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,17 +77,20 @@ 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);

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);
}
}
},

Expand Down Expand Up @@ -320,15 +323,18 @@ var WebAudioSoundManager = new Class({
{
bodyRemove('touchstart', unlockHandler);
bodyRemove('touchend', unlockHandler);
bodyRemove('click', unlockHandler);
bodyRemove('mousedown', unlockHandler);
bodyRemove('mouseup', unlockHandler);
bodyRemove('keydown', unlockHandler);

_this.unlocked = true;

}, function ()
{
bodyRemove('touchstart', unlockHandler);
bodyRemove('touchend', unlockHandler);
bodyRemove('click', unlockHandler);
bodyRemove('mousedown', unlockHandler);
bodyRemove('mouseup', unlockHandler);
bodyRemove('keydown', unlockHandler);
});
}
Expand All @@ -338,7 +344,8 @@ var WebAudioSoundManager = new Class({
{
body.addEventListener('touchstart', unlockHandler, false);
body.addEventListener('touchend', unlockHandler, false);
body.addEventListener('click', unlockHandler, false);
body.addEventListener('mousedown', unlockHandler, false);
body.addEventListener('mouseup', unlockHandler, false);
body.addEventListener('keydown', unlockHandler, false);
}
},
Expand Down

0 comments on commit d847fdf

Please sign in to comment.