Nodejs Socketio Get All Clients
In socket.io v.0.9.x you could access al connected clients by using the aptly named function clients
:
io.sockets.clients().map(function(socket) {
...
})
In v.1.x that does not work. One one to do it would be to access the underlying engine.io:
To get an array of connected clients:
io.sockets.sockets.map(function(socket) {
...
})
To get an array of the connected client ids:
//Get array of the connected clients
Object.keys(io.eio.clients) //=> [ 'US8AxrUrrDF_G7ZUAAAA', 'Ov2Ca24Olkhf2NHbAAAB' ]
To get a count of connected clients:
io.eio.clientsCount
NOTE: You could also use the io.engine
property.