projects
/
vchess.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
a8f0bbc
)
Attempt to get rid of the weird trans-pages errors (especially in Game)
author
Benjamin Auder
<benjamin.auder@somewhere>
Sun, 22 Mar 2020 12:59:22 +0000
(13:59 +0100)
committer
Benjamin Auder
<benjamin.auder@somewhere>
Sun, 22 Mar 2020 12:59:22 +0000
(13:59 +0100)
client/src/views/Game.vue
patch
|
blob
|
blame
|
history
client/src/views/Hall.vue
patch
|
blob
|
blame
|
history
client/src/views/MyGames.vue
patch
|
blob
|
blame
|
history
server/models/Game.js
patch
|
blob
|
blame
|
history
diff --git
a/client/src/views/Game.vue
b/client/src/views/Game.vue
index
ddbd330
..
f7e5549
100644
(file)
--- a/
client/src/views/Game.vue
+++ b/
client/src/views/Game.vue
@@
-192,7
+192,10
@@
export default {
},
watch: {
$route: function(to, from) {
},
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");
// Change everything:
this.cleanBeforeDestroy();
let boardDiv = document.querySelector(".game");
@@
-210,7
+213,6
@@
export default {
this.atCreation();
},
mounted: function() {
this.atCreation();
},
mounted: function() {
- document.addEventListener('visibilitychange', this.visibilityChange);
["chatWrap", "infoDiv"].forEach(eltName => {
document.getElementById(eltName)
.addEventListener("click", processModalClick);
["chatWrap", "infoDiv"].forEach(eltName => {
document.getElementById(eltName)
.addEventListener("click", processModalClick);
@@
-223,10
+225,19
@@
export default {
}
},
beforeDestroy: function() {
}
},
beforeDestroy: function() {
- document.removeEventListener('visibilitychange', this.visibilityChange);
this.cleanBeforeDestroy();
},
methods: {
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(
visibilityChange: function() {
// TODO: Use document.hidden? https://webplatform.news/issues/2019-03-27
this.send(
@@
-236,6
+247,7
@@
export default {
);
},
atCreation: function() {
);
},
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)
// 0] (Re)Set variables
this.gameRef = this.$route.params["id"];
// next = next corr games IDs to navigate faster (if applicable)
@@
-310,15
+322,6
@@
export default {
socketInit(() => { this.send("askfullgame"); });
});
},
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
roomInit: function() {
if (!this.roomInitialized) {
// Notify the room only now that I connected, because
diff --git
a/client/src/views/Hall.vue
b/client/src/views/Hall.vue
index
2863546
..
f401c6e
100644
(file)
--- a/
client/src/views/Hall.vue
+++ b/
client/src/views/Hall.vue
@@
-267,9
+267,14
@@
export default {
});
if (!this.newchallenge.V && this.newchallenge.vid > 0)
this.loadNewchallVariant();
});
if (!this.newchallenge.V && this.newchallenge.vid > 0)
this.loadNewchallVariant();
+ },
+ $route: function(to, from) {
+ if (to.path != "/") this.cleanBeforeDestroy();
}
},
created: function() {
}
},
created: function() {
+ document.addEventListener('visibilitychange', this.visibilityChange);
+ window.addEventListener("beforeunload", this.cleanBeforeDestroy);
if (this.st.variants.length > 0 && this.newchallenge.vid > 0)
this.loadNewchallVariant();
const my = this.st.user;
if (this.st.variants.length > 0 && this.newchallenge.vid > 0)
this.loadNewchallVariant();
const my = this.st.user;
@@
-304,7
+309,6
@@
export default {
this.conn.addEventListener("close", this.socketCloseListener);
},
mounted: function() {
this.conn.addEventListener("close", this.socketCloseListener);
},
mounted: function() {
- document.addEventListener('visibilitychange', this.visibilityChange);
["peopleWrap", "infoDiv", "newgameDiv"].forEach(eltName => {
document.getElementById(eltName)
.addEventListener("click", processModalClick);
["peopleWrap", "infoDiv", "newgameDiv"].forEach(eltName => {
document.getElementById(eltName)
.addEventListener("click", processModalClick);
@@
-388,10
+392,14
@@
export default {
);
},
beforeDestroy: function() {
);
},
beforeDestroy: function() {
- document.removeEventListener('visibilitychange', this.visibilityChange);
- this.send("disconnect");
+ this.cleanBeforeDestroy();
},
methods: {
},
methods: {
+ cleanBeforeDestroy: function() {
+ document.removeEventListener('visibilitychange', this.visibilityChange);
+ window.removeEventListener("beforeunload", this.cleanBeforeDestroy);
+ this.send("disconnect");
+ },
getRandomnessClass: function(pc) {
return {
["random-" + pc.randomness]: true
getRandomnessClass: function(pc) {
return {
["random-" + pc.randomness]: true
diff --git
a/client/src/views/MyGames.vue
b/client/src/views/MyGames.vue
index
6078394
..
3c2f460
100644
(file)
--- a/
client/src/views/MyGames.vue
+++ b/
client/src/views/MyGames.vue
@@
-58,7
+58,13
@@
export default {
connexionString: ""
};
},
connexionString: ""
};
},
+ watch: {
+ $route: function(to, from) {
+ if (to.path != "/mygames") this.cleanBeforeDestroy();
+ }
+ },
created: function() {
created: function() {
+ window.addEventListener("beforeunload", this.cleanBeforeDestroy);
// Initialize connection
this.connexionString =
params.socketUrl +
// Initialize connection
this.connexionString =
params.socketUrl +
@@
-132,9
+138,13
@@
export default {
});
},
beforeDestroy: function() {
});
},
beforeDestroy: function() {
- this.c
onn.send(JSON.stringify({code: "disconnect"})
);
+ this.c
leanBeforeDestroy(
);
},
methods: {
},
methods: {
+ cleanBeforeDestroy: function() {
+ window.removeEventListener("beforeunload", this.cleanBeforeDestroy);
+ this.conn.send(JSON.stringify({code: "disconnect"}));
+ },
setDisplay: function(type, e) {
this.display = type;
localStorage.setItem("type-myGames", type);
setDisplay: function(type, e) {
this.display = type;
localStorage.setItem("type-myGames", type);
diff --git
a/server/models/Game.js
b/server/models/Game.js
index
8511972
..
aec80a0
100644
(file)
--- a/
server/models/Game.js
+++ b/
server/models/Game.js
@@
-380,7
+380,7
@@
const GameModel =
"FROM Games " +
"WHERE id = " + id;
db.get(query, (err2, ret2) => {
"FROM Games " +
"WHERE id = " + id;
db.get(query, (err2, ret2) => {
- const daysTc = parseInt(ret2.cadence.match(/
\(^[0-9]+\)
/)[0]);
+ const daysTc = parseInt(ret2.cadence.match(/
^[0-9]+
/)[0]);
if (Date.now() - ret.lastPlayed > daysTc * 24 * 3600 * 1000)
finishAndSendQuery();
else cb({ errmsg: "Time not over" });
if (Date.now() - ret.lastPlayed > daysTc * 24 * 3600 * 1000)
finishAndSendQuery();
else cb({ errmsg: "Time not over" });