Skip to content

Instantly share code, notes, and snippets.

@buesing
Created June 28, 2019 11:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save buesing/0c8ea45694cb53be15d54dfc7c34b0f1 to your computer and use it in GitHub Desktop.
Save buesing/0c8ea45694cb53be15d54dfc7c34b0f1 to your computer and use it in GitHub Desktop.
$(window).on('beforeunload', () => {
if (this.isOpponentConnected) {
// tell opponent we disconnected
this.statusRecord.set(`player-${this.isHost ? 1 : 2}`, {action: ACTION.DISCONNECT});
}
if (this.statusRecord) {
// delete all records
this.statusRecord.discard();
this.statusRecord.delete();
this.paddle1Record.discard();
this.paddle1Record.delete();
this.paddle2Record.discard();
this.paddle2Record.delete();
this.hitRecord.discard();
this.hitRecord.delete();
this.missRecord.discard();
this.missRecord.delete();
this.pingRecord.discard();
this.pingRecord.delete();
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment