Answer the question
In order to leave comments, you need to log in
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
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.
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 questionAsk a Question
731 491 924 answers to any question