gshow8 shac
gshow8 shac

Reputation: 421

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.

Upvotes: 1

Views: 678

Answers (2)

gshow8 shac
gshow8 shac

Reputation: 421

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.

Upvotes: 0

user11909477
user11909477

Reputation:

From the documentation:

When you want to send something to all users of a room, use

io.to('some room').emit('some event');

When you want to send something to all users of a room except for one socket in that room (which is usually called "broadcasting"), use

socket.to('some room').emit('some event');

Upvotes: 3

Related Questions