You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm working on a multiplayer game using Socket.IO and React where users can join a room using a unique game pin. When a user leaves the room, I want to emit a 'userLeft' event to the remaining users in the room. However, when a single user leaves the room, all users are being removed from the room, and the 'userLeft' event is not being received by any user.
The issue occurs even though I'm not calling socket.leave() on the server-side. When I log the clients in the room before handling the 'leaveGame' event, all clients are still in the room. But when I enter the event handler for 'leaveGame' on the server-side, the room is empty.
When a user creates a room it displays : Haz joined room: 825072 Clients in room 825072: [ 'UFr55p1UUTQWr6q_AAAG' ] Mol joined room: 825072 Clients in room 825072: [ 'UFr55p1UUTQWr6q_AAAG', 'n4SpYjvY-r8JzI8-AAAH' ]
However when my client-side calls "userLeaving", this is what logClientsInRoom logs: Clients in room 825072: []
The userLeft listener isn't called because when the server side socket.to(gamePin).emit("userLeft", name); is called the room is already empty, so there is no one to listen to that event.
I want to understand why all users are being removed from the room when a single user leaves, and how to fix this issue so that the 'userLeft' event is received by the remaining users in the room.
Please let me know if you need any additional information or clarification.
The text was updated successfully, but these errors were encountered:
I'm working on a multiplayer game using Socket.IO and React where users can join a room using a unique game pin. When a user leaves the room, I want to emit a 'userLeft' event to the remaining users in the room. However, when a single user leaves the room, all users are being removed from the room, and the 'userLeft' event is not being received by any user.
The issue occurs even though I'm not calling socket.leave() on the server-side. When I log the clients in the room before handling the 'leaveGame' event, all clients are still in the room. But when I enter the event handler for 'leaveGame' on the server-side, the room is empty.
Here's my server-side code:
When a user creates a room it displays :
Haz joined room: 825072 Clients in room 825072: [ 'UFr55p1UUTQWr6q_AAAG' ] Mol joined room: 825072 Clients in room 825072: [ 'UFr55p1UUTQWr6q_AAAG', 'n4SpYjvY-r8JzI8-AAAH' ]
However when my client-side calls "userLeaving", this is what logClientsInRoom logs:
Clients in room 825072: []
Here's my client-side code:
The userLeft listener isn't called because when the server side
socket.to(gamePin).emit("userLeft", name);
is called the room is already empty, so there is no one to listen to that event.I want to understand why all users are being removed from the room when a single user leaves, and how to fix this issue so that the 'userLeft' event is received by the remaining users in the room.
Please let me know if you need any additional information or clarification.
The text was updated successfully, but these errors were encountered: