List of connected clients username using socket io

前端 未结 2 469
旧巷少年郎
旧巷少年郎 2020-12-22 23:46

I\'ve made a chat client with different chat rooms in NodeJS, socketIO and Express. I am trying to display an updated list over connected users for each room.

Is ther

相关标签:
2条回答
  • 2020-12-23 00:20

    There are similar questions that will help you with this:

    Socket.IO - how do I get a list of connected sockets/clients?

    Create a list of Connected Clients using socket.io

    My advice is to keep track yourself of the list of connected clients, because you never know when the internal API of Socket.IO may change. So on each connect add the client to an array (or to the database) and on each disconnect remove him.

    0 讨论(0)
  • 2020-12-23 00:26

    In socket.io@2.3.0 you can use:

    Object.keys(io.sockets).forEach((socketId) => {
      const socket = io.sockets[socketId];
    })
    
    0 讨论(0)
提交回复
热议问题