diff --git a/CHANGELOG.md b/CHANGELOG.md index 9521e7f..ddd75e4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Release Notes +## Version 2.0.4 +- fix bug with live sessions that contain travelers from a different set +- fix server channel cleanup + +--- + ## Version 2.0.3 - load roles that belong to different editions (like travelers) from gamestate - close session when missing custom roles and open edition modal diff --git a/server/index.js b/server/index.js index d6bd73a..3bfb9b3 100644 --- a/server/index.js +++ b/server/index.js @@ -113,14 +113,6 @@ wss.on("connection", function connection(ws, req) { // start ping pong ws.ping(noop); ws.on("pong", heartbeat); - // remove client from channels on close - ws.on("close", () => { - const index = channels[ws.channel].indexOf(ws); - if (index >= 0) { - channels[ws.channel].splice(index, 1); - } - if (!channels[ws.channel].length) delete channels[ws.channel]; - }); // handle message ws.on("message", function incoming(data) { metrics.messages_incoming.inc(); @@ -180,6 +172,7 @@ wss.on("connection", function connection(ws, req) { // start ping interval timer const interval = setInterval(function ping() { + // ping each client wss.clients.forEach(function each(ws) { if (ws.isAlive === false) { metrics.connection_terminated_timeout.inc(); @@ -189,6 +182,20 @@ const interval = setInterval(function ping() { ws.pingStart = new Date().getTime(); ws.ping(noop); }); + // clean up empty channels + for (let channel in channels) { + if ( + !channels[channel].length || + !channels[channel].some( + ws => + ws && + (ws.readyState === WebSocket.OPEN || + ws.readyState === WebSocket.CONNECTING) + ) + ) { + delete channels[channel]; + } + } }, PING_INTERVAL); // handle server shutdown diff --git a/src/store/persistence.js b/src/store/persistence.js index 59f4103..715d552 100644 --- a/src/store/persistence.js +++ b/src/store/persistence.js @@ -21,8 +21,7 @@ module.exports = store => { JSON.parse(localStorage.bluffs).forEach((role, index) => { store.commit("players/setBluff", { index, - role: - store.state.roles.get(role) || {} + role: store.state.roles.get(role) || {} }); }); } diff --git a/src/store/socket.js b/src/store/socket.js index 4b87f11..b018833 100644 --- a/src/store/socket.js +++ b/src/store/socket.js @@ -287,12 +287,16 @@ class LiveSession { }); // roles are special, because of travelers if (roleId && player.role.id !== roleId) { - const role = this._store.state.roles.get(roleId); - this._store.commit("players/update", { - player, - property: "role", - value: role - }); + const role = + this._store.state.roles.get(roleId) || + this._store.getters.rolesJSONbyId.get(roleId); + if (role) { + this._store.commit("players/update", { + player, + property: "role", + value: role + }); + } } else if (!roleId && player.role.team === "traveler") { this._store.commit("players/update", { player,