Manage channel updates
Update channel details and receive events whenever someone updates them.
Requires App Context
To store data about channels, you must enable App Context for your app's keyset in the Admin Portal.
Update channel details
You can edit the metadata of an existing channel with Update()
and UpdateChannel()
.
Both of them give the same output. The only difference is that you call a given method either on the Chat
(UpdateChannel()
) or the Channel
(Update()
) object. Depending on the object, these methods take a different set of input parameters - you either have to specify the channel ID you want to update or not because it's already known.
Method signature
- Blueprint
- C++ / Input parameters
-
Channel->Update()
Channel->Update(FPubnubChatChannelData ChannelData);
-
Chat->UpdateChannel()
Chat->UpdateChannel(
FString ChannelID,
FPubnubChatChannelData ChannelData
);
Parameter | Type | Required in Channel->Update() | Required in Chat->UpdateChannel() | Default | Description |
---|---|---|---|---|---|
ChannelID | FString | No | Yes | n/a | Unique channel identifier. |
ChannelData | FPubnubChatChannelData | No | No | n\a | Information about the channel. |
FPubnubChatChannelData
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
ChannelName | FString | No | n/a | Display name for the channel (must not be empty or consist only of whitespace characters). |
Description | FString | No | n/a | Channel's identifier in an external system. You can use it to match id with a similar identifier from an external database. |
CustomDataJson | FString | No | n/a | JSON providing custom data about the channel. Values must be scalar only; arrays or objects are not supported. Filtering App Context data through the custom property is not recommended in SDKs. |
Status | FString | No | n/a | Tag that lets you categorize your app channels by their current state. The tag choice is entirely up to you and depends on your use case. |
Type | FString | No | n/a | Tag that lets you categorize your app channels by their functional roles. The tag choice is entirely up to you and depends on your use case. |
Output
Type | Description |
---|---|
UPubnubChannel* | Object returning the updated channel metadata. |
Basic usage
Update the description of the support
channel.
-
Update()
#include "Kismet/GameplayStatics.h"
#include "PubnubChatSubsystem.h"
UGameInstance* GameInstance = UGameplayStatics::GetGameInstance(ContextObject);
UPubnubChatSubsystem* PubnubChatSubsystem = GameInstance->GetSubsystem<UPubnubChatSubsystem>();
UPubnubChat* Chat = PubnubChatSubsystem->InitChat("demo", "demo", "my_user");
UPubnubChannel* Channel = Chat->GetChannel("support");
// Define the channel data
FPubnubChatChannelData ChannelData;
ChannelData.Description = "Channel for CRM tickets";
Channel->Update(ChannelData); -
UpdateChannel()
#include "Kismet/GameplayStatics.h"
#include "PubnubChatSubsystem.h"
UGameInstance* GameInstance = UGameplayStatics::GetGameInstance(ContextObject);
UPubnubChatSubsystem* PubnubChatSubsystem = GameInstance->GetSubsystem<UPubnubChatSubsystem>();
UPubnubChat* Chat = PubnubChatSubsystem->InitChat("demo", "demo", "my_user");
// Define the channel data
FPubnubChatChannelData ChannelData;
ChannelData.Description = "Channel for CRM tickets";
Chat->UpdateChannel("support", ChannelData);
Get channel updates
You can receive updates when specific Channel
object(s) are edited or removed on other clients using the following methods:
StreamUpdates()
checks updates on a singleChannel
object.StreamUpdatesOn()
checks updates on aChannel
object list.
Both methods accept a callback function as an argument. The Unreal Chat SDK invokes this callback whenever someone adds, changes, or removes channel metadata.
Underneath, these methods subscribe the current user to a channel and add an objects event listener to receive all objects
events of type channel
. These methods also return the unsubscribe
function you can invoke to stop receiving objects
events and unsubscribe from the channel.
Method signature
- Blueprint
- C++ / Input parameters
-
StreamUpdates()
Channel->StreamUpdates(FOnPubnubChannelStreamUpdateReceived ChannelUpdateCallback);
-
StreamUpdatesOn()
Channel->StreamUpdatesOn(
TArray<UPubnubChannel*> Channels,
FOnPubnubChannelStreamUpdateReceived ChannelUpdateCallback
);
Parameter | Type | Required in StreamUpdates() | Required in StreamUpdatesOn() | Default | Description |
---|---|---|---|---|---|
Channels | TArray<UPubnubChannel*> | No | Yes | n/a | Array of Channel objects for which you want to get updates. |
ChannelUpdateCallback | FOnPubnubChannelStreamUpdateReceived | Yes | Yes | n/a | Callback function passed as a parameter to both methods. It defines the custom behavior to be executed when detecting channel metadata changes. |
Output
Type | Description |
---|---|
UPubnubCallbackStop* | Object on which you can call Stop() to stop receiving updates. |
Basic usage
-
StreamUpdates()
Get updates on the
support
channel.
show all 17 lines#include "Kismet/GameplayStatics.h"
#include "PubnubChatSubsystem.h"
UGameInstance* GameInstance = UGameplayStatics::GetGameInstance(this);
UPubnubChatSubsystem* PubnubChatSubsystem = GameInstance->GetSubsystem<UPubnubChatSubsystem>();
UPubnubChat* Chat = PubnubChatSubsystem ->InitChat("demo", "demo", "my_user");
// Get the channel and save the reference
UPubnubChannel* Channel = Chat->GetChannel("support");
// Create a pubnub response delegate
// you MUST implement your own callback function to handle the response
FOnPubnubChannelStreamUpdateReceived StreamUpdatesResponse;
StreamUpdatesResponse.BindDynamic(this, &AMyActor::OnChannelUpdateResponseReceived); -
StreamUpdatesOn()
Get updates on the
support
andincident-management
channels.
show all 22 lines#include "Kismet/GameplayStatics.h"
#include "PubnubChatSubsystem.h"
UGameInstance* GameInstance = UGameplayStatics::GetGameInstance(this);
UPubnubChatSubsystem* PubnubChatSubsystem = GameInstance->GetSubsystem<UPubnubChatSubsystem>();
UPubnubChat* Chat = PubnubChatSubsystem ->InitChat("demo", "demo", "my_user");
// Get the channels and save the reference
UPubnubChannel* Channel1 = Chat->GetChannel("support");
UPubnubChannel* Channel2 = Chat->GetChannel("incident-management");
TArray<UPubnubChannel*> Channels;
Channels.Add(Channel1);
Channels.Add(Channel2);
Other examples
-
StreamUpdates()
Stop listening to updates on the
support
channel.auto StopUpdates = Channel->Channel->StreamUpdates(StreamUpdatesResponse);
StopUpdates->Stop(); -
StreamUpdatesOn()
Stop listening to updates on the
support
andincident-management
channels.auto StopUpdates = Channel->StreamUpdatesOn(Channels, StreamUpdatesOnResponse);
StopUpdates->Stop();