From cb45da4de49663a567bb2271e756cffd67b45163 Mon Sep 17 00:00:00 2001 From: Dave Date: Sat, 16 Jan 2021 23:56:10 +0000 Subject: [PATCH 01/97] add pronoun property to player in state --- src/store/modules/players.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/store/modules/players.js b/src/store/modules/players.js index ffec7c3..83bd351 100644 --- a/src/store/modules/players.js +++ b/src/store/modules/players.js @@ -4,7 +4,8 @@ const NEWPLAYER = { role: {}, reminders: [], isVoteless: false, - isDead: false + isDead: false, + pronouns: "" }; const state = () => ({ From ccd40ccc993f60ed04d3d5908edde93a9c386f43 Mon Sep 17 00:00:00 2001 From: Dave Date: Sun, 17 Jan 2021 00:18:26 +0000 Subject: [PATCH 02/97] adding method and dialog to player vue to update player pronoun in state. --- src/components/Player.vue | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/components/Player.vue b/src/components/Player.vue index 91f8f5a..eeb43fe 100644 --- a/src/components/Player.vue +++ b/src/components/Player.vue @@ -112,6 +112,9 @@
  • Rename
  • +
  • + Change Pronouns +
  • Nomination @@ -230,6 +233,13 @@ export default { handleEmojis: text => text.replace(/:([^: ]+?):/g, "").replace(/ •/g, "\n•") }, methods: { + changePronoun() { + if (this.session.isSpectator) return; + const pronoun = + prompt("Player preffered pronouns", this.player.pronoun) || + this.player.pronoun; + this.updatePlayer("pronoun", pronoun, true); + }, toggleStatus() { if (this.grimoire.isPublic) { if (!this.player.isDead) { From 5bafa94a1a31e4aaceb4399a6ab8427b94b0b90c Mon Sep 17 00:00:00 2001 From: Dave Date: Sun, 17 Jan 2021 00:36:49 +0000 Subject: [PATCH 03/97] make change pronoun menu option appear for both story tellers and the seated player --- src/components/Player.vue | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/components/Player.vue b/src/components/Player.vue index eeb43fe..5b3df03 100644 --- a/src/components/Player.vue +++ b/src/components/Player.vue @@ -112,9 +112,6 @@
  • Rename
  • -
  • - Change Pronouns -
  • Nomination @@ -153,6 +150,12 @@
  • +
  • + Change Pronouns +
  • From 37194a390fb0dd2c981145a520cfa018281dce17 Mon Sep 17 00:00:00 2001 From: Dave Date: Sun, 17 Jan 2021 00:50:07 +0000 Subject: [PATCH 04/97] adding fonat awesome idon to menu option for change pronouns --- src/components/Player.vue | 2 +- src/main.js | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/components/Player.vue b/src/components/Player.vue index 5b3df03..ddb2e2c 100644 --- a/src/components/Player.vue +++ b/src/components/Player.vue @@ -154,7 +154,7 @@ @click="changePronoun" v-if="!session.isSpectator || player.id === session.playerId" > - Change Pronouns + Change Pronouns diff --git a/src/main.js b/src/main.js index a89be35..f728114 100644 --- a/src/main.js +++ b/src/main.js @@ -46,7 +46,8 @@ const faIcons = [ "Users", "VolumeUp", "VolumeMute", - "VoteYea" + "VoteYea", + "Transgender" ]; const fabIcons = ["Github", "Discord"]; library.add( From d8df724907043b42e4602f74f9073bbc3bb1f4c0 Mon Sep 17 00:00:00 2001 From: Dave Date: Sun, 17 Jan 2021 23:20:59 +0000 Subject: [PATCH 05/97] created css for pronoun tooltips --- src/components/Player.vue | 49 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/src/components/Player.vue b/src/components/Player.vue index ddb2e2c..f84f3be 100644 --- a/src/components/Player.vue +++ b/src/components/Player.vue @@ -104,6 +104,9 @@ :class="{ active: isMenuOpen }" > {{ player.name }} +
    + {{ player.pronoun }} +
    @@ -641,6 +644,7 @@ li.move:not(.from) .player .overlay svg.move { /***** Player name *****/ .player > .name { text-align: center; + justify-content: center; font-size: 120%; line-height: 120%; cursor: pointer; @@ -652,13 +656,56 @@ li.move:not(.from) .player .overlay svg.move { top: 5px; box-shadow: 0 0 5px black; text-overflow: ellipsis; - overflow: hidden; padding: 0 4px; #townsquare:not(.spectator) &:hover, &.active { color: red; } + + .pronouns { + display: inline-block; + position: absolute; + padding: 5px 10px; + left: 120%; + z-index: 25; + font-size: 80%; + background: rgba(0, 0, 0, 0.5); + border-radius: 10px; + border: 3px solid black; + filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.5)); + text-align: left; + justify-items: center; + align-content: center; + align-items: center; + pointer-events: none; + opacity: 0; + transition: opacity 200ms ease-in-out; + + &:before { + content: " "; + border: 10px solid transparent; + width: 0; + height: 0; + border-right-color: black; + position: absolute; + margin-right: 2px; + right: 100%; + } + } + + &:hover { + .pronouns { + opacity: 1; + } + } + + #townsquare:not(.spectator) &:hover, + &.active { + .pronouns { + color: white; + } + } } .player.dead > .name { From 03731bc88719d360d78ff0abc269a5f83fd6b44b Mon Sep 17 00:00:00 2001 From: Dave Date: Sun, 17 Jan 2021 23:41:44 +0000 Subject: [PATCH 06/97] tweaking position of tooltip --- src/components/Player.vue | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/components/Player.vue b/src/components/Player.vue index f84f3be..c89b9cc 100644 --- a/src/components/Player.vue +++ b/src/components/Player.vue @@ -664,11 +664,10 @@ li.move:not(.from) .player .overlay svg.move { } .pronouns { - display: inline-block; + display: inline-flex; position: absolute; padding: 5px 10px; - left: 120%; - z-index: 25; + left: 110%; font-size: 80%; background: rgba(0, 0, 0, 0.5); border-radius: 10px; From 48eab1fa8c2deca157030cd8b187ea9234b7876a Mon Sep 17 00:00:00 2001 From: Dave Date: Mon, 18 Jan 2021 14:02:03 +0000 Subject: [PATCH 07/97] getting player pronouns to be synced over sockets layer --- src/components/Player.vue | 1 + src/store/socket.js | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/components/Player.vue b/src/components/Player.vue index c89b9cc..7d73ea7 100644 --- a/src/components/Player.vue +++ b/src/components/Player.vue @@ -245,6 +245,7 @@ export default { prompt("Player preffered pronouns", this.player.pronoun) || this.player.pronoun; this.updatePlayer("pronoun", pronoun, true); + this.$emit("trigger", ["updatePlayer", this.player, "pronoun", pronoun]); }, toggleStatus() { if (this.grimoire.isPublic) { diff --git a/src/store/socket.js b/src/store/socket.js index 4da4a7c..9b368ec 100644 --- a/src/store/socket.js +++ b/src/store/socket.js @@ -222,6 +222,7 @@ class LiveSession { id: player.id, isDead: player.isDead, isVoteless: player.isVoteless, + pronoun: player.pronoun, ...(player.role && player.role.team === "traveler" ? { roleId: player.role.id } : {}) @@ -279,7 +280,7 @@ class LiveSession { const player = players[x]; const { roleId } = state; // update relevant properties - ["name", "id", "isDead", "isVoteless"].forEach(property => { + ["name", "id", "isDead", "isVoteless", "pronoun"].forEach(property => { const value = state[property]; if (player[property] !== value) { this._store.commit("players/update", { player, property, value }); From 30ca53dde3d57c148ecab69eab922c2976c0f4dd Mon Sep 17 00:00:00 2001 From: Dave Date: Mon, 18 Jan 2021 19:40:14 +0000 Subject: [PATCH 08/97] make pronouns tooltip appear on the left on the right hand side of the circle. --- src/components/TownSquare.vue | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/components/TownSquare.vue b/src/components/TownSquare.vue index 684c386..c1aead5 100644 --- a/src/components/TownSquare.vue +++ b/src/components/TownSquare.vue @@ -292,6 +292,17 @@ export default { left: 100%; } } + //show pronouns tooltip on the left + .pronouns { + right: 120%; + left: auto; + &:before { + border-right-color: transparent; + border-left-color: black; + right: auto; + left: 100%; + } + } } @else { // second half of players z-index: $i - 1; From b645c1312daac330777e5e9e140c3914a95bfc8e Mon Sep 17 00:00:00 2001 From: Dave Date: Mon, 18 Jan 2021 19:42:28 +0000 Subject: [PATCH 09/97] fixing correct distance between tooltip and name when displaying on the left --- src/components/TownSquare.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/TownSquare.vue b/src/components/TownSquare.vue index c1aead5..2849327 100644 --- a/src/components/TownSquare.vue +++ b/src/components/TownSquare.vue @@ -294,7 +294,7 @@ export default { } //show pronouns tooltip on the left .pronouns { - right: 120%; + right: 110%; left: auto; &:before { border-right-color: transparent; From 18e5b865184b8868c51cef505fa114e7385d2e13 Mon Sep 17 00:00:00 2001 From: Dave Date: Mon, 25 Jan 2021 21:15:45 +0000 Subject: [PATCH 10/97] makeing option to change pronouns only show for currently seated player --- src/components/Player.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/Player.vue b/src/components/Player.vue index 7d73ea7..3a3e864 100644 --- a/src/components/Player.vue +++ b/src/components/Player.vue @@ -155,7 +155,7 @@
  • Change Pronouns
  • From e60def422650b6f8c15df2ba9413116973baa60a Mon Sep 17 00:00:00 2001 From: Dave Date: Wed, 27 Jan 2021 19:41:28 +0000 Subject: [PATCH 11/97] creating an action to store player pronoun in state and persist the data in local storage --- src/components/Player.vue | 12 ++++++------ src/store/modules/players.js | 6 ++++++ src/store/persistence.js | 1 + 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/components/Player.vue b/src/components/Player.vue index 3a3e864..4e5fdf1 100644 --- a/src/components/Player.vue +++ b/src/components/Player.vue @@ -240,12 +240,12 @@ export default { }, methods: { changePronoun() { - if (this.session.isSpectator) return; - const pronoun = - prompt("Player preffered pronouns", this.player.pronoun) || - this.player.pronoun; - this.updatePlayer("pronoun", pronoun, true); - this.$emit("trigger", ["updatePlayer", this.player, "pronoun", pronoun]); + const pronoun = prompt("Player preffered pronouns", this.player.pronoun); + this.$store.commit("players/setPronoun", { + player: this.player, + pronoun + }); + this.isMenuOpen = false; }, toggleStatus() { if (this.grimoire.isPublic) { diff --git a/src/store/modules/players.js b/src/store/modules/players.js index 83bd351..a04879b 100644 --- a/src/store/modules/players.js +++ b/src/store/modules/players.js @@ -107,6 +107,12 @@ const mutations = { state.players[index][property] = value; } }, + setPronoun(state, { player, pronoun }) { + const index = state.players.indexOf(player); + if (index >= 0) { + state.players[index].pronoun = pronoun; + } + }, add(state, name) { state.players.push({ ...NEWPLAYER, diff --git a/src/store/persistence.js b/src/store/persistence.js index fbd22ab..a0282fe 100644 --- a/src/store/persistence.js +++ b/src/store/persistence.js @@ -122,6 +122,7 @@ module.exports = store => { case "players/set": case "players/swap": case "players/move": + case "players/setPronoun": if (state.players.players.length) { localStorage.setItem( "players", From 60fab2efe05a1b9564804cb28f0fed1577af7be3 Mon Sep 17 00:00:00 2001 From: Dave Date: Wed, 27 Jan 2021 20:33:38 +0000 Subject: [PATCH 12/97] adding code to transmit changes to player pronoun --- src/store/socket.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/store/socket.js b/src/store/socket.js index 3c29e1c..32e5b02 100644 --- a/src/store/socket.js +++ b/src/store/socket.js @@ -170,6 +170,9 @@ class LiveSession { case "bye": this._handleBye(params); break; + case "pronoun": + this._updatePlayerPronoun(params); + break; } } @@ -461,6 +464,24 @@ class LiveSession { } } + sendPlayerPronoun({ player, pronoun }) { + if (!this._isSpectator) return; + const index = this._store.state.players.players.indexOf(player); + this._send("pronoun", { index, pronoun }); + } + + /** + * Update a pronoun based on incoming data. Player only. + * @param index + * @param pronoun + * @private + */ + _updatePlayerPronoun({ index, pronoun }) { + const player = this._store.state.players.players[index]; + if (!player) return; + this._store.commit("players/setPronoun", { player, pronoun }); + } + /** * Handle a ping message by another player / storyteller * @param isSpectator @@ -789,6 +810,9 @@ export default store => { case "players/update": session.sendPlayer(payload); break; + case "players/setPronoun": + session.sendPlayerPronoun(payload); + break; } }); From ea0e6d2d72b5532f130e521a82e43e1118806ac0 Mon Sep 17 00:00:00 2001 From: Steffen Date: Wed, 27 Jan 2021 22:05:32 +0100 Subject: [PATCH 13/97] ping changed to direct message --- src/store/socket.js | 75 +++++++++++++++++++++++---------------------- 1 file changed, 39 insertions(+), 36 deletions(-) diff --git a/src/store/socket.js b/src/store/socket.js index 925c326..bdab4c1 100644 --- a/src/store/socket.js +++ b/src/store/socket.js @@ -80,12 +80,14 @@ class LiveSession { * @private */ _ping() { - this._send("ping", [ - this._isSpectator, - this._store.state.session.playerId, - "latency" - ]); this._handlePing(); + if (this._isSpectator) { + this._send("direct", { + host: [this._store.state.session.playerId, "latency"] + }); + } else { + this._send("ping", [Object.keys(this._players).length, "latency"]); + } clearTimeout(this._pingTimer); this._pingTimer = setTimeout(this._ping.bind(this), this._pingInterval); } @@ -462,41 +464,37 @@ class LiveSession { /** * Handle a ping message by another player / storyteller - * @param isSpectator - * @param playerId - * @param timestamp + * @param playerIdOrCount + * @param latency * @private */ - _handlePing([isSpectator, playerId, latency] = []) { + _handlePing([playerIdOrCount, latency] = []) { const now = new Date().getTime(); - // remove players that haven't sent a ping in twice the timespan - for (let player in this._players) { - if (now - this._players[player] > this._pingInterval * 2) { - delete this._players[player]; - delete this._pings[player]; + if (!this._isSpectator) { + // remove players that haven't sent a ping in twice the timespan + for (let player in this._players) { + if (now - this._players[player] > this._pingInterval * 2) { + delete this._players[player]; + delete this._pings[player]; + } } - } - // remove claimed seats from players that are no longer connected - this._store.state.players.players.forEach(player => { - if (!this._isSpectator && player.id && !this._players[player.id]) { - this._store.commit("players/update", { - player, - property: "id", - value: "" - }); - } - }); - // store new player data - if (playerId) { - this._players[playerId] = now; - const ping = parseInt(latency, 10); - if (ping && ping > 0 && ping < 30 * 1000) { - if (this._isSpectator && !isSpectator) { - // ping to ST - this._store.commit("session/setPing", ping); - } else if (!this._isSpectator) { + // remove claimed seats from players that are no longer connected + this._store.state.players.players.forEach(player => { + if (player.id && !this._players[player.id]) { + this._store.commit("players/update", { + player, + property: "id", + value: "" + }); + } + }); + // store new player data + if (playerIdOrCount) { + this._players[playerIdOrCount] = now; + const ping = parseInt(latency, 10); + if (ping && ping > 0 && ping < 30 * 1000) { // ping to Players - this._pings[playerId] = ping; + this._pings[playerIdOrCount] = ping; const pings = Object.values(this._pings); this._store.commit( "session/setPing", @@ -504,10 +502,15 @@ class LiveSession { ); } } + } else if (latency) { + // ping to ST + this._store.commit("session/setPing", parseInt(latency, 10)); } this._store.commit( "session/setPlayerCount", - Object.keys(this._players).length + this._isSpectator + ? playerIdOrCount || 0 + : Object.keys(this._players).length ); } From ec05b07329b8b269e9f5ab15f2840b2ff2fabff4 Mon Sep 17 00:00:00 2001 From: Dave Date: Wed, 27 Jan 2021 22:36:42 +0000 Subject: [PATCH 14/97] adding additional validation to changePronoun method in player.vue --- src/components/Player.vue | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/components/Player.vue b/src/components/Player.vue index 4e5fdf1..8c777f2 100644 --- a/src/components/Player.vue +++ b/src/components/Player.vue @@ -240,6 +240,8 @@ export default { }, methods: { changePronoun() { + if (!this.session.isSpectator || this.player.id !== this.session.playerId) + return; const pronoun = prompt("Player preffered pronouns", this.player.pronoun); this.$store.commit("players/setPronoun", { player: this.player, From fafbb3c23fa50453910d10d16625d8d4092c1fd5 Mon Sep 17 00:00:00 2001 From: Dave Date: Wed, 27 Jan 2021 23:22:56 +0000 Subject: [PATCH 15/97] adding a regex in to the join session method in Menu.vue, to check if a townsquare domain has been entered in to join dialog, if it finds one it will get the session id from the # query string instead of just taking the value directly from the dialog. --- src/components/Menu.vue | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/components/Menu.vue b/src/components/Menu.vue index 79715a5..8ed2507 100644 --- a/src/components/Menu.vue +++ b/src/components/Menu.vue @@ -255,9 +255,16 @@ export default { }, joinSession() { if (this.session.sessionId) return this.leaveSession(); - const sessionId = prompt( + let sessionId = prompt( "Enter the channel number / name of the session you want to join" ); + if ( + sessionId.match( + /^https?:\/\/([^.]+\.github\.io|localhost|clocktower\.online|eddbra1nprivatetownsquare\.xyz)/i + ) + ) { + sessionId = sessionId.split("#")[1]; + } if (sessionId) { this.$store.commit("session/clearVoteHistory"); this.$store.commit("session/setSpectator", true); From 724a218b6f0a85cc127eb3a98117df9ed6385b64 Mon Sep 17 00:00:00 2001 From: Dave Date: Fri, 29 Jan 2021 14:55:19 +0000 Subject: [PATCH 16/97] simplified the regex on joining a session to only look for anything starting with http(s):// and parseing out the code. --- src/components/Menu.vue | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/components/Menu.vue b/src/components/Menu.vue index 8ed2507..eb039d9 100644 --- a/src/components/Menu.vue +++ b/src/components/Menu.vue @@ -258,11 +258,7 @@ export default { let sessionId = prompt( "Enter the channel number / name of the session you want to join" ); - if ( - sessionId.match( - /^https?:\/\/([^.]+\.github\.io|localhost|clocktower\.online|eddbra1nprivatetownsquare\.xyz)/i - ) - ) { + if (sessionId.match(/^https?:\/\//i)) { sessionId = sessionId.split("#")[1]; } if (sessionId) { From 4d33e7dda99d98776ebe0211d9548b2ecfcbbb1b Mon Sep 17 00:00:00 2001 From: Steffen Date: Fri, 29 Jan 2021 21:54:27 +0100 Subject: [PATCH 17/97] optimized ping and gamestate messages --- server/index.js | 73 ++++++++++++++++++++++++++-------------- src/store/socket.js | 82 +++++++++++++++++++++++++++++---------------- vue.config.js | 2 ++ 3 files changed, 104 insertions(+), 53 deletions(-) diff --git a/server/index.js b/server/index.js index 0a82715..2a8ebc1 100644 --- a/server/index.js +++ b/server/index.js @@ -150,40 +150,63 @@ wss.on("connection", function connection(ws, req) { .substr(1) .split(",", 1) .pop(); - // don't log ping messages - if (messageType !== '"ping"') { - console.log(new Date(), wss.clients.size, ws.channel, ws.playerId, data); - } - // handle "direct" messages differently - if (messageType === '"direct"') { - try { - const dataToPlayer = JSON.parse(data)[1]; + switch (messageType) { + case '"ping"': + // ping messages will only be sent host -> all or all -> host channels[ws.channel].forEach(function each(client) { if ( client !== ws && client.readyState === WebSocket.OPEN && - dataToPlayer[client.playerId] + (ws.playerId === "host" || client.playerId === "host") ) { - client.send(JSON.stringify(dataToPlayer[client.playerId])); + client.send( + data.replace(/latency/, (client.latency || 0) + (ws.latency || 0)) + ); metrics.messages_outgoing.inc(); } }); - } catch (e) { - console.log("error parsing direct message JSON", e); - } - } else { - // all other messages - channels[ws.channel].forEach(function each(client) { - if (client !== ws && client.readyState === WebSocket.OPEN) { - // inject latency between both clients if ping message - if (messageType === '"ping"' && client.latency && ws.latency) { - client.send(data.replace(/latency/, client.latency + ws.latency)); - } else { - client.send(data); - } - metrics.messages_outgoing.inc(); + break; + case '"direct"': + // handle "direct" messages differently + console.log( + new Date(), + wss.clients.size, + ws.channel, + ws.playerId, + data + ); + try { + const dataToPlayer = JSON.parse(data)[1]; + channels[ws.channel].forEach(function each(client) { + if ( + client !== ws && + client.readyState === WebSocket.OPEN && + dataToPlayer[client.playerId] + ) { + client.send(JSON.stringify(dataToPlayer[client.playerId])); + metrics.messages_outgoing.inc(); + } + }); + } catch (e) { + console.log("error parsing direct message JSON", e); } - }); + break; + default: + // all other messages + console.log( + new Date(), + wss.clients.size, + ws.channel, + ws.playerId, + data + ); + channels[ws.channel].forEach(function each(client) { + if (client !== ws && client.readyState === WebSocket.OPEN) { + client.send(data); + metrics.messages_outgoing.inc(); + } + }); + break; } }); }); diff --git a/src/store/socket.js b/src/store/socket.js index bdab4c1..be5175e 100644 --- a/src/store/socket.js +++ b/src/store/socket.js @@ -62,13 +62,33 @@ class LiveSession { } } + /** + * Send a message directly to a single playerId, if provided. + * Otherwise broadcast it. + * @param playerId player ID or "host", optional + * @param command + * @param params + * @private + */ + _sendDirect(playerId, command, params) { + if (playerId) { + this._send("direct", { [playerId]: [command, params] }); + } else { + this._send(command, params); + } + } + /** * Open event handler for socket. * @private */ _onOpen() { if (this._isSpectator) { - this._send("req", "gs"); + this._sendDirect( + "host", + "getGamestate", + this._store.state.session.playerId + ); } else { this.sendGamestate(); } @@ -81,13 +101,12 @@ class LiveSession { */ _ping() { this._handlePing(); - if (this._isSpectator) { - this._send("direct", { - host: [this._store.state.session.playerId, "latency"] - }); - } else { - this._send("ping", [Object.keys(this._players).length, "latency"]); - } + this._send("ping", [ + this._isSpectator + ? this._store.state.session.playerId + : Object.keys(this._players).length, + "latency" + ]); clearTimeout(this._pingTimer); this._pingTimer = setTimeout(this._ping.bind(this), this._pingInterval); } @@ -105,10 +124,8 @@ class LiveSession { console.log("unsupported socket message", data); } switch (command) { - case "req": - if (params === "gs") { - this.sendGamestate(); - } + case "getGamestate": + this.sendGamestate(params); break; case "edition": this._updateEdition(params); @@ -206,7 +223,9 @@ class LiveSession { this._store.commit("session/setReconnecting", false); clearTimeout(this._reconnectTimer); if (this._socket) { - this._send("bye", this._store.state.session.playerId); + if (this._isSpectator) { + this._sendDirect("host", "bye", this._store.state.session.playerId); + } this._socket.close(1000); this._socket = null; } @@ -215,9 +234,10 @@ class LiveSession { /** * Publish the current gamestate. * Optional param to reduce traffic. (send only player data) + * @param playerId * @param isLightweight */ - sendGamestate(isLightweight = false) { + sendGamestate(playerId = "", isLightweight = false) { if (this._isSpectator) return; this._gamestate = this._store.state.players.players.map(player => ({ name: player.name, @@ -229,12 +249,15 @@ class LiveSession { : {}) })); if (isLightweight) { - this._send("gs", { gamestate: this._gamestate, isLightweight }); + this._sendDirect(playerId, "gs", { + gamestate: this._gamestate, + isLightweight + }); } else { const { session, grimoire } = this._store.state; const { fabled } = this._store.state.players; - this.sendEdition(); - this._send("gs", { + this.sendEdition(playerId); + this._sendDirect(playerId, "gs", { gamestate: this._gamestate, isNight: grimoire.isNight, nomination: session.nomination, @@ -324,15 +347,16 @@ class LiveSession { /** * Publish an edition update. ST only + * @param playerId */ - sendEdition() { + sendEdition(playerId = "") { if (this._isSpectator) return; const { edition } = this._store.state; let roles; if (!edition.isOfficial) { roles = Array.from(this._store.state.roles.keys()); } - this._send("edition", { + this._sendDirect(playerId, "edition", { edition: edition.isOfficial ? { id: edition.id } : Object.assign({}, edition, { logo: "" }), @@ -468,7 +492,7 @@ class LiveSession { * @param latency * @private */ - _handlePing([playerIdOrCount, latency] = []) { + _handlePing([playerIdOrCount = 0, latency] = []) { const now = new Date().getTime(); if (!this._isSpectator) { // remove players that haven't sent a ping in twice the timespan @@ -506,20 +530,22 @@ class LiveSession { // ping to ST this._store.commit("session/setPing", parseInt(latency, 10)); } - this._store.commit( - "session/setPlayerCount", - this._isSpectator - ? playerIdOrCount || 0 - : Object.keys(this._players).length - ); + // update player count + if (!this._isSpectator || playerIdOrCount) { + this._store.commit( + "session/setPlayerCount", + this._isSpectator ? playerIdOrCount : Object.keys(this._players).length + ); + } } /** - * Handle a player leaving the sessions + * Handle a player leaving the sessions. ST only * @param playerId * @private */ _handleBye(playerId) { + if (this._isSpectator) return; delete this._players[playerId]; this._store.commit( "session/setPlayerCount", @@ -786,7 +812,7 @@ export default store => { case "players/clear": case "players/remove": case "players/add": - session.sendGamestate(true); + session.sendGamestate("", true); break; case "players/update": session.sendPlayer(payload); diff --git a/vue.config.js b/vue.config.js index d61bd25..c18495d 100644 --- a/vue.config.js +++ b/vue.config.js @@ -1,3 +1,5 @@ module.exports = { + // if the app is supposed to run on Github Pages in a subfolder, use the following config: + // publicPath: process.env.NODE_ENV === "production" ? "/townsquare/" : "/" publicPath: process.env.NODE_ENV === "production" ? "/" : "/" }; From 7f0d60c272b3454b68d5866e8e249c95ffea5fff Mon Sep 17 00:00:00 2001 From: Dave Date: Sat, 30 Jan 2021 12:50:09 +0000 Subject: [PATCH 18/97] changed code to grab session id from pasted domain in join dialog to be a pop, to avoid errors if the hash string is not present --- src/components/Menu.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/Menu.vue b/src/components/Menu.vue index eb039d9..5160305 100644 --- a/src/components/Menu.vue +++ b/src/components/Menu.vue @@ -259,7 +259,7 @@ export default { "Enter the channel number / name of the session you want to join" ); if (sessionId.match(/^https?:\/\//i)) { - sessionId = sessionId.split("#")[1]; + sessionId = sessionId.split("#").pop(); } if (sessionId) { this.$store.commit("session/clearVoteHistory"); From ec64584da5586cc2cfed774286588c1aeabf2e86 Mon Sep 17 00:00:00 2001 From: Steffen Date: Mon, 1 Feb 2021 22:33:59 +0100 Subject: [PATCH 19/97] added custom image opt in --- src/components/Menu.vue | 80 +++++++++++++++++++++--------------- src/store/index.js | 55 +++++++++++-------------- src/store/modules/session.js | 10 ++--- src/store/persistence.js | 36 ++++++++++++---- 4 files changed, 103 insertions(+), 78 deletions(-) diff --git a/src/components/Menu.vue b/src/components/Menu.vue index 79715a5..aa8ea5a 100644 --- a/src/components/Menu.vue +++ b/src/components/Menu.vue @@ -73,7 +73,7 @@ Background image -
  • +
  • Mute Sounds Live Session
  • -
  • - Host (Storyteller)[H] -
  • -
  • - Join (Player)[J] -
  • -
  • - Delay to {{ session.isSpectator ? "host" : "players" }} - {{ session.ping }}ms -
  • -
  • - Copy player link - -
  • -
  • - Send Characters - -
  • -
  • - Nomination history[V] -
  • -
  • - Leave Session - {{ session.sessionId }} -
  • + +