Note that there are some explanatory texts on larger screens.

plurals
  1. POSocket.IO get connected clients list
    primarykey
    data
    text
    <p>I'm having a heck of a time finding documentation on <code>io.sockets.clients()</code> so I can retrieve the connected clients id, username, etc. When I <code>alert(io.sockets.clients().length.toString());</code> it gives me the correct number, but I need to find the structure of the array. Is there a way I can figure out the array without knowing the structure? Much like php's <code>print_r()</code>?</p> <p>Code so far:</p> <pre><code>socket.on('switchRoom', function(newroom){ var clients = io.sockets.clients(); socket.emit('users', clients); }); socket.on('users', function(usernames) { for(var client in usernames) { console.log(usernames[client].id + ' disconnected: ' + usernames[client].disconnected) } }); </code></pre> <p>I receive this error after 'switchRoom' is fired</p> <pre><code>/home/ed/socket/chat/node_modules/socket.io/lib/parser.js:81 data = JSON.stringify(ev); ^ TypeError: Converting circular structure to JSON at Object.stringify (native) at Object.encodePacket (/home/ed/socket/chat/node_modules/socket.io/lib/parser.js:81:19) at Socket.packet (/home/ed/socket/chat/node_modules/socket.io/lib/socket.js:202:21) at Socket.emit (/home/ed/socket/chat/node_modules/socket.io/lib/socket.js:351:15) at Socket.&lt;anonymous&gt; (/home/ed/socket/chat/app.js:58:10) at Socket.$emit (events.js:64:17) at SocketNamespace.handlePacket (/home/ed/socket/chat/node_modules/socket.io/lib/namespace.js:331:20) at Manager.onClientMessage (/home/ed/socket/chat/node_modules/socket.io/lib/manager.js:436:38) at WebSocket.onMessage (/home/ed/socket/chat/node_modules/socket.io/lib/transport.js:387:20) at Parser.&lt;anonymous&gt; (/home/ed/socket/chat/node_modules/socket.io/lib/transports/websocket/hybi-07-12.js:38:10) </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload