Pass result to Hall after a game ends
[vchess.git] / client / src / views / Game.vue
index a5db146..062990d 100644 (file)
@@ -1,7 +1,7 @@
 <template lang="pug">
 main
   input#modalChat.modal(type="checkbox" @click="resetChatColor()")
-  div#chatWrap(role="dialog" data-checkbox="modalChat" aria-labelledby="inputChat")
+  div#chatWrap(role="dialog" data-checkbox="modalChat")
     #chat.card
       label.modal-close(for="modalChat")
       #participants
@@ -134,7 +134,11 @@ export default {
       if (!!this.conn && this.conn.readyState == 1) //1 == OPEN state
         callback();
       else //socket not ready yet (initial loading)
-        this.conn.onopen = callback;
+      {
+        // NOTE: it's important to call callback without arguments,
+        // otherwise first arg is Websocket object and loadGame fails.
+        this.conn.onopen = () => { return callback() };
+      }
     };
     if (!this.gameRef.rid) //game stored locally or on server
       this.loadGame(null, () => socketInit(this.roomInit));
@@ -540,7 +544,8 @@ export default {
         });
         if (this.repeat[repIdx] >= 3)
           this.drawOffer = "threerep";
-        callback();
+        if (!!callback)
+          callback();
       };
       if (!!game)
         return afterRetrieval(game);
@@ -681,6 +686,8 @@ export default {
       {
         GameStorage.update(this.gameRef.id,
           {score: score, scoreMsg: scoreMsg});
+        // Notify the score to main Hall. TODO: only one player (currently double send)
+        this.send("result", {gid:this.game.id, score:score});
       }
     },
   },
@@ -738,7 +745,7 @@ export default {
 
 #chat
   padding-top: 20px
-  max-width: 600px
+  max-width: 767px
   border: none;
 
 #chatBtn