MetaSoul

Loading...
Searching...
No Matches
ESIONative.h
Go to the documentation of this file.
1#pragma once
2
3#include "EmoShapeSubSystem/EmoShapeIOLib/Public/sio_client.h"
4#include "EmoShapeSubSystem/EmoShapeJson/Public/ESJsonObject.h"
5#include "EmoShapeSubSystem/EmoShapeJson/Public/ESJsonValue.h"
6#include "ESMessageConvert.h"
7#include "CoreMinimal.h"
8
9UENUM(BlueprintType)
10enum EEmoShapeIOConnectionCloseReason
11{
12 CLOSE_REASON_NORMAL,
13 CLOSE_REASON_DROP
14};
15
16UENUM(BlueprintType)
17enum EEmoShapeIOThreadOverrideOption
18{
19 USE_DEFAULT,
20 USE_GAME_THREAD,
21 USE_NETWORK_THREAD
22};
23
24//Used in early (pre-connection) binds and maintaining map if re-setting connection type
25 struct FEmoShapeIOBoundEvent
26{
27 TFunction< void(const FString&, const TSharedPtr<FJsonValue>&)> Function;
28 FString Namespace;
29 EEmoShapeIOThreadOverrideOption ThreadOption;
30
31 FEmoShapeIOBoundEvent()
32 {
33 Namespace = TEXT("/");
34 ThreadOption = USE_DEFAULT;
35 }
36};
37
38 class EMOSHAPESUBSYSTEM_API FESIONative
39{
40 public:
41
43 FESIONative(const bool bForceTLSMode = false, const bool bShouldVerifyTLSCertificate = false);
44
45 //Native Callbacks
46 TFunction<void(const FString& SessionId)> OnConnectedCallback; //TFunction<void(const FString& SessionId)>
47 TFunction<void(const EEmoShapeIOConnectionCloseReason Reason)> OnDisconnectedCallback; //TFunction<void(const EEmoShapeIOConnectionCloseReason Reason)>
48 TFunction<void(const FString& Namespace)> OnNamespaceConnectedCallback; //TFunction<void(const FString& Namespace)>
49 TFunction<void(const FString& Namespace)> OnNamespaceDisconnectedCallback; //TFunction<void(const FString& Namespace)>
50 TFunction<void(const uint32 AttemptCount, const uint32 DelayInMs)> OnReconnectionCallback;
51 TFunction<void()> OnFailCallback;
52
53 //Map for all native functions bound to this socket
54 TMap<FString, FEmoShapeIOBoundEvent> EventFunctionMap;
55
57 FEmoShapeConnectParams URLParams;
58
60 uint32 MaxReconnectionAttempts;
61
63 uint32 ReconnectionDelay;
64
66 bool bIsConnected;
67
69 FString SessionId;
70
71 //This will remain valid even after we disconnect. Replaced on disconnect.
72 FString LastSessionId;
73
75 bool VerboseLog;
76
78 bool bCallbackOnGameThread;
79
81 bool bIsSetupForTLS;
82
84 bool bForceTLSUse;
85
87 bool bUsingTLSCertVerification;
88
90 bool bUnbindEventsOnDisconnect;
91
99 void Connect(const FString& InAddressAndPort);
100
110 void Connect(const FEmoShapeConnectParams& ConnectParams);
111
115 void JoinNamespace(const FString& Namespace);
116
120 void LeaveNamespace(const FString& Namespace);
121
127 void Disconnect();
128
129 void SyncDisconnect();
130
131 void ClearAllCallbacks();
132
141 void Emit(
142 const FString& EventName,
143 const TSharedPtr<FJsonValue>& Message = nullptr,
144 TFunction< void(const TArray<TSharedPtr<FJsonValue>>&)> CallbackFunction = nullptr,
145 const FString& Namespace = TEXT("/"));
146
155 void Emit(
156 const FString& EventName,
157 const TSharedPtr<FJsonObject>& ObjectMessage = nullptr,
158 TFunction< void(const TArray<TSharedPtr<FJsonValue>>&)> CallbackFunction = nullptr,
159 const FString& Namespace = TEXT("/"));
160
169 void Emit(
170 const FString& EventName,
171 const FString& StringMessage = FString(),
172 TFunction< void(const TArray<TSharedPtr<FJsonValue>>&)> CallbackFunction = nullptr,
173 const FString& Namespace = TEXT("/"));
174
175
176//flexible type allowing TEXT() passed as second param for overloaded emit
177#if !defined(SIO_TEXT_TYPE)
178 #if PLATFORM_TCHAR_IS_CHAR16
179 #define SIO_TEXT_TYPE char16_t*
180 #else
181 #define SIO_TEXT_TYPE wchar_t*
182 #endif
183#endif
184
193 void Emit(
194 const FString& EventName,
195 const SIO_TEXT_TYPE StringMessage = TEXT(""),
196 TFunction< void(const TArray<TSharedPtr<FJsonValue>>&)> CallbackFunction = nullptr,
197 const FString& Namespace = TEXT("/"));
198
207 void Emit(
208 const FString& EventName,
209 double NumberMessage,
210 TFunction< void(const TArray<TSharedPtr<FJsonValue>>&)> CallbackFunction = nullptr,
211 const FString& Namespace = TEXT("/"));
212
221 void Emit(
222 const FString& EventName,
223 bool BooleanMessage,
224 TFunction< void(const TArray<TSharedPtr<FJsonValue>>&)> CallbackFunction = nullptr,
225 const FString& Namespace = TEXT("/"));
226
235 void Emit
236 (const FString& EventName,
237 const TArray<uint8>& BinaryMessage,
238 TFunction< void(const TArray<TSharedPtr<FJsonValue>>&)> CallbackFunction = nullptr,
239 const FString& Namespace = TEXT("/"));
240
249 void Emit(
250 const FString& EventName,
251 const TArray<TSharedPtr<FJsonValue>>& ArrayMessage,
252 TFunction< void(const TArray<TSharedPtr<FJsonValue>>&)> CallbackFunction = nullptr,
253 const FString& Namespace = TEXT("/"));
254
264 void Emit(
265 const FString& EventName,
266 UStruct* Struct,
267 const void* StructPtr,
268 TFunction< void(const TArray<TSharedPtr<FJsonValue>>&)> CallbackFunction = nullptr,
269 const FString& Namespace = TEXT("/"));
270
280 void Emit(
281 const FString& EventName,
282 TFunction< void(const TArray<TSharedPtr<FJsonValue>>&)> CallbackFunction = nullptr,
283 const FString& Namespace = TEXT("/"));
284
293 void EmitRaw(
294 const FString& EventName,
295 const emoshapeio::message::list& MessageList = nullptr,
296 TFunction<void(const emoshapeio::message::list&)> CallbackFunction = nullptr,
297 const FString& Namespace = TEXT("/"));
298
307 void EmitRawBinary(
308 const FString& EventName,
309 uint8* Data,
310 int32 DataLength,
311 const FString& Namespace = TEXT("/"));
312
313
322 void OnEvent(
323 const FString& EventName,
324 TFunction< void(const FString&, const TSharedPtr<FJsonValue>&)> CallbackFunction,
325 const FString& Namespace = TEXT("/"),
326 EEmoShapeIOThreadOverrideOption CallbackThread = USE_DEFAULT);
327
337 void OnRawEvent(
338 const FString& EventName,
339 TFunction< void(const FString&, const emoshapeio::message::ptr&)> CallbackFunction,
340 const FString& Namespace = TEXT("/"),
341 EEmoShapeIOThreadOverrideOption CallbackThread = USE_DEFAULT);
342
351 void OnRawBinaryEvent(
352 const FString& EventName,
353 TFunction< void(const FString&, const TArray<uint8>&)> CallbackFunction,
354 const FString& Namespace = TEXT("/"));
355
361 void UnbindEvent(const FString& EventName, const FString& Namespace = TEXT("/"));
362
363 protected:
364
366 void ClearInternalCallbacks();
367
369 void SetupInternalCallbacks();
370
371 void RebindCurrentEventMap();
372
374 bool IsTLSURL(const FString& URL);
375
381 void SyncPrivateClientToTLSMode(const FString& URL);
382
383 void InitPrivateClient(const bool bShouldUseTlsLibraries = false, const bool bShouldVerifyTLSCertificate = false);
384
385 TSharedPtr<emoshapeio::client> PrivateClient;
386
387};
EEmoShapeIOConnectionCloseReason
EEmoShapeIOConnectionCloseReason
Definition ESIONative.h:11
CLOSE_REASON_NORMAL
@ CLOSE_REASON_NORMAL
Definition ESIONative.h:12
CLOSE_REASON_DROP
@ CLOSE_REASON_DROP
Definition ESIONative.h:13
SIO_TEXT_TYPE
#define SIO_TEXT_TYPE
Definition ESIONative.h:181
EEmoShapeIOThreadOverrideOption
EEmoShapeIOThreadOverrideOption
Definition ESIONative.h:18
USE_GAME_THREAD
@ USE_GAME_THREAD
Definition ESIONative.h:20
USE_NETWORK_THREAD
@ USE_NETWORK_THREAD
Definition ESIONative.h:21
USE_DEFAULT
@ USE_DEFAULT
Definition ESIONative.h:19
ESJsonObject.h
ESJsonValue.h
ESMessageConvert.h
FESIONative
Definition ESIONative.h:39
FESIONative::VerboseLog
bool VerboseLog
Definition ESIONative.h:75
FESIONative::bIsConnected
bool bIsConnected
Definition ESIONative.h:66
FESIONative::URLParams
FEmoShapeConnectParams URLParams
Definition ESIONative.h:57
FESIONative::OnReconnectionCallback
TFunction< void(const uint32 AttemptCount, const uint32 DelayInMs)> OnReconnectionCallback
Definition ESIONative.h:50
FESIONative::bForceTLSUse
bool bForceTLSUse
Definition ESIONative.h:84
FESIONative::bUnbindEventsOnDisconnect
bool bUnbindEventsOnDisconnect
Definition ESIONative.h:90
FESIONative::OnNamespaceConnectedCallback
TFunction< void(const FString &Namespace) OnNamespaceConnectedCallback)
Definition ESIONative.h:48
FESIONative::OnConnectedCallback
TFunction< void(const FString &SessionId) OnConnectedCallback)
Definition ESIONative.h:46
FESIONative::bCallbackOnGameThread
bool bCallbackOnGameThread
Definition ESIONative.h:78
FESIONative::SessionId
FString SessionId
Definition ESIONative.h:69
FESIONative::OnDisconnectedCallback
TFunction< void(const EEmoShapeIOConnectionCloseReason Reason)> OnDisconnectedCallback
Definition ESIONative.h:47
FESIONative::ReconnectionDelay
uint32 ReconnectionDelay
Definition ESIONative.h:63
FESIONative::bUsingTLSCertVerification
bool bUsingTLSCertVerification
Definition ESIONative.h:87
FESIONative::OnFailCallback
TFunction< void()> OnFailCallback
Definition ESIONative.h:51
FESIONative::bIsSetupForTLS
bool bIsSetupForTLS
Definition ESIONative.h:81
FESIONative::EventFunctionMap
TMap< FString, FEmoShapeIOBoundEvent > EventFunctionMap
Definition ESIONative.h:54
FESIONative::OnNamespaceDisconnectedCallback
TFunction< void(const FString &Namespace) OnNamespaceDisconnectedCallback)
Definition ESIONative.h:49
FESIONative::PrivateClient
TSharedPtr< emoshapeio::client > PrivateClient
Definition ESIONative.h:385
FESIONative::Emit
void Emit(const FString &EventName, const SIO_TEXT_TYPE StringMessage=TEXT(""), TFunction< void(const TArray< TSharedPtr< FJsonValue > > &)> CallbackFunction=nullptr, const FString &Namespace=TEXT("/"))
FESIONative::MaxReconnectionAttempts
uint32 MaxReconnectionAttempts
Definition ESIONative.h:60
FESIONative::LastSessionId
FString LastSessionId
Definition ESIONative.h:72
emoshapeio::message::list
Definition sio_message.h:411
emoshapeio::message::ptr
std::shared_ptr< message > ptr
Definition sio_message.h:37
sio_client.h
FEmoShapeConnectParams
Definition ESMessageConvert.h:12
FEmoShapeIOBoundEvent
Definition ESIONative.h:26
FEmoShapeIOBoundEvent::Function
TFunction< void(const FString &, const TSharedPtr< FJsonValue > &) Function)
Definition ESIONative.h:27
FEmoShapeIOBoundEvent::FEmoShapeIOBoundEvent
FEmoShapeIOBoundEvent()
Definition ESIONative.h:31
FEmoShapeIOBoundEvent::ThreadOption
EEmoShapeIOThreadOverrideOption ThreadOption
Definition ESIONative.h:29
FEmoShapeIOBoundEvent::Namespace
FString Namespace
Definition ESIONative.h:28