On this page

Channel Groups API for Unity SDK

Channel groups allow PubNub developers to bundle thousands of channels into a group that can be identified by a name. These channel groups can then be subscribed to, receiving data from the many back-end channels the channel group contains.

Channel group operations

You can't publish to a channel group. You can only subscribe to it. To publish within the channel group, you need to publish to each channel individually.

Add channels to a channel group

Requires Stream Controller add-on

This method requires the Stream Controller add-on enabled for your key in the Admin Portal. Read the support page on enabling add-on features.

This function adds a channel to a channel group.

Method(s)

Use the following method in the Unity SDK:

Maximum number of channels

You can add up to 200 channels to a channel group per API call.

1pubnub.AddChannelsToChannelGroup()
2 .ChannelGroup(string)
3 .Channels(Array)
4 .QueryParam(Dictionary<string,object>)
5 .Execute(System.Action<PNChannelGroupsAddChannelResult, PNStatus>);
* required
ParameterDescription
ChannelGroup *
Type: string
The ChannelGroup to add the channels to.
Channels *
Type: Array
The Channels to add to the channel group.
QueryParam
Type: Dictionary<string, object>
Name-value pairs to include as query parameters.
Async
Type: PNCallback
PNCallback of type PNChannelGroupsAddChannelResult.
Execute *
Type: System.Action
System.Action of type PNChannelGroupsAddChannelResult.
ExecuteAsync
Type: None
Returns Task<PNResult<PNChannelGroupsAddChannelResult>>.

Sample code

Add channels

Reference code
This example is a self-contained code snippet ready to be run. It includes necessary imports and executes methods with console logging. Use it as a reference when working with other examples in this document.
1

Returns

The AddChannelsToChannelGroup() operation returns a PNResult<PNChannelGroupsAddChannelResult> with:

Property NameTypeDescription
Result
PNChannelGroupsAddChannelResult
The operation result.
Status
PNStatus
The request status.

PNChannelGroupsAddChannelResult includes:

Property NameTypeDescription
PNChannelGroupsAddChannelResult
Object
Empty object.
PNStatus
Object
Request status, including errors.

List channels in a channel group

Requires Stream Controller add-on

This method requires the Stream Controller add-on enabled for your key in the Admin Portal. Read the support page on enabling add-on features.

This function lists all channels in a channel group.

Method(s)

Use the following method in the Unity SDK:

1pubnub.ListChannelsForChannelGroup()
2 .ChannelGroup(string)
3 .QueryParam(Dictionary<string,object>)
4 .Execute(System.Action<PNChannelGroupsAllChannelsResult, PNStatus>);
* required
ParameterDescription
ChannelGroup *
Type: string
The channel group to fetch the channels of.
QueryParam
Type: Dictionary<string, object>
Name-value pairs to include as query parameters.
Async
Type: PNCallback
PNCallback of type PNChannelGroupsAllChannelsResult.
Execute *
Type: System.Action
System.Action of type PNChannelGroupsAllChannelsResult.
ExecuteAsync
Type: None
Returns Task<PNResult<PNChannelGroupsAllChannelsResult>>.

Sample code

List channels

1

Returns

The ListChannelsForChannelGroup() operation returns a PNChannelGroupsAllChannelsResult with:

Property NameTypeDescription
Result
PNChannelGroupsAllChannelsResult
The operation result.
Status
PNStatus
The request status.

PNChannelGroupsAllChannelsResult includes:

Property NameTypeDescription
Channels
List<string>
Channel names in the group.

Remove channels from a channel group

Requires Stream Controller add-on

This method requires the Stream Controller add-on enabled for your key in the Admin Portal. Read the support page on enabling add-on features.

This function removes channels from a channel group.

Method(s)

Use the following method in the Unity SDK:

1pubnub.RemoveChannelsFromChannelGroup()
2 .ChannelGroup(string)
3 .Channels(Array)
4 .QueryParam(Dictionary<string,object>)
5 .Execute((result, status) => {});
* required
ParameterDescription
ChannelGroup *
Type: string
The channel group to remove channels from.
Channels *
Type: Array
The channels to remove.
QueryParam
Type: Dictionary<string, object>
Name-value pairs to include as query parameters.
Async
Type: PNCallback
PNCallback of type PNChannelGroupsRemoveChannelResult.
Execute *
Type: System.Action
System.Action of type PNChannelGroupsRemoveChannelResult.
ExecuteAsync
Type: None
Returns Task<PNResult<PNChannelGroupsRemoveChannelResult>>.

Sample code

Remove channels

1

Returns

The RemoveChannelsFromChannelGroup() operation returns a PNChannelGroupsAddChannelResult with:

Property NameTypeDescription
Result
PNChannelGroupsRemoveChannelResult
The operation result.
Status
PNStatus
The request status.

PNChannelGroupsRemoveChannelResult includes:

Property NameTypeDescription
PNChannelGroupsRemoveChannelResult
Object
Empty object.

Delete a channel group

Requires Stream Controller add-on

This method requires the Stream Controller add-on enabled for your key in the Admin Portal. Read the support page on enabling add-on features.

This function removes a channel group.

Method(s)

Use the following method in the Unity SDK:

1pubnub.DeleteChannelGroup()
2 .ChannelGroup(string)
3 .QueryParam(Dictionary<string,object>)
4 .Execute(System.Action<PNChannelGroupsDeleteGroupResult, PNStatus>);
* required
ParameterDescription
ChannelGroup *
Type: string
The channel group to remove.
QueryParam
Type: Dictionary<string, object>
Name-value pairs to include as query parameters.
Async
Type: PNCallback
PNCallback of type PNChannelGroupsDeleteGroupResult.
Execute *
Type: System.Action
System.Action of type PNChannelGroupsDeleteGroupResult.
ExecuteAsync
Type: None
Returns Task<PNResult<PNChannelGroupsDeleteGroupResult>>.

Sample code

Delete channel group

1

Returns

The DeleteChannelGroup() operation returns a PNResult<PNChannelGroupsDeleteGroupResult> with:

Property NameTypeDescription
Status
int
HTTP status code.
Error
bool
True if the operation failed.
1{
2 "status" : 200,
3 "message" : "OK",
4 "service" : "channel-registry",
5 "error" : False
6}
Last updated on