0

I can see the way to create a group as:

public Task CreateGroup(string group)
{
    return Groups.Add(Context.ConnectionId, group);
}

How do I create an array of groups for Ids of an entity Channel (having Id and Name properties) even though the only connection id I have is context.ConnectionId.
(Edited with Task syntax)

If i have an array of group names, i want to be able to create groups on the basis of it. Something like ...

public void CreateGroups(string[] groups)
{
    Groups.AddRange(Context.ConnectionId, groups);
}
heyNow
  • 866
  • 2
  • 19
  • 42

1 Answers1

1

You can do something like this:

public async Task CreateGroup(string[] groups)
{
    foreach (var group in groups)
    {
        await Groups.Add(Context.ConnectionId, group);
    }
}

There is however a caveat to adding a client to many groups. The way group membership is sent between the client and the server is a groupsToken which is an encrypted and encoded list of groups a connection belong to. Once a connection belongs to many groups the groupsToken is getting really long. Since the groupsToken is sent in the query string for some operations (most notably reconnects, or in case of longPolling for each poll request) if it gets too long the requests can fail due to url being to long.

Pawel
  • 31,342
  • 4
  • 73
  • 104
  • wow i had no idea, i was thinking of a way to authenticate group membership so that a client would stay in their assigned group (else error for them). Also when we establish a secure signalR connection using our own token will that get exchanged for a group token when a group is created ? – heyNow Sep 21 '16 at 17:19
  • I don't think you can provide your own groupsToken if you are asking about that - the server needs to be able to decrypt token so you would have to encrypt it using the same key. Also if group membership changes the server pushes new groupsToken to the client. In any way providing your own groupsToken is not a supported scenario and if you are trying to hack the system you are pretty much on your own. – Pawel Sep 21 '16 at 17:29