Listing all the clients connected to a room in Socket.io version > 1

前端 未结 2 820
终归单人心
终归单人心 2020-12-30 07:09

After the io.sockets.clients() method has been depreciated from the later versions of Socket.io, and after my research couldn\'t find any documentation on the socket.io offi

2条回答
  •  独厮守ぢ
    2020-12-30 07:54

    In Socket.IO 1.4

    To get the array of All connected Users :

    // io.sockets.connected returns an Object with socketId as its key 
    
    var allConnectedClients = Object.keys(io.sockets.connected);// This will return the array of SockeId of all the connected clients
    

    To get the Count of all clients :

    var clientsCount = io.engine.clientsCount ; // This will return the count of connected clients
    

提交回复
热议问题