-
Notifications
You must be signed in to change notification settings - Fork 81
Print passport data of connected sockets in a room #122
Comments
can you try something like this: var currentRoom = io.nsps['/'].adapter.rooms[socket.request.user.companyid];
var currentUsersInRoom = currentRoom.sockets.map(s => s.request.user);
console.dir(currentUsersInRoom); I haven't tested this, the reason I have to believe this should work is because of this doc Socket#request which states:
Let me know if if works |
I get:
|
Sorry this is the error:
|
Yes, is a little bit more complicated than what I though. Here is an answer on SO: Maybe something like this: function findClientsSocket(roomId, namespace) {
var res = []
, ns = io.of(namespace ||"/"); // the default namespace is "/"
if (ns) {
for (var id in ns.connected) {
if(roomId) {
var index = ns.connected[id].rooms.indexOf(roomId) ;
if(index !== -1) {
res.push(ns.connected[id]);
}
} else {
res.push(ns.connected[id]);
}
}
}
return res;
}
//then
var users = findClientsSocket(socket.request.user.companyid).map(s => s.request.user);
console.dir(users, { depth: 10 }); |
This is what I get in
|
is an object and the expression |
I'm using
passport.socketio
to get user credentials and I want to print to the console the list of connected users in a given room every time a user connect. Currently I have the following:But it prints something like:
Room { sockets: { '/#PteHXocxKH8Ctv6TAAAB': true }, length: 1 }
How can I print the Passport data?
The text was updated successfully, but these errors were encountered: