clearInterval(this.retrySendmove);
if (!!this.clockUpdate)
clearInterval(this.clockUpdate);
+ this.conn.removeEventListener("message", this.socketMessageListener);
+ this.conn.removeEventListener("close", this.socketCloseListener);
this.send("disconnect");
+ this.conn = null;
},
visibilityChange: function() {
// TODO: Use document.hidden? https://webplatform.news/issues/2019-03-27
cleanBeforeDestroy: function() {
document.removeEventListener('visibilitychange', this.visibilityChange);
window.removeEventListener("beforeunload", this.cleanBeforeDestroy);
+ this.conn.removeEventListener("message", this.socketMessageListener);
+ this.conn.removeEventListener("close", this.socketCloseListener);
this.send("disconnect");
+ this.conn = null;
},
getRandomnessClass: function(pc) {
return {
methods: {
cleanBeforeDestroy: function() {
window.removeEventListener("beforeunload", this.cleanBeforeDestroy);
+ this.conn.removeEventListener("message", this.socketMessageListener);
+ this.conn.removeEventListener("close", this.socketCloseListener);
this.conn.send(JSON.stringify({code: "disconnect"}));
+ this.conn = null;
},
setDisplay: function(type, e) {
this.display = type;
});
},
socketMessageListener: function(msg) {
+ if (!this.conn) return;
const data = JSON.parse(msg.data);
let gamesArrays = {
"corr": this.corrGames,
game.players[0].sid == this.st.user.sid
? game.players[1].sid
: game.players[0].sid;
- this.conn.send(
- JSON.stringify(
- {
- code: "mabort",
- gid: game.id,
- // NOTE: target might not be online
- target: oppsid
- }
- )
- );
+ if (!!this.conn) {
+ this.conn.send(
+ JSON.stringify(
+ {
+ code: "mabort",
+ gid: game.id,
+ // NOTE: target might not be online
+ target: oppsid
+ }
+ )
+ );
+ }
}
else if (!game.deletedByWhite || !game.deletedByBlack) {
// Set score if game isn't deleted on server: