From 08b309de22a851baa57ca7044339091b947e748c Mon Sep 17 00:00:00 2001 From: ntr Date: Wed, 1 May 2019 19:06:45 +1000 Subject: [PATCH] fix timeouts --- client/src/components/body.component.jsx | 5 ++++- client/src/components/game.component.jsx | 5 ++--- client/src/events.jsx | 4 +++- client/src/socket.jsx | 21 ++++++++++++++++++--- 4 files changed, 27 insertions(+), 8 deletions(-) diff --git a/client/src/components/body.component.jsx b/client/src/components/body.component.jsx index 78d9ea4a..6f393fd7 100644 --- a/client/src/components/body.component.jsx +++ b/client/src/components/body.component.jsx @@ -13,13 +13,16 @@ const addState = connect( if (!game) { ws.clearGameStateTimeout(); + } else { + ws.startGameStateTimeout(game.id); } if (!instance) { ws.clearInstanceStateTimeout(); + } else { + ws.startInstanceStateTimeout(instance.id); } - return { game, instance, account }; } ); diff --git a/client/src/components/game.component.jsx b/client/src/components/game.component.jsx index 5b84db3e..4e92a2cd 100644 --- a/client/src/components/game.component.jsx +++ b/client/src/components/game.component.jsx @@ -50,15 +50,14 @@ function GamePanel(props) { } function backClick() { - quit(); - return sendInstanceState(game.instance); + if (game.phase === 'Finish') sendInstanceState(game.instance); + return quit(); } const header = (
diff --git a/client/src/events.jsx b/client/src/events.jsx index 719971e2..bb7f4b0a 100644 --- a/client/src/events.jsx +++ b/client/src/events.jsx @@ -100,7 +100,9 @@ function registerEvents(store) { const player = v.players.find(p => p.id === account.id); if (player) store.dispatch(actions.setPlayer(player)); - if (!v) ws.clearInstanceStateTimeout(); + if (!v) { + ws.clearInstanceStateTimeout(); + } return store.dispatch(actions.setInstance(v)); } diff --git a/client/src/socket.jsx b/client/src/socket.jsx index e7716740..548e7381 100644 --- a/client/src/socket.jsx +++ b/client/src/socket.jsx @@ -184,14 +184,18 @@ function createSocket(events) { events.setCrypList(cryps); } - let gameStateTimeout; function gameState(response) { const [structName, game] = response; - clearTimeout(gameStateTimeout); - gameStateTimeout = setTimeout(() => sendGameState(game.id), 1000); events.setGame(game); } + let gameStateTimeout; + function startGameStateTimeout(id) { + clearTimeout(gameStateTimeout); + gameStateTimeout = setTimeout(() => sendGameState(id), 1000); + return true; + } + function clearGameStateTimeout() { clearTimeout(gameStateTimeout); } @@ -206,14 +210,23 @@ function createSocket(events) { } let instanceStateTimeout; + function startInstanceStateTimeout(id) { + clearTimeout(instanceStateTimeout); + instanceStateTimeout = setTimeout(() => sendInstanceState(id), 1000); + return true; + } + function instanceState(response) { const [structName, i] = response; clearTimeout(instanceStateTimeout); instanceStateTimeout = setTimeout(() => sendInstanceState(i.id), 1000); + console.log(instanceStateTimeout); events.setInstance(i); + return true; } function clearInstanceStateTimeout() { + console.log('instance state timeout cleared'); clearTimeout(instanceStateTimeout); } @@ -353,6 +366,8 @@ function createSocket(events) { sendVboxCombine, sendVboxDiscard, sendVboxUnequip, + startInstanceStateTimeout, + startGameStateTimeout, connect, }; }