Is there a way to get a sockets namespace? I've tried various things but cannot get it to work. Given a socket object I would like to be able to know what namespace it belongs to. Thank you very much.
for example
nsp = io.of('/' + venue_code).on('connection', function(socket) {
socket.namespace = nsp
if (typeof servers[nsp.name] == 'undefined') {
servers[nsp.name] = socket.id
winston.debug("Server " + socket.id + " connected to " + nsp.name)
socket.room = "servers"
socket.join(socket.room)
} else {
socket.room = "clients"
socket.join(socket.room)
winston.debug("Client " + socket.id + " connected to " + nsp.name)
}
path Default value: /socket.io/ It is the name of the path that is captured on the server side.
Note: You can use either https or wss (respectively, http or ws ).
Socket.IO is NOT a WebSocket implementation. Although Socket.IO indeed uses WebSocket for transport when possible, it adds additional metadata to each packet.
As we saw in the performance section of this article, a Socket.IO server can sustain 10,000 concurrent connections.
It is just socket.nsp
, which gives the entire Namespace
object. Use socket.nsp.name
to get the actual name.
nsp = io.of('/' + venue_code).on('connection', function(socket) {
winston.debug(socket.nsp)
}
Note that if you attach this same handler to the root namespace, you'll get the root namespace -- those middlewares are run before the correct namespace is attached.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With