Expose all the callback events, hook up connect/disconnect events in example

This commit is contained in:
Chris Marsh 2017-08-16 11:31:54 -07:00
parent bd995f047d
commit 432166ef1d
3 changed files with 30 additions and 5 deletions

View file

@ -11,13 +11,16 @@ static void ReadyHandler() {
UE_LOG(Discord, Log, TEXT("Discord connected")); UE_LOG(Discord, Log, TEXT("Discord connected"));
if (self) { if (self) {
self->IsConnected = true; self->IsConnected = true;
self->OnConnected.Broadcast();
} }
} }
static void DisconnectHandler(int errorCode, const char* message) { static void DisconnectHandler(int errorCode, const char* message) {
UE_LOG(Discord, Log, TEXT("Discord disconnected (%d): %s"), errorCode, message); auto msg = FString(message);
UE_LOG(Discord, Log, TEXT("Discord disconnected (%d): %s"), errorCode, *msg);
if (self) { if (self) {
self->IsConnected = false; self->IsConnected = false;
self->OnDisconnected.Broadcast(errorCode, msg);
} }
}; };

View file

@ -8,6 +8,12 @@
DECLARE_LOG_CATEGORY_EXTERN(Discord, Log, All); DECLARE_LOG_CATEGORY_EXTERN(Discord, Log, All);
DECLARE_DYNAMIC_MULTICAST_DELEGATE(FDiscordConnected);
DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FDiscordDisconnected, int, errorCode, const FString&, errorMessage);
DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FDiscordErrored, int, errorCode, const FString&, errorMessage);
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FDiscordJoin, const FString&, joinSecret);
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FDiscordSpectate, const FString&, spectateSecret);
/** /**
* *
*/ */
@ -18,15 +24,31 @@ class DISCORDRPC_API UDiscordRpc : public UObject
public: public:
UFUNCTION(BlueprintCallable, meta = (DisplayName = "Discord initialize connection", Keywords = "Discord rpc"), Category = "Discord") UFUNCTION(BlueprintCallable, meta = (DisplayName = "Initialize connection", Keywords = "Discord rpc"), Category = "Discord")
void Initialize(const FString& applicationId, bool autoRegister); void Initialize(const FString& applicationId, bool autoRegister);
UFUNCTION(BlueprintCallable, meta = (DisplayName = "Discord shut down connection", Keywords = "Discord rpc"), Category = "Discord") UFUNCTION(BlueprintCallable, meta = (DisplayName = "Shut down connection", Keywords = "Discord rpc"), Category = "Discord")
void Shutdown(); void Shutdown();
UFUNCTION(BlueprintCallable, meta = (DisplayName = "Discord check for callbacks", Keywords = "Discord rpc"), Category = "Discord") UFUNCTION(BlueprintCallable, meta = (DisplayName = "Check for callbacks", Keywords = "Discord rpc"), Category = "Discord")
void RunCallbacks(); void RunCallbacks();
UPROPERTY(BlueprintReadOnly, meta = (DisplayName = "Discord connected", Keywords = "Discord rpc"), Category = "Discord") UPROPERTY(BlueprintReadOnly, meta = (DisplayName = "Is Discord connected", Keywords = "Discord rpc"), Category = "Discord")
bool IsConnected; bool IsConnected;
UPROPERTY(BlueprintAssignable, meta = (DisplayName = "On connection", Keywords = "Discord rpc"), Category = "Discord")
FDiscordConnected OnConnected;
UPROPERTY(BlueprintAssignable, meta = (DisplayName = "On disconnection", Keywords = "Discord rpc"), Category = "Discord")
FDiscordDisconnected OnDisconnected;
UPROPERTY(BlueprintAssignable, meta = (DisplayName = "On error message", Keywords = "Discord rpc"), Category = "Discord")
FDiscordErrored OnErrored;
UPROPERTY(BlueprintAssignable, meta = (DisplayName = "When Discord user presses join", Keywords = "Discord rpc"), Category = "Discord")
FDiscordJoin OnJoin;
UPROPERTY(BlueprintAssignable, meta = (DisplayName = "When Discord user presses spectate", Keywords = "Discord rpc"), Category = "Discord")
FDiscordSpectate OnSpectate;
}; };