title: how to get number of clients in room while using socket.io?
body: <p>I want to get <strong>number of participants</strong> in a room while using <strong>socket.io</strong></p>
  <p>This is what I am trying to do</p>
  <pre><code>io.on(&quot;connection&quot;, function (socket) {
    console.log(&quot;User Connected &quot; + socket.id);
  
    io.on(&quot;join&quot;, function (roomName) {
      var numClients = io.sockets.adapter.rooms[roomName].length;
      if (numClients == 0) {
        socket.join(roomName);
      } else if (numClients == 1) {
        socket.join(roomName);
      } else {
        console.log(&quot;More than 2 users.&quot;);
      }
    });
  });
  </code></pre>