Fix lobby: only show players who have joined

Changes:
- Added socket.join(LOBBY_ROOM) when player joins lobby
- Changed io.emit() to io.to(LOBBY_ROOM).emit() for all lobby events
- Players only see lobby events after they click JOIN LOBBY
- Fixed player list to update correctly when players join/ready
- Game now starts properly when all players are ready

Files modified:
- server/index.js: Use Socket.io rooms for lobby scoping
- public/js/app.js: Show lobby screen on player-joined event
- public/js/ui.js: Removed duplicate listener override
This commit is contained in:
2026-03-20 07:30:42 -07:00
parent e7917a338e
commit 833256d18f
3 changed files with 15 additions and 13 deletions
+4
View File
@@ -23,6 +23,10 @@ function setupNetworkListeners() {
// Player joined lobby
network.setListener('player-joined', (player) => {
ui.updatePlayerList(network.getAllPlayers());
// Show lobby screen if we're on the login screen
if (ui.screens.room.classList.contains('active')) {
ui.showScreen('lobby');
}
});
// Player left lobby
-5
View File
@@ -57,11 +57,6 @@ class UIManager {
return;
}
// Set listener for player joined event
network.setListener('player-joined', () => {
this.showScreen('lobby');
});
network.joinLobby(playerName);
}