Getting all group names in signalr

2019-03-01 00:58发布

ok so I have this code

var c = GlobalHost.ConnectionManager.GetHubContext<SomeHubClass>().Clients;

now from this the Clients returns an IHubConext that has IHubConnectionContext that has an IGroupManager Groups. now is there anyway to get all the group names from this? Is this even possible with the signalR interface or do I have to track all the groups for each hub myself?

标签: c# signalr
1条回答
三岁会撩人
2楼-- · 2019-03-01 01:18

SignalR does not have an exposed API for managing groups as a whole, iterating over groups, or even obtaining a summary list of groups. You can only add or remove groups. If you want to persist a list of group names, perhaps use a singleton pattern for your SomeHubClass. Persist a List<string> of group names in the singleton that you can easily access, or even a Dictionary<string, HashSet<string>> to map both the name and the hashset of connection ids, though that is probably overkill in this instance.

See http://www.asp.net/signalr/overview/hubs-api/hubs-api-guide-server#callfromoutsidehub for implementing a singleton of your hub.

查看更多
登录 后发表回答