Skip to content

SignalR send to users and groups in one call #22214

@jhofer-arian

Description

@jhofer-arian

Is your feature request related to a problem? Please describe.

I am trying to send a SignalR Message to a List of Groups and Users. For example, all Admins and Managers should get this message as well as a certain user who triggered an API call in the program.
To do this we are using the following code.

   [CapSubscribe(EventNames.SignalRUpdateEventName)]
        public async Task Handle(SignalREvent @event)
        {
            //Adds a message ID to each message to give the client the option to discard duplicates
            @event.JsonPayload.Add("MessageId", Guid.NewGuid().ToString());
            if ([email protected]())
            {
                await _hubContext.Clients.Groups(@event.Groups).SendAsync(@event.MethodName, new object[] {@event.JsonPayload});
            }

            if ([email protected]())
            {
                await _hubContext.Clients.Users(@event.Users)
                    .SendAsync(@event.MethodName, new object[] {@event.JsonPayload});
            }

        }

This results in multiple Messages being sent by SignalR and our client receiving multiple messages if the user is, for example, the one who initiated the call and is part of the group Admin and Manager.

Describe the solution you'd like

My Solution would be that I could call something like this:
_hubContext.Clients.Groups(@event.Groups).Users(@event.Users).SendAsync(@event.MethodName, new object[] {@event.JsonPayload});
And in the background singalR would aggregate all the connection Ids so that only one message per connection would be sent.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions