SelectWebWorker Channel Groups API Reference for Realtime Apps

These docs are for version 3.16.5 of the WebWorker SDK. To check out the docs for the latest version Click Here.
 

PubNub 4.0 for JavaScript is our latest and greatest! Please click here for our PubNub 4.0 for JavaScript docs and SDK.

PubNub 3.x for WebWorker will encounter End Of Life (EOL) July 1st, 2017. All users currently on 3.x should begin migrating to 4.x. The 3.x SDK will continue to work. We will no longer support it and if you run into an issue, we will request that you upgrade to the latest version before solving the issue.

If you have questions about the PubNub for JavaScript 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 WebWorker SDK:
  1. ParameterTypeRequiredDescription
    channelString/Comma separated list/ArrayYesThe channel to add to the channel group.
    channel_groupStringYesThe channelGroup to add the channels to.
    callbackFunctionOptionalThis callback is called on success event.
    errorFunctionOptionalThis callback is called on an error event.
var channelGroup = "family"; 
pubnub.channel_group_add_channel({
	callback : function(m,e,c,d,f){
		console.log(JSON.stringify(m, null, 4));
	},
	error : function (error) {
		// Handle error here
		console.log(JSON.stringify(error));
	},
	channel_group: channelGroup,
	channel: "wife"
});
{
    "service" : "channel-registry",
    "status"  : 200,
    "error"   : false,
    "message" : "OK"
}

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 WebWorker SDK:
  1. ParameterTypeRequiredDescription
    channel_group StringYesChannel Group to list the channel(s) of.
    callbackFunctionOptionalThis callback is called on success event.
    errorFunctionOptionalThis callback is called on an error event.
var channelGroup = "family"; 
pubnub.channel_group_list_channels({
	channel_group: channelGroup,
	callback : function(m,e,c,d,f){
		console.log(JSON.stringify(m, null, 4));
	},
	error : function (error) {
		// Handle error here
		console.log(JSON.stringify(error));
	}
});

{
	"status" : 200,
	"payload" : {
		"channels" : ["hi"], 
		"group" : "abcd"
	},
	"service" : "channel-registry",
	"error" : False
}

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 WebWorker SDK:
  1. ParameterTypeRequiredDescription
    channelStringYesThe channel to remove from the channel group.
    channel_groupStringYesThe channelGroup to remove the channels from.
    callbackFunctionOptionalThis callback is called on success event.
    errorFunctionOptionalThis callback is called on an error event.
Removing channels :
var channelGroup = "family"; 
pubnub.channel_group_remove_channel({
	callback : function(m,e,c,d,f){
		console.log(JSON.stringify(m, null, 4));
	},
	error : function (error) {
		// Handle error here
		console.log(JSON.stringify(error));
	},
	channel: "son",
	channel_group: channelGroup
});

{
	"status" : 200,
	"message" : "OK",
	"service" : "channel-registry",
	"error" : False
}

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 WebWorker SDK:
  1. ParameterTypeRequiredDescription
    channel_groupStringYesThe channelGroup to remove.
    callbackFunctionYesThis callback is called on success event.
    errorFunctionOptionalThis callback is called on an error event.
Deleting Channel Group :
var channelGroup = "family"; 
pubnub.channel_group_remove_group({
	callback : function(m,e,c,d,f){
		console.log(JSON.stringify(m, null, 4));
	},
	error : function (error) {
        // Handle error here
        console.log(JSON.stringify(error));
    },
	channel_group: channelGroup
});

{
	"status" : 200,
	"message" : "OK",
	"service" : "channel-registry",
	"error" : False
}