WebWebNode.jsPhoneGapReact V4JavaScriptJavaScript V4 Channel Groups API Reference for Realtime Apps

Go to Access Manager


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 JavaScript V4 SDK:
  1. ParameterTypeRequiredDescription
    Operation ArgumentsHashYesA hash of arguments.
    channelsArrayYesThe channel to add to the channel group.
    channelGroup StringYesThe channelGroup to add the channels to.
    callbackFunctionOptionalExecutes on a successful/unsuccessful addChannels.
pubnub.channelGroups.addChannels(
    {
        channels: ['ch1', 'ch2'],
        channelGroup: "myChannelGroup"
    }, 
    function(status) {
        if (status.error) {
            console.log("operation failed w/ status: ", status);
        } else {
            console.log("operation done!")
        }
    }
);
{
    error: false,
    operation: "PNAddChannelsToGroupOperation",
    statusCode: 200
}
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 JavaScript V4 SDK:
  1. ParameterTypeRequiredDescription
    Operation ArgumentsHashYesA hash of arguments.
    channelGroup StringYesChannel Group to list the channel(s) of.
    callbackFunctionOptionalExecutes on a successful/unsuccessful listChannels.
// assuming an intialized PubNub instance already exists
pubnub.channelGroups.listChannels(
    {
        channelGroup: "myChannelGroup"
    }, 
    function (status, response) {
		if (status.error) {
			console.log("operation failed w/ error:", status);
			return;
		}
		
		console.log("listing push channel for device")
		response.channels.forEach( function (channel) {
			console.log(channel)
		})
    }
);
// Example of Status
{
    error: false,
    operation: "PNChannelsForGroupOperation",
    statusCode: 200
}

// Example of Response
{
    channels: ["ch1", "ch2"]
}
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 JavaScript V4 SDK:
  1. ParameterTypeRequiredDescription
    Operation ArgumentsHashYesA hash of arguments.
    channelsArrayYesThe channel to remove from the channel group.
    channelGroup StringYesThe channelGroup to remove the channels from.
    callbackFunctionOptionalExecutes on a successful/unsuccessful removeChannels.
// assuming an initialized PubNub instance already exists
pubnub.channelGroups.removeChannels(
    {
        channels: ['son'],
        channelGroup: "family"
    },
    function (status) {
		if (status.error) {
			console.log("operation failed w/ error:", status);
        } else {
            console.log("operation done!")
        }
    }
);
{
    error: false,
    operation: "PNRemoveChannelsFromGroupOperation",
    statusCode: 200
}
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 JavaScript V4 SDK:
  1. ParameterTypeRequiredDescription
    Operation ArgumentsHashYesA hash of arguments.
    channelGroup StringYesThe channelGroup to remove.
    callbackFunctionOptionalExecutes on a successful/unsuccessful deleteGroup.
pubnub.channelGroups.deleteGroup(
    {
        channelGroup: "family"
    },
    function (status) {
        if (status.error) {
            console.log("operation failed w/ error:", status);
        } else {
            console.log("operation done!")
        }
    }
);
{
    error: false,
    operation: "PNRemoveGroupOperation",
    statusCode: 200
}

Go to Storage and Playback