diff --git a/Source/SocketIOClient/Private/SocketIOClientComponent.cpp b/Source/SocketIOClient/Private/SocketIOClientComponent.cpp index 3d8a385..9a0c53e 100644 --- a/Source/SocketIOClient/Private/SocketIOClientComponent.cpp +++ b/Source/SocketIOClient/Private/SocketIOClientComponent.cpp @@ -7,9 +7,10 @@ #include "SIOJRequestJSON.h" #include "SocketIOClient.h" #include "Engine/Engine.h" +#include "sio_message.h" -USocketIOClientComponent::USocketIOClientComponent(const FObjectInitializer &init) : UActorComponent(init) +USocketIOClientComponent::USocketIOClientComponent(const FObjectInitializer& init) : UActorComponent(init) { bWantsInitializeComponent = true; bAutoActivate = true; @@ -21,7 +22,7 @@ USocketIOClientComponent::USocketIOClientComponent(const FObjectInitializer &ini NativeClient = nullptr; bLimitConnectionToGameWorld = true; SessionId = TEXT("Invalid"); - + //Plugin scoped utilities bPluginScopedConnection = false; PluginScopedId = TEXT("Default"); @@ -131,78 +132,78 @@ void USocketIOClientComponent::SetupCallbacks() } NativeClient->OnConnectedCallback = [this](const FString& InSocketId, const FString& InSessionId) - { - if (NativeClient.IsValid()) { - bIsConnected = true; - SocketId = InSocketId; - SessionId = InSessionId; - bool bIsReconnection = bIsHavingConnectionProblems; - bIsHavingConnectionProblems = false; - OnConnected.Broadcast(SocketId, SessionId, bIsReconnection); - - } - }; + if (NativeClient.IsValid()) + { + bIsConnected = true; + SocketId = InSocketId; + SessionId = InSessionId; + bool bIsReconnection = bIsHavingConnectionProblems; + bIsHavingConnectionProblems = false; + OnConnected.Broadcast(SocketId, SessionId, bIsReconnection); + + } + }; const FSIOCCloseEventSignature OnDisconnectedSafe = OnDisconnected; NativeClient->OnDisconnectedCallback = [OnDisconnectedSafe, this](const ESIOConnectionCloseReason Reason) - { - if (NativeClient.IsValid()) { - bIsConnected = false; - OnDisconnectedSafe.Broadcast(Reason); - } - }; + if (NativeClient.IsValid()) + { + bIsConnected = false; + OnDisconnectedSafe.Broadcast(Reason); + } + }; NativeClient->OnNamespaceConnectedCallback = [this](const FString& Namespace) - { - if (NativeClient.IsValid()) { - OnSocketNamespaceConnected.Broadcast(Namespace); - } - }; + if (NativeClient.IsValid()) + { + OnSocketNamespaceConnected.Broadcast(Namespace); + } + }; const FSIOCSocketEventSignature OnSocketNamespaceDisconnectedSafe = OnSocketNamespaceDisconnected; NativeClient->OnNamespaceDisconnectedCallback = [this, OnSocketNamespaceDisconnectedSafe](const FString& Namespace) - { - - if (NativeClient.IsValid()) { - OnSocketNamespaceDisconnectedSafe.Broadcast(Namespace); - } - }; - NativeClient->OnReconnectionCallback = [this](const uint32 AttemptCount, const uint32 DelayInMs) - { - if (NativeClient.IsValid()) - { - //First time we know about this problem? - if (!bIsHavingConnectionProblems) + + if (NativeClient.IsValid()) { - TimeWhenConnectionProblemsStarted = FDateTime::Now(); - bIsHavingConnectionProblems = true; + OnSocketNamespaceDisconnectedSafe.Broadcast(Namespace); } - - FTimespan Difference = FDateTime::Now() - TimeWhenConnectionProblemsStarted; - float ElapsedInSec = Difference.GetTotalSeconds(); - - if (ReconnectionTimeout > 0 && ElapsedInSec > ReconnectionTimeout) + }; + NativeClient->OnReconnectionCallback = [this](const uint32 AttemptCount, const uint32 DelayInMs) + { + if (NativeClient.IsValid()) { - //Let's stop trying and disconnect if we're using timeouts - Disconnect(); + //First time we know about this problem? + if (!bIsHavingConnectionProblems) + { + TimeWhenConnectionProblemsStarted = FDateTime::Now(); + bIsHavingConnectionProblems = true; + } + + FTimespan Difference = FDateTime::Now() - TimeWhenConnectionProblemsStarted; + float ElapsedInSec = Difference.GetTotalSeconds(); + + if (ReconnectionTimeout > 0 && ElapsedInSec > ReconnectionTimeout) + { + //Let's stop trying and disconnect if we're using timeouts + Disconnect(); + } + OnConnectionProblems.Broadcast(AttemptCount, DelayInMs, ElapsedInSec); } - OnConnectionProblems.Broadcast(AttemptCount, DelayInMs, ElapsedInSec); - } - }; + }; NativeClient->OnFailCallback = [this]() - { - if(NativeClient.IsValid()) { - OnFail.Broadcast(); + if (NativeClient.IsValid()) + { + OnFail.Broadcast(); + }; }; - }; } void USocketIOClientComponent::ClearCallbacks() @@ -226,7 +227,7 @@ bool USocketIOClientComponent::CallBPFunctionWithResponse(UObject* Target, const { UE_LOG(SocketIO, Log, TEXT("World is invalid, %s BP function call ignored."), *FunctionName); return false; - } + } if (World && World->bIsTearingDown) { UE_LOG(SocketIO, Log, TEXT("World tearing down, %s BP function call ignored."), *FunctionName); @@ -309,7 +310,7 @@ bool USocketIOClientComponent::CallBPFunctionWithResponse(UObject* Target, const else if (FirstParam.Equals("FString")) { FString StringValue = USIOJConvert::ToJsonString(FirstFJsonValue); - + Target->ProcessEvent(Function, &StringValue); return true; } @@ -394,7 +395,7 @@ void USocketIOClientComponent::Connect(const FString& InAddressAndPort, const FS if (!InAddressAndPort.IsEmpty()) { URLParams.AddressAndPort = InAddressAndPort; - + TSharedPtr QueryFJson; TSharedPtr HeadersFJson; @@ -412,7 +413,7 @@ void USocketIOClientComponent::Connect(const FString& InAddressAndPort, const FS URLParams.Headers = USIOMessageConvert::JsonObjectToFStringMap(HeadersFJson); URLParams.Path = InPath; } - + if (!InAuthToken.IsEmpty()) { URLParams.AuthToken = InAuthToken; @@ -433,10 +434,10 @@ void USocketIOClientComponent::ConnectWithParams(const FSIOConnectParams& InURLP NativeClient->Connect(InURLParams); } -void USocketIOClientComponent::ConnectNative(const FString& InAddressAndPort, +void USocketIOClientComponent::ConnectNative(const FString& InAddressAndPort, const FString& InPath, const FString& InAuthToken, - const TSharedPtr& Query /*= nullptr*/, + const TSharedPtr& Query /*= nullptr*/, const TSharedPtr& Headers /*= nullptr*/) { FSIOConnectParams Params; @@ -491,6 +492,38 @@ void USocketIOClientComponent::Emit(const FString& EventName, USIOJsonValue* Mes NativeClient->Emit(EventName, JsonMessage, nullptr, Namespace); } +void USocketIOClientComponent::EmitMessages(const FString& EventName, const TArray& Messages, const FString& Namespace) +{ + if (Messages.Num() <= 0) + { + NativeClient->Emit(EventName, MakeShareable(new FJsonValueNull), nullptr, Namespace); + return; + } + + sio::message::list* MessageList = new sio::message::list(); + + for (int i = 0; i < Messages.Num(); i++) + { + auto Message = Messages[i]; + TSharedPtr JsonMessage = nullptr; + + if (Message != nullptr) + { + JsonMessage = Message->GetRootValue(); + } + else + { + JsonMessage = MakeShareable(new FJsonValueNull); + } + + MessageList->push(USIOMessageConvert::ToSIOMessage(JsonMessage)); + } + + NativeClient->EmitRaw(EventName, *MessageList, nullptr, Namespace); + + delete MessageList; +} + void USocketIOClientComponent::EmitWithCallBack(const FString& EventName, USIOJsonValue* Message /*= nullptr*/, const FString& CallbackFunctionName /*= FString(TEXT(""))*/, UObject* Target /*= nullptr*/, const FString& Namespace /*= FString(TEXT("/"))*/, UObject* WorldContextObject /*= nullptr*/) { if (!CallbackFunctionName.IsEmpty()) @@ -512,13 +545,13 @@ void USocketIOClientComponent::EmitWithCallBack(const FString& EventName, USIOJs } EmitNative(EventName, JsonMessage, [&, Target, CallbackFunctionName, this](const TArray>& Response) - { - CallBPFunctionWithResponse(Target, CallbackFunctionName, Response); - }, Namespace); + { + CallBPFunctionWithResponse(Target, CallbackFunctionName, Response); + }, Namespace); } - else + else { - EmitNative(EventName, Message->GetRootValue(),nullptr,Namespace); + EmitNative(EventName, Message->GetRootValue(), nullptr, Namespace); } } @@ -534,24 +567,59 @@ void USocketIOClientComponent::EmitWithGraphCallBack(const FString& EventName, s { JsonMessage = MakeShareable(new FJsonValueNull); } - FCULatentAction *LatentAction = FCULatentAction::CreateLatentAction(LatentInfo, this); + FCULatentAction* LatentAction = FCULatentAction::CreateLatentAction(LatentInfo, this); if (LatentAction) { //emit the message and pass the LatentAction, we also pass the result reference through lambda capture NativeClient->Emit(EventName, JsonMessage, [this, LatentAction, &Result](const TArray>& Response) - { - // Finish the latent action - if (LatentAction) { - TSharedPtr FirstResponseValue = Response[0]; - USIOJsonValue* ResultObj = NewObject(); - ResultObj->SetRootValue(FirstResponseValue); - Result = ResultObj; //update the output value - LatentAction->Call(); //resume the latent action - } - }, Namespace); + // Finish the latent action + if (LatentAction) + { + TSharedPtr FirstResponseValue = Response[0]; + USIOJsonValue* ResultObj = NewObject(); + ResultObj->SetRootValue(FirstResponseValue); + Result = ResultObj; //update the output value + LatentAction->Call(); //resume the latent action + } + }, Namespace); + } +} + +void USocketIOClientComponent::EmitMessagesWithCallBack(const FString& EventName, const TArray& Messages, const FString& CallbackFunctionName, UObject* Target, const FString& Namespace, UObject* WorldContextObject) +{ + sio::message::list* MessageList = new sio::message::list(); + + for (int i = 0; i < Messages.Num(); i++) + { + auto Message = Messages[i]; + TSharedPtr JsonMessage = nullptr; + + if (Message != nullptr) + { + JsonMessage = Message->GetRootValue(); + } + else + { + JsonMessage = MakeShareable(new FJsonValueNull); + } + + MessageList->push(USIOMessageConvert::ToSIOMessage(JsonMessage)); + } + + if (CallbackFunctionName.IsEmpty()) { + NativeClient->EmitRaw(EventName, *MessageList, nullptr, Namespace); } + else { + // TODO: Update CallBPFunctionWithResponse to support NativeClient->EmitRaw. + //NativeClient->EmitRaw(EventName, *MessageList, [&, Target, CallbackFunctionName, this](const sio::message::list& Response) + // { + // CallBPFunctionWithResponse(Target, CallbackFunctionName, Response); + // }, Namespace); + } + + delete MessageList; } void USocketIOClientComponent::EmitNative(const FString& EventName, const TSharedPtr& Message /*= nullptr*/, TFunction< void(const TArray>&)> CallbackFunction /*= nullptr*/, const FString& Namespace /*= FString(TEXT("/"))*/) @@ -607,35 +675,35 @@ void USocketIOClientComponent::EmitNative(const FString& EventName, const SIO_TE void USocketIOClientComponent::BindEventToGenericEvent(const FString& EventName, const FString& Namespace) { NativeClient->OnEvent(EventName, [&](const FString& Event, const TSharedPtr& EventValue) - { - USIOJsonValue* NewValue = NewObject(); - TSharedPtr NonConstValue = EventValue; - NewValue->SetRootValue(NonConstValue); - OnGenericEvent.Broadcast(Event, NewValue); - }, Namespace); + { + USIOJsonValue* NewValue = NewObject(); + TSharedPtr NonConstValue = EventValue; + NewValue->SetRootValue(NonConstValue); + OnGenericEvent.Broadcast(Event, NewValue); + }, Namespace); } -void USocketIOClientComponent::BindEventToDelegate(const FString& EventName, - const FSIOJsonValueSignature& CallbackDelegate, +void USocketIOClientComponent::BindEventToDelegate(const FString& EventName, + const FSIOJsonValueSignature& CallbackDelegate, const FString& Namespace /*= TEXT("/")*/, ESIOThreadOverrideOption ThreadOverride /*= USE_DEFAULT*/) { const FSIOJsonValueSignature SafeCallback = CallbackDelegate; //copy for lambda ref OnNativeEvent(EventName, [&, SafeCallback](const FString& Event, const TSharedPtr& Message) - { - USIOJsonValue* Value = NewObject(); - TSharedPtr NonConstValue = Message; - Value->SetRootValue(NonConstValue); + { + USIOJsonValue* Value = NewObject(); + TSharedPtr NonConstValue = Message; + Value->SetRootValue(NonConstValue); - SafeCallback.ExecuteIfBound(Value); - }, Namespace, ThreadOverride); + SafeCallback.ExecuteIfBound(Value); + }, Namespace, ThreadOverride); } void USocketIOClientComponent::BindEventToFunction(const FString& EventName, const FString& FunctionName, - UObject* Target, + UObject* Target, const FString& Namespace /*= FString(TEXT("/"))*/, ESIOThreadOverrideOption ThreadOverride /*= USE_DEFAULT*/, UObject* WorldContextObject /*= nullptr*/) @@ -647,9 +715,9 @@ void USocketIOClientComponent::BindEventToFunction(const FString& EventName, Target = WorldContextObject; } OnNativeEvent(EventName, [&, FunctionName, Target](const FString& Event, const TSharedPtr& Message) - { - CallBPFunctionWithMessage(Target, FunctionName, Message); - }, Namespace, ThreadOverride); + { + CallBPFunctionWithMessage(Target, FunctionName, Message); + }, Namespace, ThreadOverride); } else { diff --git a/Source/SocketIOClient/Public/SocketIOClientComponent.h b/Source/SocketIOClient/Public/SocketIOClientComponent.h index 7ec2e98..e245396 100644 --- a/Source/SocketIOClient/Public/SocketIOClientComponent.h +++ b/Source/SocketIOClient/Public/SocketIOClientComponent.h @@ -13,7 +13,7 @@ DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FSIOCSocketEventSignature, FString, DECLARE_DYNAMIC_MULTICAST_DELEGATE_ThreeParams(FSIOCOpenEventSignature, FString, SocketId, FString, SessionId, bool, bIsReconnection); DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FSIOCCloseEventSignature, TEnumAsByte, Reason); DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FSIOCEventJsonSignature, FString, EventName, class USIOJsonValue*, EventData); -DECLARE_DYNAMIC_MULTICAST_DELEGATE_ThreeParams(FSIOConnectionProblemSignature, int32, Attempts, int32, NextAttemptInMs, float, TimeSinceConnected); +DECLARE_DYNAMIC_MULTICAST_DELEGATE_ThreeParams(FSIOConnectionProblemSignature, int32, Attempts, int32, NextAttemptInMs, float, TimeSinceConnected); //For Direct Delegate Event Bind DECLARE_DYNAMIC_DELEGATE_OneParam(FSIOJsonValueSignature, USIOJsonValue*, EventData); @@ -34,14 +34,14 @@ class SOCKETIOCLIENT_API USocketIOClientComponent : public UActorComponent UPROPERTY(BlueprintAssignable, Category = "SocketIO Events") FSIOCOpenEventSignature OnConnected; - /** - * Received on socket.io connection disconnected. This may never get - * called in default settings, see OnConnectionProblems event for details. + /** + * Received on socket.io connection disconnected. This may never get + * called in default settings, see OnConnectionProblems event for details. */ UPROPERTY(BlueprintAssignable, Category = "SocketIO Events") FSIOCCloseEventSignature OnDisconnected; - /** + /** * Received when connection problems arise. In default settings the * connection will keep repeating trying to reconnect an infinite * amount of times and you may never get OnDisconnected callback @@ -76,7 +76,7 @@ class SOCKETIOCLIENT_API USocketIOClientComponent : public UActorComponent bool bForceTLS; /** - * If true, all your bound events will unbind on disconnect. + * If true, all your bound events will unbind on disconnect. * Useful for cleanup if typically binding on connection and there * are no early event binds (before connection). */ @@ -84,9 +84,9 @@ class SOCKETIOCLIENT_API USocketIOClientComponent : public UActorComponent bool bUnbindEventsOnDisconnect; /** - * If using a TLS url (or if forced) and setting this to false will not verify + * If using a TLS url (or if forced) and setting this to false will not verify * the authenticity of the SSL certificate (i.e. asio::ssl::verify_none). - * + * * NOTE: Certification verification is currently not implemented; setting to true will * always fail verification. */ @@ -103,7 +103,7 @@ class SOCKETIOCLIENT_API USocketIOClientComponent : public UActorComponent /** * Number of times the connection should try before giving up. - * Default: infinity, this means you never truly disconnect, just suffer connection problems + * Default: infinity, this means you never truly disconnect, just suffer connection problems */ UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "SocketIO Connection Properties") int32 MaxReconnectionAttempts; @@ -121,8 +121,8 @@ class SOCKETIOCLIENT_API USocketIOClientComponent : public UActorComponent UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "SocketIO Scope Properties") bool bLimitConnectionToGameWorld; - /** - * Toggle which enables plugin scoped connections. + /** + * Toggle which enables plugin scoped connections. * If you enable this the connection will remain until you manually call disconnect * or close the app. The latest connection with the same PluginScopedId will use the same connection * as the previous one and receive the same events. @@ -165,11 +165,11 @@ class SOCKETIOCLIENT_API USocketIOClientComponent : public UActorComponent * */ UFUNCTION(BlueprintCallable, Category = "SocketIO Functions") - void Connect( const FString& InAddressAndPort = TEXT(""), - const FString& InPath = TEXT("socket.io"), - const FString& InAuthToken = TEXT(""), - USIOJsonObject* Query = nullptr, - USIOJsonObject* Headers = nullptr); + void Connect(const FString& InAddressAndPort = TEXT(""), + const FString& InPath = TEXT("socket.io"), + const FString& InAuthToken = TEXT(""), + USIOJsonObject* Query = nullptr, + USIOJsonObject* Headers = nullptr); /** * Connect to a socket.io server, optional method if auto-connect is set to true. @@ -181,7 +181,7 @@ class SOCKETIOCLIENT_API USocketIOClientComponent : public UActorComponent /** * Disconnect from current socket.io server. This is an asynchronous action, - * subscribe to OnDisconnected to know when you can safely continue from a + * subscribe to OnDisconnected to know when you can safely continue from a * disconnected state. * * @param AddressAndPort the address in URL format with port @@ -197,7 +197,7 @@ class SOCKETIOCLIENT_API USocketIOClientComponent : public UActorComponent UFUNCTION(BlueprintCallable, Category = "SocketIO Functions") void JoinNamespace(const FString& Namespace); - /** + /** * Leave a specified namespace. Should stop listening to events on given namespace. */ UFUNCTION(BlueprintCallable, Category = "SocketIO Functions") @@ -217,6 +217,16 @@ class SOCKETIOCLIENT_API USocketIOClientComponent : public UActorComponent UFUNCTION(BlueprintCallable, Category = "SocketIO Functions") void Emit(const FString& EventName, USIOJsonValue* Message = nullptr, const FString& Namespace = TEXT("/")); + /** + * Emit an event with a JsonValue message + * + * @param Name Event name + * @param Messages TArray of Message + * @param Namespace Namespace within socket.io + */ + UFUNCTION(BlueprintCallable, Category = "SocketIO Functions") + void EmitMessages(const FString& EventName, const TArray & Messages, const FString& Namespace = TEXT("/")); + /** * Emit an event with a JsonValue message with a callback function defined by CallBackFunctionName * @@ -227,12 +237,12 @@ class SOCKETIOCLIENT_API USocketIOClientComponent : public UActorComponent * @param Namespace Namespace within socket.io */ UFUNCTION(BlueprintCallable, Category = "SocketIO Functions", meta = (WorldContext = "WorldContextObject")) - void EmitWithCallBack( const FString& EventName, - USIOJsonValue* Message = nullptr, - const FString& CallbackFunctionName = FString(""), - UObject* Target = nullptr, - const FString& Namespace = TEXT("/"), - UObject* WorldContextObject = nullptr); + void EmitWithCallBack(const FString& EventName, + USIOJsonValue* Message = nullptr, + const FString& CallbackFunctionName = FString(""), + UObject* Target = nullptr, + const FString& Namespace = TEXT("/"), + UObject* WorldContextObject = nullptr); /** @@ -245,28 +255,43 @@ class SOCKETIOCLIENT_API USocketIOClientComponent : public UActorComponent * @param Namespace Namespace within socket.io */ UFUNCTION(BlueprintCallable, meta = (Latent, LatentInfo = "LatentInfo"), Category = "SocketIO Functions") - void EmitWithGraphCallBack( const FString& EventName, - struct FLatentActionInfo LatentInfo, - USIOJsonValue*& Result, - USIOJsonValue* Message = nullptr, - const FString& Namespace = TEXT("/")); - + void EmitWithGraphCallBack(const FString& EventName, + struct FLatentActionInfo LatentInfo, + USIOJsonValue*& Result, + USIOJsonValue* Message = nullptr, + const FString& Namespace = TEXT("/")); + /** + * Emit an event with a MessageList with a callback function defined by CallBackFunctionName + * + * @param Name Event name + * @param Message SIOJsonValue + * @param CallbackFunctionName Name of the optional callback function with signature (String, SIOJsonValue) + * @param Target Optional, defaults to caller self. Change to delegate function callback to another class. + * @param Namespace Namespace within socket.io + */ + UFUNCTION(BlueprintCallable, Category = "SocketIO Functions", meta = (WorldContext = "WorldContextObject")) + void EmitMessagesWithCallBack(const FString& EventName, + const TArray & Messages, + const FString& CallbackFunctionName = FString(""), + UObject* Target = nullptr, + const FString& Namespace = TEXT("/"), + UObject* WorldContextObject = nullptr); /** * Bind an event directly to a matching delegate. Drag off from red box or * use create event option. - * + * * @param EventName Event name * @param CallbackDelegate Delegate that needs to be bound * @param Namespace Optional namespace, defaults to default namespace * @param ThreadOverride Optional override to receive event on specified thread. Note NETWORK thread is lower latency but unsafe for a lot of blueprint use. Use with CAUTION. */ UFUNCTION(BlueprintCallable, Category = "SocketIO Functions") - void BindEventToDelegate( const FString& EventName, - const FSIOJsonValueSignature& CallbackDelegate, - const FString& Namespace = TEXT("/"), - ESIOThreadOverrideOption ThreadOverride = USE_DEFAULT); + void BindEventToDelegate(const FString& EventName, + const FSIOJsonValueSignature& CallbackDelegate, + const FString& Namespace = TEXT("/"), + ESIOThreadOverrideOption ThreadOverride = USE_DEFAULT); /** * Bind an event, then respond to it with 'OnGenericEvent' multi-cast delegate. @@ -289,12 +314,12 @@ class SOCKETIOCLIENT_API USocketIOClientComponent : public UActorComponent * @param ThreadOverride Optional override to receive event on specified thread. Note NETWORK thread is lower latency but unsafe for a lot of blueprint use. Use with CAUTION. */ UFUNCTION(BlueprintCallable, Category = "SocketIO Functions", meta = (WorldContext = "WorldContextObject")) - void BindEventToFunction( const FString& EventName, - const FString& FunctionName, - UObject* Target, - const FString& Namespace = TEXT("/"), - ESIOThreadOverrideOption ThreadOverride = USE_DEFAULT, - UObject* WorldContextObject = nullptr); + void BindEventToFunction(const FString& EventName, + const FString& FunctionName, + UObject* Target, + const FString& Namespace = TEXT("/"), + ESIOThreadOverrideOption ThreadOverride = USE_DEFAULT, + UObject* WorldContextObject = nullptr); /** * Unbind an event from whatever it was bound to (safe to call if not already bound) @@ -320,15 +345,15 @@ class SOCKETIOCLIENT_API USocketIOClientComponent : public UActorComponent * @param Headers http header as a FJsonObject with string keys and values * */ - void ConnectNative( const FString& InAddressAndPort, - const FString& InPath = TEXT("socket.io"), - const FString& InAuthToken = TEXT(""), - const TSharedPtr& Query = nullptr, - const TSharedPtr& Headers = nullptr); + void ConnectNative(const FString& InAddressAndPort, + const FString& InPath = TEXT("socket.io"), + const FString& InAuthToken = TEXT(""), + const TSharedPtr& Query = nullptr, + const TSharedPtr& Headers = nullptr); /** - * Emit an event with a JsonValue message + * Emit an event with a JsonValue message * * @param EventName Event name * @param Message FJsonValue @@ -336,9 +361,9 @@ class SOCKETIOCLIENT_API USocketIOClientComponent : public UActorComponent * @param Namespace Optional Namespace within socket.io */ void EmitNative(const FString& EventName, - const TSharedPtr& Message = nullptr, - TFunction< void(const TArray>&)> CallbackFunction = nullptr, - const FString& Namespace = TEXT("/")); + const TSharedPtr& Message = nullptr, + TFunction< void(const TArray>&)> CallbackFunction = nullptr, + const FString& Namespace = TEXT("/")); /** * (Overloaded) Emit an event with a Json Object message @@ -349,9 +374,9 @@ class SOCKETIOCLIENT_API USocketIOClientComponent : public UActorComponent * @param Namespace Optional Namespace within socket.io */ void EmitNative(const FString& EventName, - const TSharedPtr& ObjectMessage = nullptr, - TFunction< void(const TArray>&)> CallbackFunction = nullptr, - const FString& Namespace = TEXT("/")); + const TSharedPtr& ObjectMessage = nullptr, + TFunction< void(const TArray>&)> CallbackFunction = nullptr, + const FString& Namespace = TEXT("/")); /** * (Overloaded) Emit an event with a string message @@ -362,9 +387,9 @@ class SOCKETIOCLIENT_API USocketIOClientComponent : public UActorComponent * @param Namespace Optional Namespace within socket.io */ void EmitNative(const FString& EventName, - const FString& StringMessage = FString(), - TFunction< void(const TArray>&)> CallbackFunction = nullptr, - const FString& Namespace = TEXT("/")); + const FString& StringMessage = FString(), + TFunction< void(const TArray>&)> CallbackFunction = nullptr, + const FString& Namespace = TEXT("/")); /** * (Overloaded) Emit an event with a string message @@ -388,9 +413,9 @@ class SOCKETIOCLIENT_API USocketIOClientComponent : public UActorComponent * @param Namespace Optional Namespace within socket.io */ void EmitNative(const FString& EventName, - double NumberMessage, - TFunction< void(const TArray>&)> CallbackFunction = nullptr, - const FString& Namespace = TEXT("/")); + double NumberMessage, + TFunction< void(const TArray>&)> CallbackFunction = nullptr, + const FString& Namespace = TEXT("/")); /** * (Overloaded) Emit an event with a bool message @@ -401,9 +426,9 @@ class SOCKETIOCLIENT_API USocketIOClientComponent : public UActorComponent * @param Namespace Optional Namespace within socket.io */ void EmitNative(const FString& EventName, - bool BooleanMessage, - TFunction< void(const TArray>&)> CallbackFunction = nullptr, - const FString& Namespace = TEXT("/")); + bool BooleanMessage, + TFunction< void(const TArray>&)> CallbackFunction = nullptr, + const FString& Namespace = TEXT("/")); /** * (Overloaded) Emit an event with a binary message @@ -414,9 +439,9 @@ class SOCKETIOCLIENT_API USocketIOClientComponent : public UActorComponent * @param Namespace Optional Namespace within socket.io */ void EmitNative(const FString& EventName, - const TArray& BinaryMessage, - TFunction< void(const TArray>&)> CallbackFunction = nullptr, - const FString& Namespace = TEXT("/")); + const TArray& BinaryMessage, + TFunction< void(const TArray>&)> CallbackFunction = nullptr, + const FString& Namespace = TEXT("/")); /** * (Overloaded) Emit an event with an array message @@ -427,9 +452,9 @@ class SOCKETIOCLIENT_API USocketIOClientComponent : public UActorComponent * @param Namespace Optional Namespace within socket.io */ void EmitNative(const FString& EventName, - const TArray>& ArrayMessage, - TFunction< void(const TArray>&)> CallbackFunction = nullptr, - const FString& Namespace = TEXT("/")); + const TArray>& ArrayMessage, + TFunction< void(const TArray>&)> CallbackFunction = nullptr, + const FString& Namespace = TEXT("/")); /** * (Overloaded) Emit an event with an UStruct message @@ -441,10 +466,10 @@ class SOCKETIOCLIENT_API USocketIOClientComponent : public UActorComponent * @param Namespace Optional Namespace within socket.io */ void EmitNative(const FString& EventName, - UStruct* Struct, - const void* StructPtr, - TFunction< void(const TArray>&)> CallbackFunction = nullptr, - const FString& Namespace = TEXT("/")); + UStruct* Struct, + const void* StructPtr, + TFunction< void(const TArray>&)> CallbackFunction = nullptr, + const FString& Namespace = TEXT("/")); /** * Call function callback on receiving socket event. C++ only. @@ -454,9 +479,9 @@ class SOCKETIOCLIENT_API USocketIOClientComponent : public UActorComponent * @param Namespace Optional namespace, defaults to default namespace * @param ThreadOverride Optional override to receive event on specified thread. Note NETWORK thread is lower latency but unsafe for a lot of blueprint use. Use with CAUTION. */ - void OnNativeEvent( const FString& EventName, - TFunction< void(const FString&, const TSharedPtr&)> CallbackFunction, - const FString& Namespace = TEXT("/"), + void OnNativeEvent(const FString& EventName, + TFunction< void(const FString&, const TSharedPtr&)> CallbackFunction, + const FString& Namespace = TEXT("/"), ESIOThreadOverrideOption ThreadOverride = USE_DEFAULT); /** @@ -466,11 +491,11 @@ class SOCKETIOCLIENT_API USocketIOClientComponent : public UActorComponent * @param TFunction Lambda callback, raw flavor * @param Namespace Optional namespace, defaults to default namespace */ - void OnBinaryEvent( const FString& EventName, - TFunction< void(const FString&, const TArray&)> CallbackFunction, - const FString& Namespace = TEXT("/")); + void OnBinaryEvent(const FString& EventName, + TFunction< void(const FString&, const TArray&)> CallbackFunction, + const FString& Namespace = TEXT("/")); + - /** Called by SocketIOFunctionLibrary to initialize statically constructed components. */ void StaticInitialization(UObject* WorldContextObject, bool bValidOwnerWorld); @@ -479,7 +504,7 @@ class SOCKETIOCLIENT_API USocketIOClientComponent : public UActorComponent virtual void BeginPlay() override; ~USocketIOClientComponent(); - + protected: void SetupCallbacks(); void ClearCallbacks();