Reputation: 17946
When the following SignalR code is run, a member who belongs to multiple qualifying groups will receive multiple messages:
public class ChatHub : Hub
{
public void Send(string name, string message, params string[] groups)
{
this.Clients.Groups(groups).broadcast(name, message);
}
}
Is there any way to send a single message to users who are members of any of the groups? In other words, if the groups
parameter above is defined as ["grpA","grpB"]
, I would want the following to happen:
Upvotes: 5
Views: 1947
Reputation: 2610
No there isn't such feature as of now in signalR. To achieve this functionality you can store the connections somewhere in memory of database that contains the information about
MemberID, GroupID, SignalRConnectionID
and then get the distinct connectionIDs for members of specific groups and sent them a message using the syntax like
List<String> connectionIDs = #GET DISTINCT LIST OF CONNECTIONS FROM DB OR IN MEMORY STORAGE#;
Clients.Clients(connectionIDs).broadcast(name, message);
Upvotes: 1
Reputation: 2820
There's not way to do this other than creating your own way to track users in each group and distinct users on your own before/on broadcasting.
Probably, this API will be introduced in the future releases, but for now there's not way to do that.
Upvotes: 3