question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Sending to all in room, including self

See original GitHub issue

I cannot seem to find a way how to emit event to all clients inside a room including self.

Basicly socket.in('myroom').broadcast.emit() emits to all, except self and socket.in('myroom').emit() sends only to self.

I know I can do both at the same time, but that doesn’t feel effective to me.

How do I emit to all clients in the room, including self with one call?

Update: Okay, I manged to emit to all with io.sockets.in('myroom').emit();, but that made me introduce io into global scope, that kind of ruins my decoupling.

Is there a way to do it through socket object?

Issue Analytics

  • State:closed
  • Created 11 years ago
  • Comments:9

github_iconTop GitHub Comments

30reactions
yadscommented, Jul 8, 2014

FWIW in v1.0 you can do

socket.nsp.to(room).emit(event);

0reactions
immatobicommented, Nov 13, 2022

@yads Works well, thanks

Read more comments on GitHub >

github_iconTop Results From Across the Web

javascript - Socket.Io how to emit to all members in a room ...
Send to both room and self. As a work-around, you could also just send to both: socket.broadcast(room).emit(...); socket.emit(...); ...
Read more >
Emit cheatsheet - Socket.IO
WARNING: `socket.to(socket.id).emit()` will NOT work, as it will send to everyone in the room // named `socket.id` but the sender.
Read more >
Socket.IO - Broadcasting - Tutorialspoint
Broadcasting can be done at multiple levels. We can send the message to all the connected clients, to clients on a namespace and...
Read more >
Broadcasting event to all clients including sender - Laracasts
What happens is that when i broadcast a laravel event all clients get updated except the sender but when sending other events from...
Read more >
Managing breakout rooms - Zoom Support
* While both the host and any co-hosts have the ability to assign participants to breakout rooms, only the first submitted set of...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found