Channel Groups API for AngularJS 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

Maximum number of channels

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

This function adds channels to a channel group.

Method(s)

Adding Channels is accomplished by using the following method(s) in the AngularJS SDK:

Note

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

1Pubnub.channelGroups.addChannels({Array channels, String channelGroup},Function callback)
* required
ParameterDescription
channels *
Type: Array
The channel to add to the channel group.
channelGroup *
Type: String
The channelGroup to add the channels to.
callback
Type: Function
Executes on a successful/unsuccessful addChannels.

Sample code

1Pubnub.channelGroups.addChannels(
2 {
3 channels: ['ch1', 'ch2'],
4 channelGroup: "myChannelGroup"
5 },
6 function(status) {
7 if (status.error) {
8 console.log("operation failed w/ status: ", status);
9 } else {
10 console.log("operation done!");
11 }
12 }
13);

Response

1{
2 error: false,
3 operation: "PNAddChannelsToGroupOperation",
4 statusCode: 200
5}

List channels in a channel group

Requires Stream Controller add-on

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

This function lists all channels in a channel group.

Method(s)

Use the following method in the AngularJS SDK:

1Pubnub.channelGroups.listChannels({String channelGroup},Function callback)
* required
ParameterDescription
channelGroup *
Type: String
The channel group for which to list channels.
callback
Type: Function
Executes on a successful/unsuccessful listChannels.

Sample code

1// assuming an intialized Pubnub instance already exists
2Pubnub.channelGroups.listChannels(
3 {
4 channelGroup: "myChannelGroup"
5 },
6 function(status, response) {
7 if (status.error) {
8 console.log("operation failed w/ error:", status);
9 return;
10 }
11
12 console.log("listing push channel for device");
13 response.channels.forEach( function(channel) {
14 console.log(channel);
15 });
show all 17 lines

Response

1// Example of Status
2{
3 error: false,
4 operation: "PNChannelsForGroupOperation",
5 statusCode: 200
6}
7
8// Example of Response
9{
10 channels: ["ch1", "ch2"]
11}

Remove channels from a channel group

Requires Stream Controller add-on

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

This function removes channels from a channel group.

Method(s)

Use the following method in the AngularJS SDK:

1Pubnub.channelGroups.removeChannels({Array channels, String channelGroup},Function callback)
* required
ParameterDescription
channels *
Type: Array
The channels to remove from the channel group.
channelGroup *
Type: String
The channel group from which to remove the channels.
callback
Type: Function
Executes on a successful/unsuccessful removeChannels.

Sample code

1// assuming an initialized Pubnub instance already exists
2Pubnub.channelGroups.removeChannels(
3 {
4 channels: ["son"],
5 channelGroup: "family"
6 },
7 function (status) {
8 if (status.error) {
9 console.log("operation failed w/ error:", status);
10 } else {
11 console.log("operation done!");
12 }
13 }
14);

Response

1{
2 error: false,
3 operation: "PNRemoveChannelsFromGroupOperation",
4 statusCode: 200
5}

Delete a channel group

Requires Stream Controller add-on

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

This function deletes a channel group.

Method(s)

Use the following method in the AngularJS SDK:

1Pubnub.channelGroups.deleteGroup({String channelGroup},Function callback)
* required
ParameterDescription
channelGroup *
Type: String
The channel group to delete.
callback
Type: Function
Executes on a successful/unsuccessful deleteGroup.

Sample code

1Pubnub.channelGroups.deleteGroup(
2 {
3 channelGroup: "family"
4 },
5 function (status) {
6 if (status.error) {
7 console.log("operation failed w/ error:", status);
8 } else {
9 console.log("operation done!");
10 }
11 }
12);

Response

1{
2 error: false,
3 operation: "PNRemoveGroupOperation",
4 statusCode: 200
5}
Last updated on