MetaSoul

Loading...
Searching...
No Matches
ESIOClientComponent.h
Go to the documentation of this file.
1#pragma once
2
3#include "ESMessageConvert.h"
4#include "Components/ActorComponent.h"
5#include "EmoShapeSubSystem/EmoShapeIOClient/Public/ESIONative.h"
6#include "Runtime/Engine/Classes/Engine/LatentActionManager.h"
7#include "ESIOClientComponent.generated.h"
8
9 class UESJsonObject;
10 DECLARE_DYNAMIC_MULTICAST_DELEGATE(FEmoShapeEventSignature);
11 DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FEmoShapeSocketEventSignature, FString, Namespace);
12 DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FEmoShapeOpenEventSignature, FString, SessionId, bool, bIsReconnection);
13 DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FEmoShapeCloseEventSignature, TEnumAsByte<EEmoShapeIOConnectionCloseReason>, Reason);
14 DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FEmoShapeEventJsonSignature, FString, EventName, class UESJsonValue*, EventData);
15 DECLARE_DYNAMIC_MULTICAST_DELEGATE_ThreeParams(FEmoShapeConnectionProblemSignature, int32, Attempts, int32, NextAttemptInMs, float, TimeSinceConnected);
16
17//For Direct Delegate Event Bind
18 DECLARE_DYNAMIC_DELEGATE_OneParam(FEmoShapeJsonValueSignature, UESJsonValue*, EventData);
19
20UCLASS(BlueprintType, ClassGroup= "Networking", meta=(BlueprintSpawnableComponent))
21class EMOSHAPESUBSYSTEM_API UESIOClientComponent : public UActorComponent
22{
23 GENERATED_UCLASS_BODY()
24
25 public:
26
27//Async events
28
30 UPROPERTY(BlueprintAssignable, Category = "EmoShapeIO Events")
31 FEmoShapeEventJsonSignature OnGenericEvent;
32
34 UPROPERTY(BlueprintAssignable, Category = "EmoShapeIO Events")
35 FEmoShapeOpenEventSignature OnConnected;
36
41 UPROPERTY(BlueprintAssignable, Category = "EmoShapeIO Events")
42 FEmoShapeCloseEventSignature OnDisconnected;
43
50 UPROPERTY(BlueprintAssignable, Category = "EmoShapeIO Events")
51 FEmoShapeConnectionProblemSignature OnConnectionProblems;
52
54 UPROPERTY(BlueprintAssignable, Category = "EmoShapeIO Events")
55 FEmoShapeSocketEventSignature OnSocketNamespaceConnected;
56
58 UPROPERTY(BlueprintAssignable, Category = "EmoShapeIO Events")
59 FEmoShapeSocketEventSignature OnSocketNamespaceDisconnected;
60
62 UPROPERTY(BlueprintAssignable, Category = "EmoShapeIO Events")
63 FEmoShapeEventSignature OnFail;
64
65
69 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "EmoShapeIO Connection Properties")
70 FEmoShapeConnectParams URLParams;
71
75 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "EmoShapeIO Connection Properties")
76 bool bForceTLS;
77
83 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "EmoShapeIO Connection Properties")
84 bool bUnbindEventsOnDisconnect;
85
93 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "EmoShapeIO Connection Properties")
94 bool bShouldVerifyTLSCertificate;
95
97 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "EmoShapeIO Connection Properties")
98 bool bShouldAutoConnect;
99
101 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "EmoShapeIO Connection Properties")
102 int32 ReconnectionDelayInMs;
103
108 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "EmoShapeIO Connection Properties")
109 int32 MaxReconnectionAttempts;
110
112 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "EmoShapeIO Connection Properties")
113 float ReconnectionTimeout;
114
115 FDateTime TimeWhenConnectionProblemsStarted;
116
117 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "EmoShapeIO Connection Properties")
118 bool bVerboseConnectionLog;
119
120
121 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "EmoShapeIO Scope Properties")
122 bool bLimitConnectionToGameWorld;
123
130 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "EmoShapeIO Scope Properties")
131 bool bPluginScopedConnection;
132
134 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "EmoShapeIO Scope Properties")
135 FString PluginScopedId;
136
137 UPROPERTY(BlueprintReadOnly, Category = "EmoShapeIO Connection Properties")
138 bool bIsConnected;
139
141 UPROPERTY(BlueprintReadOnly, Category = "EmoShapeIO Connection Properties")
142 FString SessionId;
143
144 UPROPERTY(BlueprintReadOnly, Category = "EmoShapeIO Connection Properties")
145 bool bIsHavingConnectionProblems;
146
148 UPROPERTY(BlueprintReadOnly, Category = "EmoShapeIO Connection Properties")
149 bool bStaticallyInitialized;
150
161 UFUNCTION(BlueprintCallable, Category = "EmoShapeIO Functions")
162 void Connect( const FString& InAddressAndPort,
163 const FString& InPath = TEXT("socket.io"),
164 UESJsonObject* Query = nullptr,
165 UESJsonObject* Headers = nullptr);
166
172 UFUNCTION(BlueprintCallable, Category = "EmoShapeIO Functions")
173 void ConnectWithParams(const FEmoShapeConnectParams& InURLParams);
174
182 UFUNCTION(BlueprintCallable, Category = "EmoShapeIO Functions")
183 void Disconnect();
184
185 void SyncDisconnect();
186
190 UFUNCTION(BlueprintCallable, Category = "EmoShapeIO Functions")
191 void JoinNamespace(const FString& Namespace);
192
196 UFUNCTION(BlueprintCallable, Category = "EmoShapeIO Functions")
197 void LeaveNamespace(const FString& Namespace);
198
199 //
200 //Blueprint Functions
201 //
202
210 UFUNCTION(BlueprintCallable, Category = "EmoShapeIO Functions")
211 void Emit(const FString& EventName, UESJsonValue* Message = nullptr, const FString& Namespace = TEXT("/"));
212
222 UFUNCTION(BlueprintCallable, Category = "EmoShapeIO Functions", meta = (WorldContext = "WorldContextObject"))
223 void EmitWithCallBack( const FString& EventName,
224 UESJsonValue* Message = nullptr,
225 const FString& CallbackFunctionName = FString(""),
226 UObject* Target = nullptr,
227 const FString& Namespace = TEXT("/"),
228 UObject* WorldContextObject = nullptr);
229
230
240 UFUNCTION(BlueprintCallable, meta = (Latent, LatentInfo = "LatentInfo"), Category = "EmoShapeIO Functions")
241 void EmitWithGraphCallBack( const FString& EventName,
242 struct FLatentActionInfo LatentInfo,
243 UESJsonValue*& Result,
244 UESJsonValue* Message = nullptr,
245 const FString& Namespace = TEXT("/"));
246
247
248
258 UFUNCTION(BlueprintCallable, Category = "EmoShapeIO Functions")
259 void BindEventToDelegate( const FString& EventName,
260 const FEmoShapeJsonValueSignature& CallbackDelegate,
261 const FString& Namespace = TEXT("/"),
262 EEmoShapeIOThreadOverrideOption ThreadOverride = USE_DEFAULT);
263
271 UFUNCTION(BlueprintCallable, Category = "EmoShapeIO Functions")
272 void BindEventToGenericEvent(const FString& EventName, const FString& Namespace = TEXT("/"));
273
284 UFUNCTION(BlueprintCallable, Category = "EmoShapeIO Functions", meta = (WorldContext = "WorldContextObject"))
285 void BindEventToFunction( const FString& EventName,
286 const FString& FunctionName,
287 UObject* Target,
288 const FString& Namespace = TEXT("/"),
289 EEmoShapeIOThreadOverrideOption ThreadOverride = USE_DEFAULT,
290 UObject* WorldContextObject = nullptr);
291
298 UFUNCTION(BlueprintCallable, Category = "EmoShapeIO Functions")
299 void UnbindEvent(const FString& EventName, const FString& Namespace = TEXT("/"));
300
301
302 //
303 //C++ functions
304 //
305
316 void ConnectNative( const FString& InAddressAndPort,
317 const FString& InPath = TEXT("socket.io"),
318 const TSharedPtr<FJsonObject>& Query = nullptr,
319 const TSharedPtr<FJsonObject>& Headers = nullptr);
320
321
330 void EmitNative(const FString& EventName,
331 const TSharedPtr<FJsonValue>& Message = nullptr,
332 TFunction< void(const TArray<TSharedPtr<FJsonValue>>&)> CallbackFunction = nullptr,
333 const FString& Namespace = TEXT("/"));
334
343 void EmitNative(const FString& EventName,
344 const TSharedPtr<FJsonObject>& ObjectMessage = nullptr,
345 TFunction< void(const TArray<TSharedPtr<FJsonValue>>&)> CallbackFunction = nullptr,
346 const FString& Namespace = TEXT("/"));
347
356 void EmitNative(const FString& EventName,
357 const FString& StringMessage = FString(),
358 TFunction< void(const TArray<TSharedPtr<FJsonValue>>&)> CallbackFunction = nullptr,
359 const FString& Namespace = TEXT("/"));
360
369 void EmitNative(const FString& EventName,
370 const SIO_TEXT_TYPE StringMessage = TEXT(""),
371 TFunction< void(const TArray<TSharedPtr<FJsonValue>>&)> CallbackFunction = nullptr,
372 const FString& Namespace = TEXT("/"));
373
382 void EmitNative(const FString& EventName,
383 double NumberMessage,
384 TFunction< void(const TArray<TSharedPtr<FJsonValue>>&)> CallbackFunction = nullptr,
385 const FString& Namespace = TEXT("/"));
386
395 void EmitNative(const FString& EventName,
396 bool BooleanMessage,
397 TFunction< void(const TArray<TSharedPtr<FJsonValue>>&)> CallbackFunction = nullptr,
398 const FString& Namespace = TEXT("/"));
399
408 void EmitNative(const FString& EventName,
409 const TArray<uint8>& BinaryMessage,
410 TFunction< void(const TArray<TSharedPtr<FJsonValue>>&)> CallbackFunction = nullptr,
411 const FString& Namespace = TEXT("/"));
412
421 void EmitNative(const FString& EventName,
422 const TArray<TSharedPtr<FJsonValue>>& ArrayMessage,
423 TFunction< void(const TArray<TSharedPtr<FJsonValue>>&)> CallbackFunction = nullptr,
424 const FString& Namespace = TEXT("/"));
425
435 void EmitNative(const FString& EventName,
436 UStruct* Struct,
437 const void* StructPtr,
438 TFunction< void(const TArray<TSharedPtr<FJsonValue>>&)> CallbackFunction = nullptr,
439 const FString& Namespace = TEXT("/"));
440
449 void OnNativeEvent( const FString& EventName,
450 TFunction< void(const FString&, const TSharedPtr<FJsonValue>&)> CallbackFunction,
451 const FString& Namespace = TEXT("/"),
452 EEmoShapeIOThreadOverrideOption ThreadOverride = USE_DEFAULT);
453
461 void OnBinaryEvent( const FString& EventName,
462 TFunction< void(const FString&, const TArray<uint8>&)> CallbackFunction,
463 const FString& Namespace = TEXT("/"));
464
465
467 void StaticInitialization(UObject* WorldContextObject, bool bValidOwnerWorld);
468
469 virtual void InitializeComponent() override;
470 virtual void UninitializeComponent() override;
471 virtual void BeginPlay() override;
472
473 ~UESIOClientComponent();
474
475protected:
476 void SetupCallbacks();
477 void ClearCallbacks();
478 void InitializeNative();
479
480 bool CallBPFunctionWithResponse(UObject* Target, const FString& FunctionName, TArray<TSharedPtr<FJsonValue>> Response);
481 bool CallBPFunctionWithMessage(UObject* Target, const FString& FunctionName, TSharedPtr<FJsonValue> Message);
482
483 FCriticalSection AllocationSection;
484 TSharedPtr<FESIONative> NativeClient;
485};
DECLARE_DYNAMIC_MULTICAST_DELEGATE
DECLARE_DYNAMIC_MULTICAST_DELEGATE(FEmoShapeEventSignature)
DECLARE_DYNAMIC_MULTICAST_DELEGATE_ThreeParams
DECLARE_DYNAMIC_MULTICAST_DELEGATE_ThreeParams(FEmoShapeConnectionProblemSignature, int32, Attempts, int32, NextAttemptInMs, float, TimeSinceConnected)
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FEmoShapeSocketEventSignature, FString, Namespace)
DECLARE_DYNAMIC_DELEGATE_OneParam
DECLARE_DYNAMIC_DELEGATE_OneParam(FEmoShapeJsonValueSignature, UESJsonValue *, EventData)
DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams
DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FEmoShapeOpenEventSignature, FString, SessionId, bool, bIsReconnection)
ESIONative.h
SIO_TEXT_TYPE
#define SIO_TEXT_TYPE
Definition ESIONative.h:181
EEmoShapeIOThreadOverrideOption
EEmoShapeIOThreadOverrideOption
Definition ESIONative.h:18
USE_DEFAULT
@ USE_DEFAULT
Definition ESIONative.h:19
ESMessageConvert.h
FESIONative
Definition ESIONative.h:39
UESIOClientComponent
Definition ESIOClientComponent.h:22
UESJsonObject
Definition ESJsonObject.h:10
UESJsonValue
Definition ESJsonValue.h:63
FEmoShapeConnectParams
Definition ESMessageConvert.h:12