Watch channels
You can let users watch a given channel and its messages using the Connect()
method, without the need to join the channel as members.
Under the hood, this method allows your app to receive messages on a given channel by subscribing it to a message event listener underneath to receive all message
events of type text
. This method also returns a function you can invoke to stop receiving message
events and unsubscribe from the channel.
Method signature
- Blueprint
- C++ / Input parameters
Channel->Connect(FOnPubnubChannelMessageReceived MessageCallback);
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
MessageCallback | FOnPubnubChannelMessageReceived | Yes | n/a | Callback function passed as a parameter. It defines the custom behavior to be executed whenever someone sends a message on the given channel. |
Output
This method doesn't return any value.
Basic usage
Start receiving messages on the support
channel.
#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");
UPubnubChannel* Channel = Chat->GetChannel("support");
// Create a pubnub response delegate
// you MUST implement your own callback function to handle the response
FOnPubnubChannelMessageReceived MessageResponse;
MessageResponse.BindDynamic(this, &AMyActor::OnMessageResponseReceived);
show all 16 linesOther examples
Stop receiving messages on the support
channel.
Channel->Disconnect();