pubsub
This commit is contained in:
@@ -78,7 +78,7 @@ const addState = connect(
|
||||
function Vbox(args) {
|
||||
const {
|
||||
combiner,
|
||||
instance,
|
||||
// instance,
|
||||
itemInfo,
|
||||
player,
|
||||
reclaiming,
|
||||
|
||||
@@ -6,16 +6,6 @@ const { TIMES } = require('./constants');
|
||||
const { getCombatSequence } = require('./utils');
|
||||
|
||||
function registerEvents(store) {
|
||||
|
||||
// timeout handlers
|
||||
store.subscribe(() => {
|
||||
const { game, instance, ws } = store.getState();
|
||||
|
||||
if (!ws) return true;
|
||||
if (!game) ws.clearGameStateTimeout();
|
||||
if (!instance) ws.clearInstanceStateTimeout();
|
||||
});
|
||||
|
||||
function setPing(ping) {
|
||||
store.dispatch(actions.setPing(ping));
|
||||
}
|
||||
@@ -54,11 +44,9 @@ function registerEvents(store) {
|
||||
function setGame(game) {
|
||||
const { game: currentGame, ws } = store.getState();
|
||||
|
||||
if (game) ws.startGameStateTimeout(game.id);
|
||||
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);
|
||||
let id = game.resolved.length - currentGame.resolved.length;
|
||||
return eachSeries(newRes, (r, cb) => {
|
||||
@@ -151,7 +139,6 @@ function registerEvents(store) {
|
||||
store.dispatch(actions.setItemEquip(null));
|
||||
store.dispatch(actions.setItemUnequip(null));
|
||||
store.dispatch(actions.setVboxHighlight([]));
|
||||
store.dispatch(actions.setConstructDeleteId(null));
|
||||
}
|
||||
|
||||
function setAccountInstances(v) {
|
||||
@@ -161,8 +148,6 @@ function registerEvents(store) {
|
||||
function setInstance(v) {
|
||||
const { account, ws, instance } = store.getState();
|
||||
if (v) {
|
||||
ws.startInstanceStateTimeout(v.id);
|
||||
|
||||
const player = v.players.find(p => p.id === account.id);
|
||||
store.dispatch(actions.setPlayer(player));
|
||||
|
||||
|
||||
@@ -136,8 +136,6 @@ function createSocket(events) {
|
||||
// -------------
|
||||
function onAccount(login) {
|
||||
events.setAccount(login);
|
||||
sendAccountConstructs();
|
||||
sendAccountInstances();
|
||||
}
|
||||
|
||||
function onAccountShop(shop) {
|
||||
@@ -146,7 +144,6 @@ function createSocket(events) {
|
||||
|
||||
function onAccountInstances(list) {
|
||||
events.setAccountInstances(list);
|
||||
setTimeout(sendAccountInstances, 5000);
|
||||
}
|
||||
|
||||
function onAccountConstructs(constructs) {
|
||||
@@ -157,36 +154,12 @@ function createSocket(events) {
|
||||
events.setGame(game);
|
||||
}
|
||||
|
||||
let gameStateTimeout;
|
||||
function startGameStateTimeout(id) {
|
||||
clearTimeout(gameStateTimeout);
|
||||
gameStateTimeout = setTimeout(() => sendGameState(id), 1000);
|
||||
return true;
|
||||
}
|
||||
|
||||
function clearGameStateTimeout() {
|
||||
clearTimeout(gameStateTimeout);
|
||||
}
|
||||
|
||||
let instanceStateTimeout;
|
||||
function startInstanceStateTimeout(id) {
|
||||
clearTimeout(instanceStateTimeout);
|
||||
instanceStateTimeout = setTimeout(() => sendInstanceState(id), 1000);
|
||||
return true;
|
||||
}
|
||||
|
||||
function onInstanceState(instance) {
|
||||
events.setInstance(instance);
|
||||
return true;
|
||||
}
|
||||
|
||||
function onOpenInstances(list) {
|
||||
events.setInstanceList(list);
|
||||
return true;
|
||||
}
|
||||
|
||||
function clearInstanceStateTimeout() {
|
||||
clearTimeout(instanceStateTimeout);
|
||||
}
|
||||
|
||||
function onItemInfo(info) {
|
||||
@@ -277,8 +250,6 @@ function createSocket(events) {
|
||||
|
||||
function connect() {
|
||||
if (ws) {
|
||||
clearGameStateTimeout();
|
||||
clearInstanceStateTimeout();
|
||||
clearTimeout(pongTimeout);
|
||||
ws.removeEventListener('open', onOpen);
|
||||
ws.removeEventListener('message', onMessage);
|
||||
@@ -299,8 +270,6 @@ function createSocket(events) {
|
||||
}
|
||||
|
||||
return {
|
||||
clearGameStateTimeout,
|
||||
clearInstanceStateTimeout,
|
||||
sendAccountConstructs,
|
||||
sendAccountInstances,
|
||||
sendGameState,
|
||||
@@ -321,8 +290,6 @@ function createSocket(events) {
|
||||
sendItemInfo,
|
||||
sendMtxApply,
|
||||
sendMtxBuy,
|
||||
startInstanceStateTimeout,
|
||||
startGameStateTimeout,
|
||||
connect,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user