Skip to content

Commit

Permalink
refined the code to avoid multiple additions of gesture emitter, see #…
Browse files Browse the repository at this point in the history
  • Loading branch information
jbphet committed Apr 22, 2022
1 parent cae927b commit a2979ba
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions js/soundManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -301,18 +301,14 @@ class SoundManager extends PhetioObject {
phetAudioContext.currentTime}`
);

console.log( `slime: state = ${state}` );
if ( state !== 'running' ) {

// add a listener that will resume the audio context on the next touchstart
// Add a listener that will resume the audio context on the next touchstart.
window.addEventListener( 'touchstart', resumeAudioContext, false );

// listen for other user gesture events too
if ( Display.userGestureEmitter.hasListener( resumeAudioContext ) ) {

// TODO: See https://github.com/phetsims/tambo/issues/162
console.log( 'already has listener, see https://github.com/phetsims/tambo/issues/162' );
}
else {
// Listen also for other user gesture events that can be used to resume the audio context.
if ( !Display.userGestureEmitter.hasListener( resumeAudioContext ) ) {
Display.userGestureEmitter.addListener( resumeAudioContext );
}
}
Expand Down

0 comments on commit a2979ba

Please sign in to comment.