fix first WebSocket connection
authorRaphaël Jakse <raphael.trivabble@jakse.fr>
Wed, 7 Oct 2020 19:30:04 +0000 (21:30 +0200)
committerRaphaël Jakse <raphael.trivabble@jakse.fr>
Wed, 7 Oct 2020 19:30:04 +0000 (21:30 +0200)
server/trivabble-server.js

index 54666ce127cf240e293d39f9c9ef99baf1b57eb0..b90b55992d6034234ea0a6b7130a52555eec083e 100644 (file)
@@ -446,9 +446,12 @@ function countTiles(rack) {
     return count;
 }
 
-function joinGame(gameNumber) {
+function joinGame(gameNumber, message) {
     if (!gameNumber) {
         gameNumber = newGameId();
+        if (message) {
+            message.gameNumber = gameNumber;
+        }
     }
 
     const game = games[gameNumber] || (games[gameNumber] = new Game());
@@ -719,7 +722,7 @@ function handleCommand(cmdNumber, message, response) {
 
 function handleCommands(message, responseAndType) {
     if (!message.cmds || !message.cmds.length) {
-        const {gameNumber, game} = joinGame(message.gameNumber);
+        const {gameNumber, game} = joinGame(message.gameNumber, message);
 
         writeMessage(responseAndType,
             JSON.stringify({