Manage channel updates
Update channel metadata and receive real-time change events.
Requires App Context
Enable App Context for your keyset in the Admin Portal.
Update channel details
Edit channel metadata with Update() or UpdateChannel().
Both methods produce the same result. Call Update() on a Channel object or UpdateChannel() on the Chat object with the channel ID.
Method signature
- Blueprint
- C++ / Input parameters
-
Channel->Update()1Channel->Update(FPubnubChatChannelData ChannelData); -
Chat->UpdateChannel()1Chat->UpdateChannel(
2 FString ChannelID,
3 FPubnubChatChannelData ChannelData
4);
| Parameter | Required in Channel->Update() | Required in Chat->UpdateChannel() | Description |
|---|---|---|---|
ChannelIDType: FStringDefault: n/a | No | Yes | Unique channel identifier. |
ChannelDataType: FPubnubChatChannelDataDefault: n\a | No | No | Information about the channel. |
FPubnubChatChannelData
| Parameter | Description |
|---|---|
ChannelNameType: FStringDefault: n/a | Display name for the channel (must not be empty or consist only of whitespace characters). |
DescriptionType: FStringDefault: n/a | Channel's identifier in an external system. You can use it to match id with a similar identifier from an external database. |
CustomDataJsonType: FStringDefault: 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. |
StatusType: FStringDefault: 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. |
TypeType: FStringDefault: 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. |
Sample code
Update the description of the support channel.
-
Update()1#include "Kismet/GameplayStatics.h"
2#include "PubnubChatSubsystem.h"
3
4UGameInstance* GameInstance = UGameplayStatics::GetGameInstance(ContextObject);
5UPubnubChatSubsystem* PubnubChatSubsystem = GameInstance->GetSubsystem<UPubnubChatSubsystem>();
6
7UPubnubChat* Chat = PubnubChatSubsystem->InitChat("demo", "demo", "my_user");
8
9UPubnubChannel* Channel = Chat->GetChannel("support");
10
11// Define the channel data
12FPubnubChatChannelData ChannelData;
13ChannelData.Description = "Channel for CRM tickets";
14
15Channel->Update(ChannelData); -
UpdateChannel()1#include "Kismet/GameplayStatics.h"
2#include "PubnubChatSubsystem.h"
3
4UGameInstance* GameInstance = UGameplayStatics::GetGameInstance(ContextObject);
5UPubnubChatSubsystem* PubnubChatSubsystem = GameInstance->GetSubsystem<UPubnubChatSubsystem>();
6
7UPubnubChat* Chat = PubnubChatSubsystem->InitChat("demo", "demo", "my_user");
8
9// Define the channel data
10FPubnubChatChannelData ChannelData;
11ChannelData.Description = "Channel for CRM tickets";
12
13Chat->UpdateChannel("support", ChannelData);
Get channel updates
Receive updates when Channel objects are edited or removed:
StreamUpdates()- monitors a single channelStreamUpdatesOn()- monitors multiple channels
Both methods accept a callback invoked when channel metadata changes. They subscribe to a channel and add an objects event listener for channel events, returning an unsubscribe function.
Stream update behavior
StreamUpdates()returns the updatedChannelobject on each change (nullptrif deleted)StreamUpdatesOn()returns the complete list of monitored channels on any change
Method signature
- Blueprint
- C++ / Input parameters
-
StreamUpdates()1Channel->StreamUpdates(FOnPubnubChannelStreamUpdateReceived ChannelUpdateCallback); -
StreamUpdatesOn()1Channel->StreamUpdatesOn(
2 TArray<UPubnubChannel*> Channels,
3 FOnPubnubChannelStreamUpdateReceived ChannelUpdateCallback
4);
| Parameter | Required in StreamUpdates() | Required in StreamUpdatesOn() | Description |
|---|---|---|---|
ChannelsType: TArray<UPubnubChannel*>Default: n/a | No | Yes | Array of Channel objects for which you want to get updates. |
ChannelUpdateCallbackType: FOnPubnubChannelStreamUpdateReceivedDefault: n/a | Yes | Yes | 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. |
Sample code
-
StreamUpdates()Get updates on the
supportchannel.
show all 17 lines1#include "Kismet/GameplayStatics.h"
2#include "PubnubChatSubsystem.h"
3
4UGameInstance* GameInstance = UGameplayStatics::GetGameInstance(this);
5UPubnubChatSubsystem* PubnubChatSubsystem = GameInstance->GetSubsystem<UPubnubChatSubsystem>();
6
7UPubnubChat* Chat = PubnubChatSubsystem ->InitChat("demo", "demo", "my_user");
8
9// Get the channel and save the reference
10UPubnubChannel* Channel = Chat->GetChannel("support");
11
12// Create a pubnub response delegate
13// you MUST implement your own callback function to handle the response
14FOnPubnubChannelStreamUpdateReceived StreamUpdatesResponse;
15StreamUpdatesResponse.BindDynamic(this, &AMyActor::OnChannelUpdateResponseReceived); -
StreamUpdatesOn()Get updates on the
supportandincident-managementchannels.
show all 22 lines1#include "Kismet/GameplayStatics.h"
2#include "PubnubChatSubsystem.h"
3
4UGameInstance* GameInstance = UGameplayStatics::GetGameInstance(this);
5UPubnubChatSubsystem* PubnubChatSubsystem = GameInstance->GetSubsystem<UPubnubChatSubsystem>();
6
7UPubnubChat* Chat = PubnubChatSubsystem ->InitChat("demo", "demo", "my_user");
8
9// Get the channels and save the reference
10UPubnubChannel* Channel1 = Chat->GetChannel("support");
11UPubnubChannel* Channel2 = Chat->GetChannel("incident-management");
12
13TArray<UPubnubChannel*> Channels;
14Channels.Add(Channel1);
15Channels.Add(Channel2);
Other examples
-
StreamUpdates()Stop listening to updates on the
supportchannel.1auto StopUpdates = Channel->Channel->StreamUpdates(StreamUpdatesResponse);
2
3StopUpdates->Stop(); -
StreamUpdatesOn()Stop listening to updates on the
supportandincident-managementchannels.1auto StopUpdates = Channel->StreamUpdatesOn(Channels, StreamUpdatesOnResponse);
2
3StopUpdates->Stop();