Skip to content

Emit cheatsheet: sending an event to all clients #192

Open
@otsheln1k

Description

@otsheln1k

The Emit cheatsheet page says that it's possible to send an event to all clients like this:

  // sending to all connected clients
  io.emit('an event sent to all connected clients');

However, according to this documentation page, io is an alias for io.sockets (source code; it seems this isn't mentioned in the server API documentation) which itself (according to this page and source code) is an alias for io.of('/') (assuming io is a Socket.IO server). I tested this, and io.emit(...) indeed behaves just like io.of('/').emit(...).

It seems that sending an event to all clients in all namespaces is not even possible (except if you manually send it to every namespace you're interested in with multiple io.of(...).emit(...) calls).

The following example from the cheatsheet is also likely wrong, but I haven't tested it:

  // sending to all clients on this node (when using multiple nodes)
  io.local.emit('hi', 'my lovely babies');

My guess is that it will send an event to every cilent on the default namespace of the current node (source code: it only sets a modifier on the default namespace).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions