mirror of
https://github.com/randyjc/Rahoot.git
synced 2026-03-13 20:15:35 +01:00
Emit total players count to clients in the room on player join and kick events
This commit is contained in:
@@ -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) => {
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user