},
watch: {
$route: function(to, from) {
- if (from.params["id"] != to.params["id"]) {
+ if (to.path.length < 6 || to.path.substr(6) != "/game/")
+ // Page change
+ this.cleanBeforeDestroy();
+ else if (from.params["id"] != to.params["id"]) {
// Change everything:
this.cleanBeforeDestroy();
let boardDiv = document.querySelector(".game");
this.atCreation();
},
mounted: function() {
- document.addEventListener('visibilitychange', this.visibilityChange);
["chatWrap", "infoDiv"].forEach(eltName => {
document.getElementById(eltName)
.addEventListener("click", processModalClick);
}
},
beforeDestroy: function() {
- document.removeEventListener('visibilitychange', this.visibilityChange);
this.cleanBeforeDestroy();
},
methods: {
+ cleanBeforeDestroy: function() {
+ document.removeEventListener('visibilitychange', this.visibilityChange);
+ if (!!this.askLastate)
+ clearInterval(this.askLastate);
+ if (!!this.retrySendmove)
+ clearInterval(this.retrySendmove);
+ if (!!this.clockUpdate)
+ clearInterval(this.clockUpdate);
+ this.send("disconnect");
+ },
visibilityChange: function() {
// TODO: Use document.hidden? https://webplatform.news/issues/2019-03-27
this.send(
);
},
atCreation: function() {
+ document.addEventListener('visibilitychange', this.visibilityChange);
// 0] (Re)Set variables
this.gameRef = this.$route.params["id"];
// next = next corr games IDs to navigate faster (if applicable)
socketInit(() => { this.send("askfullgame"); });
});
},
- cleanBeforeDestroy: function() {
- if (!!this.askLastate)
- clearInterval(this.askLastate);
- if (!!this.retrySendmove)
- clearInterval(this.retrySendmove);
- if (!!this.clockUpdate)
- clearInterval(this.clockUpdate);
- this.send("disconnect");
- },
roomInit: function() {
if (!this.roomInitialized) {
// Notify the room only now that I connected, because
if (!this.killed[this.st.user.sid]) {
// Ask potentially missed last state, if opponent and I play
if (
+ !this.gotLastate &&
!!this.game.mycolor &&
this.game.type == "live" &&
this.game.score == "*" &&