Skip to content
New issue

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

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

Already on GitHub? # to your account

Exclude specific sockets when emitting #3789

Closed

Conversation

sebamarynissen
Copy link
Contributor

The kind of change this PR does introduce

  • a bug fix
  • a new feature
  • an update to the documentation
  • a code change that improves performance
  • other

New behavior

This PR adds the possibility to exclude specific socket ids when emitting messages:

io.except(id).emit("foo", "bar");
socket.broadcast.except(id).emit("foo", "bar");
socket.to("room").except(id).emit("foo", "bar");

In combination with socketio/socket.io-adapter#66 this will allow excluding all sockets in a specific room as well.

Other information (e.g. related issues)

See also socketio/socket.io-adapter#66 and socketio/socket.io-redis-emitter#92.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
darrachequesne pushed a commit that referenced this pull request Mar 1, 2021
New syntax:

```
io.except("room1").emit(...);
io.to("room1").except("room2").emit(...);

socket.broadcast.except("room1").emit(...);
socket.to("room1").except("room2").emit(...);
```

Related:

- #3629
- #3657
@darrachequesne
Copy link
Member

Merged as 7de2e87. Thanks a lot 👍

This was referenced Mar 10, 2021
This was referenced Mar 11, 2021
dzad pushed a commit to dzad/socket.io that referenced this pull request May 29, 2023
New syntax:

```
io.except("room1").emit(...);
io.to("room1").except("room2").emit(...);

socket.broadcast.except("room1").emit(...);
socket.to("room1").except("room2").emit(...);
```

Related:

- socketio#3629
- socketio#3657
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants