Emit total players count to clients in the room on player join and kick events

This commit is contained in:
Muhammad Rais Ramadhani
2025-09-13 18:14:56 +07:00
parent 0bdec93c21
commit 93b1098e74
4 changed files with 27 additions and 1 deletions

View File

@@ -37,6 +37,9 @@ const Manager = {
io.in(playerId).socketsLeave(game.room)
io.to(player.id).emit("game:kick")
io.to(game.manager).emit("manager:playerKicked", player.id)
// Emit updated total players to all clients in the room
io.to(game.room).emit("game:totalPlayers", game.players.length)
},
startGame: async (game, io, socket) => {

View File

@@ -56,6 +56,9 @@ const Player = {
game.players.push(playerData)
// Emit total players to all players in the room
io.to(player.room).emit("game:totalPlayers", game.players.length)
socket.emit("game:successJoin")
},
@@ -82,6 +85,8 @@ const Player = {
data: { text: "Waiting for the players to answer" },
})
socket.to(game.room).emit("game:playerAnswer", game.playersAnswer.length)
// Also emit total players to keep the UI updated
io.to(game.room).emit("game:totalPlayers", game.players.length)
if (game.playersAnswer.length === game.players.length) {
abortCooldown()