diff --git a/CHANGELOG.md b/CHANGELOG.md index 70072c5..b4525b6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Release Notes +### Version 2.9.2 +- fix issue where a player and storyteller updating the same players pronouns at around the same time causes an infinite loop disconnecting the session. + +--- ### Version 2.9.1 - added [nomination log indicator](https://fontawesome.com/icons/book-dead). When a nomination log [v] is available, the number of currently visible entries is displayed. Clicking the indicator can reveal/hide the nomination log. - fix gamestate JSON not showing (custom) roles and failing to load states with custom scripts properly diff --git a/src/store/modules/players.js b/src/store/modules/players.js index 30d4d2b..9a7ab0f 100644 --- a/src/store/modules/players.js +++ b/src/store/modules/players.js @@ -102,6 +102,14 @@ const mutations = { set(state, players = []) { state.players = players; }, + /** + The update mutation also has a property for isFromSockets + this property can be addded to payload object for any mutations + then can be used to prevent infinite loops when a property is + able to be set from multiple different session on websockets. + An example of this is in the sendPlayerPronouns and _updatePlayerPronouns + in socket.js. + */ update(state, { player, property, value }) { const index = state.players.indexOf(player); if (index >= 0) { diff --git a/src/store/socket.js b/src/store/socket.js index a69ab24..326bb8d 100644 --- a/src/store/socket.js +++ b/src/store/socket.js @@ -489,35 +489,35 @@ class LiveSession { * Publish a player pronouns update * @param player * @param value + * @param isFromSockets */ - sendPlayerPronouns({ player, value }) { + sendPlayerPronouns({ player, value, isFromSockets }) { //send pronoun only for the seated player or storyteller - if (this._isSpectator && this._store.state.session.playerId !== player.id) + //Do not re-send pronoun data for an update that was recieved from the sockets layer + if ( + isFromSockets || + (this._isSpectator && this._store.state.session.playerId !== player.id) + ) return; const index = this._store.state.players.players.indexOf(player); - this._send("pronouns", [index, value, !this._isSpectator]); + this._send("pronouns", [index, value]); } /** - * Update a pronouns based on incoming data. Player only. + * Update a pronouns based on incoming data. * @param index * @param value - * @param fromSt * @private */ - _updatePlayerPronouns([index, value, fromST]) { + _updatePlayerPronouns([index, value]) { const player = this._store.state.players.players[index]; - if ( - player && - (fromST || this._store.state.session.playerId !== player.id) && - player.pronouns !== value - ) { - this._store.commit("players/update", { - player, - property: "pronouns", - value - }); - } + + this._store.commit("players/update", { + player, + property: "pronouns", + value, + isFromSockets: true + }); } /**