Skip to content
Advertisement

socket.io broadcast in a room

I am trying to use socket.io to broadcast only to users of a specific room (in another word, to send to all users in that room except me, the sender). So far, I have tried:

io.of("/").in(room_temp).broadcast.emit('transcription', data);
io.of("/").to(room_temp).broadcast.emit('transcription', data);
io.of("/").broadcast.in(room_temp).emit('transcription', data);
io.of("/").broadcast.to(room_temp).emit('transcription', data);

None of them work unfortunately.

Advertisement

Answer

io.of("/").to(room_temp).emit('transcription', data); would submit to everyone in the room include the user itself.

socket.to(room_temp).emit('transcription', data); would submit to everyone in the room except yourself.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement