Reputation: 12437
How can I iterate through a SignalR group (hub class)
Groups.Add(Context.ConnectionId, "foo");
How would I iterate through the group to see whose in it? and then possibly based on the connectionId in there return a user
Upvotes: 2
Views: 3820
Reputation: 2564
Possibly implement a Dictionary when the clients conn/dis/re-connect
public static readonly ConcurrentDictionary<string, object> _connections
= new ConcurrentDictionary<string, object>();
public Task Connect()
{
_connections.TryAdd(Context.ConnectionId, null);
Groups.Add(Context.ConnectionId, "users");
//Returns Connection count.
return Clients.tally(_connections.Count.ToString());
}
You can expand this to include there name or group etc , but like akoeplinger say's you have to keep track of this throughout your app.
Upvotes: 1
Reputation: 2517
From the SignalR docs:
Groups are not persisted on the server so applications are responsible for keeping track of what connections are in what groups so things like group count can be achieved.
So no, you can't iterate over the users in a group, you need to keep track of that yourself.
Upvotes: 3