Reputation: 23
If you have a client in a specific namespace/room that performs a socket.emit and you do a "socket on" on the server how can you capture the namespace origin as a string ?
IE:
Client:
socket.emit('foo', $('#bar').val());
return false;
Server:
socket on('foo', function (foo) {
var usersubmitteddata = foo
var namespaceorigin = ???
});
Upvotes: 2
Views: 1395
Reputation: 6998
To list what rooms a socket belongs to just use socket.rooms
:
console.log(socket.rooms);
socket.io does not expose which namespace the client connected on, but you can see the current namespace on the server with socket.nsp.name
, and which exists on the server with socket.nsp.server.nsps
.
The namespaces that a client should connect to must be created before you connect. If not you will get an Invalid namespace
error message. But after that it's actually every message that contains the namespace, and not the socket. In the protocol itself you can have a client send messages on different namespaces.
Upvotes: 2