How to send response to a List of Groups and exclude some Connection Ids in SignalR Core?

Viewed 86

In AspNet.SignalR.Core, there was this method in IHubConnectionContext where you can send a response to a list of groups while excluding some Connection Ids i.e:

T Groups(IList<string> groupNames, params string[] excludeConnectionIds);

This would be called as:

Clients.Groups(groupNames, exconnectionIds).ReceiveCollaborationNotification(response);

Now I have migrated to AspNetCore.SignalR.Core and there is no such method that accepts both a list of group names and Connection Ids to be excluded. It does have the method mentioned below but this one only accepts one group name, not a list.

T GroupExcept(string groupName, IReadOnlyList<string> excludedConnectionIds);

How can I achieve what T Groups(IList<string> groupNames, params string[] excludeConnectionIds does in AspNetCore.SignalR.Core

1 Answers

In the new SignalR version, you have this extension methods to be invoked:

public static T GroupExcept<T> (this Microsoft.AspNetCore.SignalR.IHubClients<T> hubClients, string groupName, string excludedConnectionId1, string excludedConnectionId2, string excludedConnectionId3, string excludedConnectionId4, string excludedConnectionId5, string excludedConnectionId6, string excludedConnectionId7, string excludedConnectionId8);

You can read more about it here.

So to archive exactly what do you want, you will need to use those extension methods.

Related