Socket.io Connected User Count

后端 未结 12 1034
有刺的猬
有刺的猬 2021-01-30 20:24

I finally got socket.io to work properly, but I have encountered a strange problem.

I am not sure if this is the best way, but I am using:

io.sockets.cli         


        
12条回答
  •  庸人自扰
    2021-01-30 21:13

    Why use an (implicit global) variable when you could always filter the array, that is returned by calling the clients() method.

    function filterNullValues (i) {
      return (i!=null);
    }
    io.sockets.clients().filter(filterNullValues).length;
    

提交回复
热议问题