Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Emit cheatsheet: sending an event to all clients #192

Open
otsheln1k opened this issue Nov 8, 2020 · 0 comments
Open

Emit cheatsheet: sending an event to all clients #192

otsheln1k opened this issue Nov 8, 2020 · 0 comments

Comments

@otsheln1k
Copy link

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant