Skip to content

Commit

Permalink
check who is dead at the start of meetings and don't let them talk at…
Browse files Browse the repository at this point in the history
… the end of a meeting
  • Loading branch information
edtervit committed Aug 1, 2024
1 parent 0f4f3c5 commit 0b9dc8b
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/renderer/Voice.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,12 @@ const Voice: React.FC<VoiceProps> = function ({ t, error: initialError }: VoiceP
const [mutedState, setMuted] = useState(false);
const [connected, setConnected] = useState(false);

const [playersThatHaveDiedThisGame, setPlayersThatHaveDiedThisGame] = useState<number[]>([]);

const checkIfPlayerWasDeadAtStartOfMeeting = (ptr: number) => {
return playersThatHaveDiedThisGame.includes(ptr);
}

function applyEffect(gain: AudioNode, effectNode: AudioNode, destination: AudioNode, player: Player) {
console.log('Apply effect->', effectNode);
try {
Expand Down Expand Up @@ -702,6 +708,7 @@ const Voice: React.FC<VoiceProps> = function ({ t, error: initialError }: VoiceP
// Set dead player data
useEffect(() => {
if (gameState.gameState === GameState.LOBBY) {
setPlayersThatHaveDiedThisGame([]);
setOtherDead({});
} else if (gameState.gameState !== GameState.TASKS) {
if (!gameState.players) return;
Expand All @@ -711,6 +718,14 @@ const Voice: React.FC<VoiceProps> = function ({ t, error: initialError }: VoiceP
}
return { ...old };
});
setPlayersThatHaveDiedThisGame((prevState) => {
for (const player of gameState.players) {
if ((player.isDead || player.disconnected) && !prevState.includes(player.ptr)) {
prevState.push(player.ptr);
}
}
return [...prevState];
});
}
}, [gameState.gameState]);

Expand Down Expand Up @@ -1194,6 +1209,13 @@ const Voice: React.FC<VoiceProps> = function ({ t, error: initialError }: VoiceP
const tempTalking = { ...otherTalking };
let talkingUpdate = false;
for (const player of otherPlayers) {
// bug with TOH where all players are considered alive during the ejection screen. This is a workaround
if (checkIfPlayerWasDeadAtStartOfMeeting(player.ptr) && !player.isDead) {
player.isDead = true;
}
if (checkIfPlayerWasDeadAtStartOfMeeting(myPlayer.ptr) && !myPlayer.isDead) {
myPlayer.isDead = true;
}
const peerId = playerSocketIds[player.clientId];
const audio = player.clientId === myPlayer.clientId ? undefined : audioElements.current[peerId];
if (
Expand Down

0 comments on commit 0b9dc8b

Please sign in to comment.