M
M
Maxim Vlasov2020-07-01 08:30:33
Socket.io
Maxim Vlasov, 2020-07-01 08:30:33

How to send a message to one user in a room in socket.io?

There are several rooms, the user can be in several at the same time. How to send a message to only one of the rooms?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Maxim Vlasov, 2020-07-05
@tr0yka

Because rooms is essentially an ID that is added to a socket, I came to the conclusion that the socket needs to add its ID + room ID. Those. essentially drive each user into one more room, but personal. And then you can process such messages. Might help someone.

T
tahyhax, 2020-07-14
@tahyhax

The documentation details all options for sending events Documentation
//sending all clients this room except sender
socket.broadcast.to('roomName').emit('broadcast', 'hello friends!');
// sending to individual socketid (private message)
io.to(socketId).emit('hey', 'I just met you');

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question