I am new to node.js and javascript. I am using socket.io and trying to list the sockets connected in this room. When the socket is connected, I give it an alias:
io.use(function (socket, next) {
var handshakeUserid = socket.request._query.userid;
socket.nickname = handshakeUserid;
next();
});
With this code, I can get the socket id:
for (socketID in io.nsps['/'].adapter.rooms[room_name].sockets) {
console.log(socketID);
}
But how can I access the alias property in this loop? Trying socketID.nickname
or socketID[nickname]
will cause an error. Nick is not determined.
source
share