Hello Team,
I have noticed a bug in the API Doc tool related to Socket.IO event handling.
According to the Socket.IO documentation:
io.to(roomId).emit(…) → should send the message to all clients in the room, including the sender.
socket.broadcast.to(roomId).emit(…) → should send the message to all clients in the room except the sender.
However, in the API Doc tool, when I use socket.broadcast.to(roomId).emit(…), the sender is also receiving the message event, which should not happen. This behavior makes both methods (io.to and socket.broadcast.to) act the same, which is incorrect.
Steps to Reproduce:
Connect multiple clients to a room.
From one client, emit a message using socket.broadcast.to(roomId).emit(…).
Observe that the sender also receives the message, which is not expected.
Expected Behavior:
The sender should not receive the event when using socket.broadcast.to(…).
Actual Behavior:
The sender is still receiving the event.
Kindly investigate and fix this issue so that the broadcast behavior works correctly in the API Doc tool.
Issue:
When I use socket.broadcast.to(roomId).emit(…), the sender is also receiving the event, which should not happen. This makes both methods behave the same.
Example Code
// Server-side
socket.on(“sendMessage”, (roomId, msg) => {
socket.broadcast.to(roomId).emit(“newMessage”, msg);
});
Expected Behavior:
If User A, B, and C are in the same room:
User A sends a message.
Only User B and C should receive it.
Actual Behavior:
User A is also receiving the event, same as io.to(roomId).emit(…).
Please check this issue and fix it so socket.broadcast.to(…) works as expected.
Thank you,
Chetan
