Skip to content

Commit

Permalink
Merge pull request #72 from tridecco/bugfix/71-disconnect-event-liste…
Browse files Browse the repository at this point in the history
…ner-triggers-incorrectly-after-game-ends

fix: Clear All Event Listeners After Game Ends
  • Loading branch information
tedhyu authored Dec 25, 2024
2 parents e8b89bf + d4a9ce6 commit 1e4a272
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions public/js/game.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,18 @@ class GameNetwork {
removeListener(event, listener) {
this.socket.off(event, listener);
}

/**
* Remove all listeners.
* @param {string} [event] - The event name. (Optional)
*/
removeAllListeners(event) {
if (event) {
this.socket.removeAllListeners(event);
} else {
this.socket.removeAllListeners();
}
}
}

/**
Expand Down Expand Up @@ -2329,6 +2341,8 @@ class Game {
}
}, 2000);

this.network.removeAllListeners();

this.ui.stopPreventSleep();

this.audio.stop("countdown");
Expand Down

0 comments on commit 1e4a272

Please sign in to comment.