Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Are you doing this on the client side (in the browser) or on the server side? You mention using <code>alert</code>, but I'm not aware of a <code>clients()</code> method on the client side that does what you want.</p> <p>On the server side, <code>clients()</code> returns an array of <code>Socket</code>s <a href="https://github.com/LearnBoost/socket.io/blob/6074795b191248fa36db37b89df3c95e1520adcb/lib/namespace.js#L44-61" rel="nofollow">as defined by this method</a>:</p> <pre><code>/** * Retrieves all clients as Socket instances as an array. * * @api public */ SocketNamespace.prototype.clients = function (room) { var room = this.name + (room !== undefined ? '/' + room : ''); if (!this.manager.rooms[room]) { return []; } return this.manager.rooms[room].map(function (id) { return this.socket(id); }, this); }; </code></pre> <p>The Node.js console and browsers with dev tools provide a <code>console</code> object that allows debugging; generally, you can call <code>console.log(something)</code> where <code>something</code> pretty much anything; in the case of an object, the details of the object will be enumerated in one way or another.</p> <p>[Edit]</p> <p>Since you're already using <code>socket.set</code> to store the username, perhaps you can try something like this:</p> <pre><code>// server socket.on('connection', function(socket) { ... socket.on('disconnect', function() { socket.get('username', function (err, name) { socket.broadcast.emit('disconnected', name); }); }); ... }); // client socket.on('connect', function () { ... socket.on('disconnected', function(name) { console.log(name + " disconnected."); }); ... }); </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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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