Watch channels
Use Connect() to receive messages on a channel without joining as a member. The method subscribes to a message event listener and returns a function to disconnect.
Method signature
- Blueprint
- C++ / Input parameters
1Channel->Connect(FOnPubnubChannelMessageReceived MessageCallback);
* required
| Parameter | Description |
|---|---|
MessageCallback *Type: FOnPubnubChannelMessageReceivedDefault: 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();