UnityUnity V4 Channel Groups API Reference for Realtime Apps

 

These docs are for PubNub 4.x for Unity which is our latest and greatest! For the docs of the older versions of the SDK, please check PubNub 3.x for Unity.

If you have questions about the PubNub for Unity SDK, please contact us at support@pubnub.com.

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

Learn more about our Channel Groups here


Requires Stream Controller add-on XRequires that the Stream Controller add-on is enabled for your key. See this page on enabling add-on features on your keys:

http://www.pubnub.com/knowledge-base/discussion/644/how-do-i-enable-add-on-features-for-my-keys.
This function adds a channel to a channel group.
Adding Channels is accomplished by using the following method(s) in the Unity V4 SDK:
 

200 channels can be added to the channel group per API call.

  1. ParameterTypeRequiredDescription
    ChannelsList<string>YesThe Channels to add to the channel group.
    ChannelGroupstringYesThe ChannelGroup to add the channels to.
    QueryParamDictionary<string, string>OptionalQueryParam accepts a Dictionary object, the keys and values are passed as the query string parameters of the URL called by the API.
    AsyncPNCallbackYesPNCallback of type PNChannelGroupsAddChannelResult.
pubnub.AddChannelsToChannelGroup()
    .Channels(new List<string> (){"my_channel"})
    .ChannelGroup("channelGroup")
    .Async((result, status) => {
        if(status.Error){
            Debug.Log (string.Format("In Example, AddChannelsToChannelGroup Error: {0} {1} {2}", status.StatusCode, status.ErrorData, status.Category));
        } else {
            Debug.Log (string.Format("DateTime {0}, In Example AddChannelsToChannelGroup, result: {1}", DateTime.UtcNow, result.Message));
        }
    });
The AddChannelsToChannelGroup() does not return actionable data, be sure to check the status object on the outcome of the operation by checking the status.isError().

Requires Stream Controller add-on XRequires that the Stream Controller add-on is enabled for your key. See this page on enabling add-on features on your keys:

http://www.pubnub.com/knowledge-base/discussion/644/how-do-i-enable-add-on-features-for-my-keys.
This function lists all the channels of the channel group.
Listing Channels is accomplished by using the following method(s) in the Unity V4 SDK:
  1. ParameterTypeRequiredDescription
    ChannelGroupstringYesChannel group to fetch the channels.
    QueryParamDictionary<string, string>OptionalQueryParam accepts a Dictionary object, the keys and values are passed as the query string parameters of the URL called by the API.
    AsyncPNCallbackYesPNCallback of type PNChannelGroupsAllChannelsResult.
pubnub.ListChannelsForChannelGroup()
    .ChannelGroup("cg")
    .Async((result, status) => {
        if(status.Error){
            Debug.Log (string.Format("In Example, ListAllChannelsOfGroup Error: {0} {1} {2}", status.StatusCode, status.ErrorData, status.Category));
        } else {
            Debug.Log (string.Format("In Example ListAllChannelsOfGroup, result: {0}", (result.Channels!=null)?string.Join(",", result.Channels.ToArray()):""));
        }
    });
The ListChannelsForChannelGroup() operation returns a PNChannelGroupsAllChannelsResult which contains the following operations:
MethodTypeDescription
ChannelsList<string>List of channels of a channel group.

Requires Stream Controller add-on XRequires that the Stream Controller add-on is enabled for your key. See this page on enabling add-on features on your keys:

http://www.pubnub.com/knowledge-base/discussion/644/how-do-i-enable-add-on-features-for-my-keys.
This function removes the channels from the channel group.
Removing Channels is accomplished by using the following method(s) in the Unity V4 SDK:
  1. ParameterTypeRequiredDescription
    ChannelsList<string>YesThe Channels to remove from the channel group.
    ChannelGroupstringYesSpecifies ChannelGroup to remove the channels from.
    QueryParamDictionary<string, string>OptionalQueryParam accepts a Dictionary object, the keys and values are passed as the query string parameters of the URL called by the API.
    AsyncPNCallbackOptionalPNCallback of type PNChannelGroupsRemoveChannelResult.
pubnub.RemoveChannelsFromChannelGroup()
    .Channels(new List<string> (){"son"})
    .ChannelGroup("family")
    .Async((result, status) => {
        Debug.Log ("in RemoveChannelsFromCG");
        if(status.Error){
            Debug.Log (string.Format("In Example, RemoveChannelsFromCG Error: {0} {1} {2}", status.StatusCode, status.ErrorData, status.Category));
        } else {
            Debug.Log (string.Format("DateTime {0}, In RemoveChannelsFromCG, result: {1}", DateTime.UtcNow, result.Message));
        }
    });
The RemoveChannelsFromChannelGroup() does not return actionable data, be sure to check the status object on the outcome of the operation by checking the status.IsError().

Requires Stream Controller add-on XRequires that the Stream Controller add-on is enabled for your key. See this page on enabling add-on features on your keys:

http://www.pubnub.com/knowledge-base/discussion/644/how-do-i-enable-add-on-features-for-my-keys.
This function removes the channel group.
Deleting Channel Group is accomplished by using the following method(s) in the Unity V4 SDK:
  1. ParameterTypeRequiredDescription
    ChannelGroupstringYesSpecifies ChannelGroup to remove.
    QueryParamDictionary<string, string>OptionalQueryParam accepts a Dictionary object, the keys and values are passed as the query string parameters of the URL called by the API.
    AsyncPNCallbackOptionalPNCallback of type PNChannelGroupsDeleteGroupResult.
pubnub.DeleteChannelGroup()
    .ChannelGroup("family")
    .Async((result1, status1) => {
        if(status1.Error){
            Debug.Log (string.Format("In Example, DeleteChannelsFromChannelGroup Error: {0} {1} {2}", status1.StatusCode, status1.ErrorData, status1.Category));
        } else {
            Debug.Log (string.Format("DateTime {0}, In Example DeleteChannelsFromChannelGroup, result: {1}", DateTime.UtcNow, result1.Message));
        }
    });

The DeleteChannelGroup() does not return actionable data, be sure to check the status object on the outcome of the operation by checking the status.IsError().