X-Git-Url: https://git.auder.net/?p=vchess.git;a=blobdiff_plain;f=client%2Fsrc%2Fviews%2FHall.vue;h=ba3ad41a08fc4958e245fa46c0fd150de4b4e8a1;hp=2e17ceb0665de1a7a9b28f6e881444c6e670abb5;hb=4d64881e3b2dc55fe260a53195f9f3bc2e959fdf;hpb=5578a7bfe37908a6c020f1c394504062e0ad72b5 diff --git a/client/src/views/Hall.vue b/client/src/views/Hall.vue index 2e17ceb0..ba3ad41a 100644 --- a/client/src/views/Hall.vue +++ b/client/src/views/Hall.vue @@ -92,35 +92,36 @@ export default { computed: { uniquePlayers: function() { // Show e.g. "5 @nonymous", and do nothing on click on anonymous - let playerList = [{id:0, name:"@nonymous", count:0}]; + let anonymous = {id:0, name:"@nonymous", count:0}; + let playerList = []; this.players.forEach(p => { if (p.id > 0) playerList.push(p); else - playerList[0].count++; + anonymous.count++; }); + if (anonymous.count > 0) + playerList.push(anonymous); return playerList; }, }, - // TODO: this looks ugly... (use VueX ?!) - watch: { - "st.conn": function() { - this.st.conn.onmessage = this.socketMessageListener; - this.st.conn.onclose = this.socketCloseListener; - // Ask server for for room composition: - this.st.conn.send(JSON.stringify({code:"askplayers"})); - }, - }, created: function() { + // Always add myself to players' list + this.players.push(this.st.user); // TODO: ask server for current corr games (all but mines: names, ID, time control) // also ask for corr challenges - if (!!this.st.conn) - { - this.st.conn.onmessage = this.socketMessageListener; - this.st.conn.onclose = this.socketCloseListener; - // Ask server for for room composition: + // Ask server for for room composition: + const socketOpenListener = () => { this.st.conn.send(JSON.stringify({code:"askplayers"})); - } + }; + this.st.conn.onopen = socketOpenListener; + this.st.conn.onmessage = this.socketMessageListener; + const socketCloseListener = () => { + // connexion is reinitialized in store.js + this.st.conn.addEventListener('message', this.socketMessageListener); + this.st.conn.addEventListener('close', socketCloseListener); + }; + this.st.conn.onclose = socketCloseListener; }, methods: { socketMessageListener: function(msg) { @@ -129,8 +130,6 @@ export default { { case "room": // TODO: receive room composition (sids at least, id + names if registered) - // Add myself to players - this.players.push(this.st.user); // TODO: also receive "askchallenges", "askgames" // * - receive "new game": if live, store locally + redirect to game // * If corr: notify "new game has started", give link, but do not redirect @@ -187,11 +186,6 @@ export default { break; } }, - socketCloseListener: function() { - // connexion is reinitialized in store.js - this.st.conn.addEventListener('message', this.socketMessageListener); - this.st.conn.addEventListener('close', this.socketCloseListener); - }, showGame: function(game) { // NOTE: if we are an observer, the game will be found in main games list // (sent by connected remote players)