Implement basic observing logic
[vchess.git] / client / src / views / Hall.vue
index e11e8e1..7b90318 100644 (file)
@@ -8,7 +8,7 @@ main
         p(v-html="infoMessage")
   input#modalNewgame.modal(type="checkbox")
   div(role="dialog" aria-labelledby="titleFenedit")
-    .card.smallpad
+    .card.smallpad(@keyup.enter="newChallenge")
       label#closeNewgame.modal-close(for="modalNewgame")
       fieldset
         label(for="selectVariant") {{ st.tr["Variant"] }}
@@ -117,17 +117,21 @@ export default {
   computed: {
     uniquePlayers: function() {
       // Show e.g. "@nonymous (5)", and do nothing on click on anonymous
-      let anonymous = {id:0, name:"@nonymous", count:0};
-      let playerList = [];
+      let anonymous = {name:"@nonymous", count:0};
+      let playerList = {};
       this.people.forEach(p => {
         if (p.id > 0)
-          playerList.push(p);
+        {
+          // We don't count registered users connections: either they are here or not.
+          if (!playerList[p.id])
+            playerList[p.id] = {name: p.name, count: 0};
+        }
         else
           anonymous.count++;
       });
       if (anonymous.count > 0)
-        playerList.push(anonymous);
-      return playerList;
+        playerList[0] = anonymous;
+      return Object.values(playerList);
     },
   },
   created: function() {
@@ -217,11 +221,7 @@ export default {
       // ==> Moves sent by connected remote player(s) if live game
       let url = "/game/" + g.id;
       if (g.type == "live")
-      {
-        const remotes = g.players.filter(p => this.people.some(pl => pl.sid == p.sid));
-        const rIdx = (remotes.length == 1 ? 0 : Math.floor(Math.random()*2));
-        url += "?rid=" + remotes[rIdx].sid;
-      }
+        url += "?rid=" + g.rid;
       this.$router.push(url);
     },
     getVname: function(vid) {
@@ -280,8 +280,9 @@ export default {
             // Ask identity, challenges and game(s)
             this.st.conn.send(JSON.stringify({code:"askidentity", target:sid}));
             this.st.conn.send(JSON.stringify({code:"askchallenge", target:sid}));
-            this.st.conn.send(JSON.stringify({code:"askgame", target:sid}));
           });
+          // Also ask current games to all playing peers (TODO: some design issue)
+          this.st.conn.send(JSON.stringify({code:"askgames"}));
           break;
         }
         case "askidentity":