Skip to content

Add ability to broadcast to everyone but yoursefl #938

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

Open
NathanFlurry opened this issue Apr 21, 2025 · 3 comments
Open

Add ability to broadcast to everyone but yoursefl #938

NathanFlurry opened this issue Apr 21, 2025 · 3 comments
Assignees
Labels
good first issue Good for newcomers

Comments

@NathanFlurry
Copy link
Member

Motivation

Add ability to broadcast to conns except for the conn that sent the RPC request. Only available on ActionContext.

Implementation

actor({
  actions: {
    foo: c => {
      c.broadcast("bar", 123, { excludeSelf: true });
    }
  }
});

excludeSelf naming could use some work.

Alternative Implementations

exclude

Add a more generic option for just excluding connection IDs.

actor({
  actions: {
    foo: c => {
      c.broadcast("bar", 123, { exclude: [c.conn.id] });
    }
  }
});

It might make sense to implement both, since broadcast to all but self is a very common operation.

broadcastToOthers

Same functionality as excludeSelf but a separate method name.

Prior Art

Socket.io:

  io.except(excludedSocketId).emit('broadcastEvent', data);
@NathanFlurry NathanFlurry added the good first issue Good for newcomers label Apr 21, 2025
Copy link

linear bot commented Apr 21, 2025

@abcxff abcxff self-assigned this Apr 21, 2025
Copy link
Collaborator

abcxff commented Apr 21, 2025

a note, broadcast has signature broadcast(name, ...args), so we can't fit a options object { excludeSelf: true } at the last param.

One way of going about this is to have two methods, broadcast(name, ...args) and broadcastWith(opts, name, ...args) aka broadcastWithOptions(opts, name, ...args) . where broadcast just wraps around broadcastWith({}, name, …args)

@abcxff abcxff closed this as completed Apr 22, 2025
@abcxff abcxff reopened this Apr 22, 2025
@abcxff abcxff closed this as completed Apr 22, 2025
@abcxff
Copy link
Collaborator

abcxff commented Apr 22, 2025

Completed with #939

@abcxff abcxff reopened this Apr 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants