updated the send and update sockets methods for player pronouns to pass through a flag when the pronoun is updated from the sockets to stop the update being broadcast again and causing infinite loops of sockets messages being sent. This also simplifys from the previous loop prevention functionality.

This commit is contained in:
Dave 2021-03-16 15:14:51 +00:00
parent 2a6f4cd2a4
commit 6ad1df5a35
1 changed files with 17 additions and 17 deletions

View File

@ -489,35 +489,35 @@ class LiveSession {
* Publish a player pronouns update
* @param player
* @param value
* @param fromSockets
*/
sendPlayerPronouns({ player, value }) {
sendPlayerPronouns({ player, value, fromSockets }) {
//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 (
fromSockets ||
(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,
fromSockets: true
});
}
/**