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

Description

This function adds a channel to a channel group.

Method(s)

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

Maximum number of channels

You can add up to 200 channels to a 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

Add channels

1import PubNubVue from 'pubnub-vue';
2
3const pubnub = PubNubVue.getInstance();
4
5pubnub.channelGroups.addChannels(
6 {
7 channels: ['ch1', 'ch2'],
8 channelGroup: "myChannelGroup"
9 },
10 function(status) {
11 if (status.error) {
12 console.log("operation failed w/ status: ", status);
13 } else {
14 console.log("operation done!");
15 }
show all 17 lines

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 the channels of the channel group.

Method(s)

Listing Channels is accomplished by using the following method(s) in the Vue SDK:

1pubnub.channelGroups.listChannels({String channelGroup},Function callback)
* required
ParameterDescription
channelGroup *
Type: String
Channel Group to list the channel(s) of.
callback
Type: Function
Executes on a successful/unsuccessful listChannels.

Sample code

List channels

1import PubNubVue from 'pubnub-vue';
2
3const pubnub = PubNubVue.getInstance();
4
5// assuming an intialized PubNub instance already exists
6pubnub.channelGroups.listChannels(
7 {
8 channelGroup: "myChannelGroup"
9 },
10 function(status, response) {
11 if (status.error) {
12 console.log("operation failed w/ error:", status);
13 return;
14 }
15
show all 21 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 the channels from the channel group.

Method(s)

Removing Channels is accomplished by using the following method(s) in the Vue SDK:

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

Sample code

Remove channels

1import PubNubVue from 'pubnub-vue';
2
3const pubnub = PubNubVue.getInstance();
4
5// assuming an initialized PubNub instance already exists
6pubnub.channelGroups.removeChannels(
7 {
8 channels: ['son'],
9 channelGroup: "family"
10 },
11 function(status) {
12 if (status.error) {
13 console.log("operation failed w/ error:", status);
14 } else {
15 console.log("operation done!");
show all 18 lines

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.

Description

This function removes the channel group.

Method(s)

Deleting Channel Group is accomplished by using the following method(s) in the Vue SDK:

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

Sample code

Delete channel group

1import PubNubVue from 'pubnub-vue';
2
3const pubnub = PubNubVue.getInstance();
4
5pubnub.channelGroups.deleteGroup(
6 {
7 channelGroup: "family"
8 },
9 function(status) {
10 if (status.error) {
11 console.log("operation failed w/ error:", status);
12 } else {
13 console.log("operation done!");
14 }
15 }
show all 16 lines

Response

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