How to limit user numbers in channels

Is it possible to limit the number of users that are allowed to be in a channel?

It’s not possible to set a numeric limit on how many users can access a channel, although it is possible to restrict who can access the channel via token authorisation.

Token permissions can be set to limit access to the channel for the required users, by setting your auth server to only allow permissions on a channel to certain client IDs as specified in this article.

Example:

Say you have the letters of the alphabet as client IDs, you can set up a channel and only allow 'a' and 'b' to publish and subscribe by giving their tokens the relevant permissions.  Client IDs 'c' and 'd' would not have permissions for that channel and so could not 'publish', 'subscribe' or anything else like enter presence unless you update their permissions. Therefore, this acts as a private channel between 'a' and 'b'.

Following the above scenario, below is an example of permissions for different users in several channels called ‘private_chat_ab’, 'group_chat',  and 'alerts'.

 

ClientID 'a' has the following permissions:

{

  "private_chat_ab": ["publish", "subscribe", "presence"],

  "group_chat": ["publish", "subscribe", "history"],

  "alerts": ["subscribe"]

}

 

ClientID 'b' has the following permissions:

{

  "private_chat_ab": ["publish", "subscribe", "presence"],

  "group_chat": ["publish", "subscribe", "history"],

  "alerts": ["subscribe"]

}

 

ClientID 'c' has the following permissions:

{

  "group_chat": ["publish", "subscribe", "history"],

  "alerts": ["subscribe"]

}

 

ClientID 'd' has the following permissions:

{

  "group_chat": ["publish", "subscribe", "history"],

  "alerts": ["subscribe"]

}

 

* This means that clients 'a', 'b', 'c' and 'd' would all have permissions to publish and subscribe in the group_chat channel, but only certain users ('a' and 'b') have permissions for the dedicated private_chat_ab channel.

 

For more information on the different permissions that can be assigned to users on a channel and examples, please see here.

You can also find a demo on how to implement token authorisation and how to assign permissions via this link.

 

For further details on authentication, please see this guide

 

Reach out on our support portal if you have any further questions and we will be happy to help.