From 1874db290266f1df0a6be5af54c3dedf15a172e6 Mon Sep 17 00:00:00 2001 From: ntr Date: Wed, 17 Apr 2019 12:32:58 +1000 Subject: [PATCH] timeout --- client/src/components/body.component.jsx | 3 +-- client/src/events.jsx | 7 ++++++- client/src/socket.jsx | 8 ++++++++ server/WORKLOG.md | 7 +++++++ 4 files changed, 22 insertions(+), 3 deletions(-) diff --git a/client/src/components/body.component.jsx b/client/src/components/body.component.jsx index 7838b236..99092d42 100644 --- a/client/src/components/body.component.jsx +++ b/client/src/components/body.component.jsx @@ -12,8 +12,7 @@ const addState = connect( const { game, instance, ws, account } = state; if (!game) { - console.log('clear gs interval'); - // ws.clearGameStateInterval(); + ws.clearGameStateTimeout(); } return { game, instance, account }; diff --git a/client/src/events.jsx b/client/src/events.jsx index 32927d6e..14311ece 100644 --- a/client/src/events.jsx +++ b/client/src/events.jsx @@ -18,9 +18,11 @@ function registerEvents(store) { } function setGame(game) { - const { game: currentGame } = store.getState(); + const { game: currentGame, ws } = store.getState(); if (game && currentGame) { if (game.resolved.length !== currentGame.resolved.length) { + // stop fetching the game state til animations are done + ws.clearGameStateTimeout(); const newRes = game.resolved.slice(currentGame.resolved.length); return eachSeries(newRes, (r, cb) => { if (['Disable', 'TargetKo'].includes(r.event[0])) return cb(); @@ -29,7 +31,10 @@ function registerEvents(store) { }, err => { if (err) return console.error(err); store.dispatch(actions.setResolution(null)); + // update the game store.dispatch(actions.setGame(game)); + // get the latest state and restart polling + ws.sendGameState(currentGame.id); return true; }); } diff --git a/client/src/socket.jsx b/client/src/socket.jsx index cac81aac..e9208ffe 100644 --- a/client/src/socket.jsx +++ b/client/src/socket.jsx @@ -174,11 +174,18 @@ function createSocket(events) { events.setCrypList(cryps); } + let gameStateTimeout; function gameState(response) { const [structName, game] = response; + clearInterval(gameStateTimeout); + gameStateTimeout = setTimeout(() => sendGameState(game.id), 1000); events.setGame(game); } + function clearGameStateTimeout() { + clearTimeout(gameStateTimeout); + } + function crypSpawn(response) { const [structName, cryp] = response; } @@ -289,6 +296,7 @@ function createSocket(events) { } return { + clearGameStateTimeout, sendAccountLogin, sendAccountCreate, sendAccountDemo, diff --git a/server/WORKLOG.md b/server/WORKLOG.md index d4f755a8..db0edbf6 100644 --- a/server/WORKLOG.md +++ b/server/WORKLOG.md @@ -25,6 +25,13 @@ * resolve animations + effects *SERVER* +authentication endpoint + hit /auth with un/pw or token + invalidate previous token + generate new token and return + attach token to websocket + ez + consolidate buffs debuffs and disables no more red/blue