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
1Channel->Connect(FOnPubnubChannelMessageReceived MessageCallback);
* required
Parameter | Description |
---|---|
MessageCallback *Type: FOnPubnubChannelMessageReceived Default: 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.
Sample code
Start receiving messages on the support
channel.
1#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
9UPubnubChannel* Channel = Chat->GetChannel("support");
10
11// Create a pubnub response delegate
12// you MUST implement your own callback function to handle the response
13FOnPubnubChannelMessageReceived MessageResponse;
14MessageResponse.BindDynamic(this, &AMyActor::OnMessageResponseReceived);
15
show all 16 linesOther examples
Stop receiving messages on the support
channel.
1Channel->Disconnect();