Socket.io: Send message to a specific namespace with specific ID

Viewed 2814

Is it possible to send a message to a socket with different namespace using their custom socket.id??. I'm using socket.io to create a chat and send private message.

I successfully manage to create a room and send a message to each other privately using

io.to(room).emit('chatMessage', from, message);

But I also want to send a message to sockets with different namespace using their ID like:

io.of('nameSpace').to(socket.id).emit('chatMessage', from, message); 

I've tried different combination such as,

io.of('nameSpace').to(socket.id).emit('chatMessage', from, message);

io.of('nameSpace).sockets.socket(socket.id).emit('chatMessage', from, message);

io.to(users[socketid]).emit('chatMessage', from, message);

io.sockets.socket(socketid).emit('chatMessage', from, message);

but it's not working. Is there other way to send a message to a specific client with different namespace? I'm using a combination of rooms and namespace.

NOTE: I'm using the string query that's equal to the name of the user as the name of my room.

1 Answers
Related