C++Windows C++Windows C++Posix C++Windows C++ Channel Groups API Reference for Realtime Apps

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 Windows C++ SDK:
  1. ParameterTypeRequiredDescription
    channel std::vector <std::string>const &YesThe channel(s) vector to add to the channel group.
    channel_group std::vector<std::string>const &YesThe channel_group to add to the channel(s).
    A future result (pubnub::futres). If transaction is successful, the response will be available via get_channel() function as one channel, a JSON object.
  2. ParameterTypeRequiredDescription
    channelstd::string const &YesThe channel(s) to add to the channel group.
    channel_groupstd::string const &YesThe channel_group to add the channel(s) to.
    A future result (pubnub::futres). If transaction is successful, the response will be available via get_channel() function as one channel, a JSON object.
const std::string channel_group("family");
//Sync
static void add_channel(pubnub::context &pn) {
  enum pubnub_res res;

  try {
    res = pn.add_channel_to_group("wife", channel_group).await();

    if (PNR_OK == res) {
      std::cout <<  pn.get_channel() << std::endl;
    } else {
      std::cout << "Failed with code " << res << std::endl;
    }
  } catch (std::exception &ex) {
    std::cout << "Exception: " << ex.what() << std::endl;
  }
}

//Lambdas
static void add_channel(pubnub::context &ipn) {
  ipn.add_channel_to_group("wife", channel_group)
    .then([=](pubnub::context &pn, pubnub_res res) {
      if (PNR_OK == res) {
        std::cout <<  pn.get_channel() << std::endl;
      } else {
        std::cout << "Failed with code " << res << std::endl;
      }
  });
}

//Functions
static void on_added(pubnub::context &pn, pubnub_res res) {
  if (PNR_OK == res) {
    std::cout <<  pn.get_channel() << std::endl;
  } else {
    std::cout << "Failed with code " << res << std::endl;
  }
}

static void add_channel(pubnub::context &ipn) {
  ipn.add_channel_to_group("wife", channel_group).then(on_added);
}
{
    "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 Windows C++ SDK:
  1. ParameterTypeRequiredDescription
    channel_groupstd::string const &Yeschannel_group to fetch the channels of.
const std::string channel_group("family");
//Sync
static void list_channels(pubnub::context &pn) {
  enum pubnub_res res;

  try {
    res = pn.list_channel_group(channel_group).await();

    if (PNR_OK == res) {
      std::cout <<  pn.get_channel() << std::endl;
    } else {
      std::cout << "Failed with code " << res << std::endl;
    }
  } catch (std::exception &ex) {
    std::cout << "Exception: " << ex.what() << std::endl;
  }
}

//Lambdas
static void list_channels(pubnub::context &ipn) {
  ipn.list_channel_group(channel_group)
    .then([=](pubnub::context &pn, pubnub_res res) {
      if (PNR_OK == res) {
        std::cout <<  pn.get_channel() << std::endl;
      } else {
        std::cout << "Failed with code " << res << std::endl;
      }
  });
}

//Functions
static void on_list_received(pubnub::context &pn, pubnub_res res) {
  if (PNR_OK == res) {
    std::cout <<  pn.get_channel() << std::endl;
  } else {
    std::cout << "Failed with code " << res << std::endl;
  }
}

static void list_channels(pubnub::context &ipn) {
  ipn.list_channel_group(channel_group).then(on_list_received);
}

{
	"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 Windows C++ SDK:
  1. ParameterTypeRequiredDescription
    channel_groupstd::string const &YesSpecifies channel_group to remove the channels from.
    channelstd::string const &YesThe channel to remove from the channel group.
Removing channels :
const std::string channel_group("family");
//Sync
static void remove_channel(pubnub::context &pn) {
  enum pubnub_res res;

  try {
    res = pn.remove_channel_from_group("son", channel_group).await();

    if (PNR_OK == res) {
      std::cout <<  pn.get_channel() << std::endl;
    } else {
      std::cout << "Failed with code " << res << std::endl;
    }
  } catch (std::exception &ex) {
    std::cout << "Exception: " << ex.what() << std::endl;
  }
}

//Lambdas

static void remove_channel(pubnub::context &ipn) {
  ipn.remove_channel_from_group("son", channel_group)
    .then([=](pubnub::context &pn, pubnub_res res) {
      if (PNR_OK == res) {
        std::cout <<  pn.get_channel() << std::endl;
      } else {
        std::cout << "Failed with code " << res << std::endl;
      }
  });
}

//Functions
static void on_removed(pubnub::context &pn, pubnub_res res) {
  if (PNR_OK == res) {
    std::cout <<  pn.get_channel() << std::endl;
  } else {
    std::cout << "Failed with code " << res << std::endl;
  }
}

static void remove_channel(pubnub::context &ipn) {
  ipn.remove_channel_from_group("son", channel_group).then(on_removed);
}

{
	"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 Windows C++ SDK:
  1. ParameterTypeRequiredDescription
    channel_groupstd::string const &YesSpecifies channel_group to remove.
Deleting Channel Group :
const std::string channel_group("family");
//Sync
static void remove_group(pubnub::context &pn) {
  enum pubnub_res res;

  try {
    res = pn.remove_channel_group(channel_group).await();

    if (PNR_OK == res) {
      std::cout <<  pn.get_channel() << std::endl;
    } else {
      std::cout << "Failed with code " << res << std::endl;
    }
  } catch (std::exception &ex) {
    std::cout << "Exception: " << ex.what() << std::endl;
  }
}
 
//Lambdas
static void remove_group(pubnub::context &ipn) {
  ipn.remove_channel_group(channel_group)
    .then([=](pubnub::context &pn, pubnub_res res) {
      if (PNR_OK == res) {
        std::cout <<  pn.get_channel() << std::endl;
      } else {
        std::cout << "Failed with code " << res << std::endl;
      }
  });
}
 
//Functions
static void on_group_removed(pubnub::context &pn, pubnub_res res) {
  if (PNR_OK == res) {
    std::cout <<  pn.get_channel() << std::endl;
  } else {
    std::cout << "Failed with code " << res << std::endl;
  }
}

static void remove_group(pubnub::context &ipn) {
  ipn.remove_channel_group(channel_group).then(on_group_removed);
}

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