Channel Groups API for Unreal 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
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 adds a channel to a channel group.
Method(s)
Adding Channels
is accomplished by using the following method(s) in the Unreal SDK:
Maximum number of channels
200 channels
can be added to the channel group
per API call.
- Blueprint
- C++
PubnubSubsystem->AddChannelToGroup(
FString Channel,
FString ChannelGroup
);
Parameter | Description |
---|---|
Channel *Type: FString | The channel to add to the channel group. |
ChannelGroup *Type: FString | The channel group to add the channels to. |
Basic Usage
Reference code
This example is a self-contained code snippet ready to be run. It includes necessary imports and executes methods with console logging. Use it as a reference when working with other examples in this document.
MyGameMode.h
// NOTE: This example requires correct PubnubSDK configuration in plugins settings and adding "PubnubLibrary" to PublicDependencyModuleNames in your build.cs
// More info in the documentation: https://www.pubnub.com/docs/sdks/unreal/api-reference/configuration
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/GameModeBase.h"
#include "MyGameMode.generated.h"
/**
*
*/
UCLASS()
//Replace MYPROJECT with name of your project
class MYPROJECT_API AMyGameMode : public AGameModeBase
show all 21 linesMyGameMode.cpp
#include "MyGameMode.h"
#include "PubnubSubsystem.h"
#include "Kismet/GameplayStatics.h"
void AMyGameMode::AddChannelToGroupExample()
{
// Get PubnubSubsystem from the game instance
UGameInstance* GameInstance = UGameplayStatics::GetGameInstance(this);
UPubnubSubsystem* PubnubSubsystem = GameInstance->GetSubsystem<UPubnubSubsystem>();
// Ensure user ID is set
PubnubSubsystem->SetUserID("my_user_id");
FString Channel = "randomChannel";
FString ChannelGroup = "myChannelGroup";
show all 20 linesReturns
This method doesn't have any return value.
List Channels
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)
- Blueprint
- C++
Response variants
You can also call the ListChannelsFromGroup_JSON()
variant of this method to get an FOnPubnubResponse
which contains pure JSON.
Response variants
You can also call the ListChannelsFromGroup_JSON()
variant of this method to get an FOnPubnubResponse
which contains pure JSON.
PubnubSubsystem->ListChannelsFromGroup(
FString ChannelGroup,
FOnListChannelsFromGroupResponse OnListChannelsResponse
);
Parameter | Description |
---|---|
ChannelGroup *Type: FString | The channel group to list the channels of. |
OnListChannelsResponse * | The callback function used to handle the result. |
Basic Usage
#include "Kismet/GameplayStatics.h"
#include "PubnubSubsystem.h"
UGameInstance* GameInstance = UGameplayStatics::GetGameInstance(this);
UPubnubSubsystem* PubnubSubsystem = GameInstance->GetSubsystem<UPubnubSubsystem>();
FString Channel = "randomChannel";
FString ChannelGroup = "myChannelGroup";
// Create a pubnub response delegate
// you MUST implement your own callback function to handle the response
FOnListChannelsFromGroupResponse OnListChannelsResponse;
OnListChannelsResponse.BindDynamic(this, &AMyActor::OnListChannelsResponse);
// Add channel to channel group
show all 16 linesReturns
This method returns the FOnListChannelsFromGroupResponse
struct.
FOnListChannelsFromGroupResponse
Field | Type | Description |
---|---|---|
Error | bool | Whether the operation resulted in an error. |
Status | int | HTTP code of the result of the operation. |
Channels | TArray<FString>& | An array of channel names of all the channels of the channel group. |
JSON response
{
"error":false,
"payload":{
"channels":[],
"group":"my_channel"
},
"service":"channel-registry",
"status":200
}
Remove Channels
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)
- Blueprint
- C++
PubnubSubsystem->RemoveChannelFromGroup(
FString Channel,
FString ChannelGroup
);
Parameter | Description |
---|---|
ChannelGroup *Type: FString | The channel group to remove the channel from. |
Channel *Type: FString | The channel to remove from the channel group. |
Basic Usage
#include "Kismet/GameplayStatics.h"
#include "PubnubSubsystem.h"
UGameInstance* GameInstance = UGameplayStatics::GetGameInstance(this);
UPubnubSubsystem* PubnubSubsystem = GameInstance->GetSubsystem<UPubnubSubsystem>();
FString Channel = "randomChannel";
FString ChanelGroup = "myChannelGroup";
// Remove channel from channel group
PubnubSubsystem->RemoveChannelFromGroup(Channel, ChannelGroup);
Returns
This method doesn't have any return value.
Delete 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 channel group.
Method(s)
- Blueprint
- C++
PubnubSubsystem->RemoveChannelGroup(
String ChannelGroup
);
Parameter | Description |
---|---|
ChannelGroup *Type: FString | The channel group to remove. |
Basic Usage
#include "Kismet/GameplayStatics.h"
#include "PubnubSubsystem.h"
UGameInstance* GameInstance = UGameplayStatics::GetGameInstance(this);
UPubnubSubsystem* PubnubSubsystem = GameInstance->GetSubsystem<UPubnubSubsystem>();
FString ChanelGroup = "myChannelGroup";
// Remove channel group
PubnubSubsystem->RemoveChannelGroup(ChannelGroup);
Returns
This method doesn't have any return value.