timeout
This commit is contained in:
@@ -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 };
|
||||
|
||||
@@ -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;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user