A Demo Project for the UnrealEngineSDK
Loading...
Searching...
No Matches
ApexAPI.h
Go to the documentation of this file.
1// Copyright 2022 PixoVR Corp. All Rights Reserved.
2
3#pragma once
4
5#include "CoreMinimal.h"
6#include "Subsystems/GameInstanceSubsystem.h"
7#include "Misc/DateTime.h"
8#include "ApexSDKDefines.h"
9#include "XAPITypes.h"
10#include "ApexTypes.h"
11#include "ApexWebSocket.h"
12#include "ApexAPI.generated.h"
13
14UENUM(BlueprintType, Category = "APEX Responses", meta = (ScriptName = "MultiUserConnectionErrorType"))
16{
17 Ping,
19 Logout,
23};
25#pragma region EventDelegates
26DECLARE_DYNAMIC_MULTICAST_DELEGATE(FOnApexWebSocketConnected);
27DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnApexWebSocketConnectFailed, const FString&, Error);
28DECLARE_DYNAMIC_MULTICAST_DELEGATE_ThreeParams(FOnApexWebSocketDisconnected, int32, StatusCode, const FString&, Reason, bool, bWasClean);
29DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnApexAuthCodeRetrieved, const FString&, AuthorizationCode);
31DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FOnApexRequestComplete, EApexRequestType, RequestType, const class UVaRestRequestJSON*, Request);
32DECLARE_DYNAMIC_MULTICAST_DELEGATE_ThreeParams(FOnApexRequestFail, EApexRequestType, RequestType, const class UVaRestRequestJSON*, Request, FAPEXRequestFailed, FailedRequestResponse);
33
34DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FOnApexTopTenDataComplete, const class UVaRestRequestJSON*, Request, FTopTenData, TopTenData);
35DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FOnApexTopTenDataFail, const class UVaRestRequestJSON*, Request, FAPEXRequestFailed, FailedFetchResponse);
36
37DECLARE_MULTICAST_DELEGATE(FOnStaticApexWebSocketConnected);
38DECLARE_MULTICAST_DELEGATE_OneParam(FOnStaticApexWebSocketConnectFailed, const FString&);
39DECLARE_MULTICAST_DELEGATE_ThreeParams(FOnStaticApexWebSocketDisconnected, int32, const FString&, bool);
40DECLARE_MULTICAST_DELEGATE_OneParam(FOnStaticApexAuthCodeRetrieved, const FString&);
44
45DECLARE_MULTICAST_DELEGATE_TwoParams(FOnStaticApexTopTenDataComplete, const class UVaRestRequestJSON*, FTopTenData);
47#pragma endregion EventDelegates
59UCLASS(BlueprintType, Blueprintable)
60class APEXSDK_API UApexAPI : public UGameInstanceSubsystem
61{
62 GENERATED_BODY()
63
64public:
65
66#pragma region PublicProperties
73 UPROPERTY(BlueprintReadOnly)
74 FString URL;
75
81 UPROPERTY(BlueprintReadOnly)
82 FString WebSocketURL;
83
84 UPROPERTY(BlueprintReadOnly)
85 FString ScenarioId;
86
87 UPROPERTY(BlueprintReadOnly, Meta=(DisplayName="Module Id"))
88 int LoadedModuleId;
89
90 UPROPERTY(BlueprintReadOnly)
91 FString ModuleVersion;
92
93 UPROPERTY(BlueprintReadOnly)
94 FString Platform;
96 UPROPERTY(BlueprintReadOnly)
97 FString DeviceId;
98
99 UPROPERTY(BlueprintReadOnly)
100 FString DeviceModel;
102 UPROPERTY(BlueprintReadOnly)
103 FString ClientIP;
104
105 UPROPERTY(BlueprintReadOnly)
106 FGuid CurrentSessionGuid;
108 UPROPERTY(BlueprintReadOnly)
109 FUserSessionData CurrentActiveLogin;
110#pragma endregion PublicProperties
111
112protected:
114 UPROPERTY(BlueprintReadOnly)
115 bool SessionInProgress;
116
117 UPROPERTY(BlueprintReadOnly)
118 bool WebSocketEnabled;
120public:
121 UApexAPI();
122
123 virtual void Initialize(FSubsystemCollectionBase& Collection) override;
124
125 UFUNCTION(BlueprintCallable, Category = "Apex|API")
126 void Ping();
127
128 UFUNCTION(BlueprintCallable, Category = "Apex|API")
129 void Login(const FApexLoginInfo& InLoginInfo, bool bShouldLogout = true);
130
131 UFUNCTION(BlueprintCallable, Category = "Apex|API")
132 void Logout();
133
134 UFUNCTION(BlueprintCallable, Category = "Apex|API")
135 bool IsWebSocketConnected();
136
137 UFUNCTION(BlueprintCallable, Category = "Apex|API", meta = (Tooltip = "This function only needs to be called when a user has logged out."))
138 void ConnectWebSocketService();
139
140 UFUNCTION(BlueprintCallable, Category = "Apex|API")
141 void RequestAuthorizationCode();
142
143 UFUNCTION(BlueprintCallable, Category = "Apex|API")
144 bool JoinSession(FString InScenarioId, const FXAPIExtension& InContextExtension);
145
146 UFUNCTION(BlueprintCallable, Category = "Apex|API")
147 bool CompleteSession(const FSessionData& InSessionData);
148
149 UFUNCTION(BlueprintCallable, Category = "Apex|API")
150 bool SendSessionEvent(const FXAPIStatement& InStatement);
151
152 UFUNCTION(BlueprintCallable, Category = "Apex|API")
153 bool FetchTopTen(FString Scenario, int OrgUnit);
154
155 UFUNCTION(BlueprintCallable, Category = "Apex|API", meta = (DisplayName = "Fetch Top Ten By User"))
156 bool FetchTopTenByCurrentUser(FString Scenario);
157
158 UFUNCTION(BlueprintCallable, Category = "Apex|API", meta=(DisplayName = "Fetch Top Ten By User"))
159 bool FetchTopTenByUser(int UserId, FString Scenario, int OrgUnit);
160
161 UFUNCTION(BlueprintCallable, Category = "Apex|API")
162 bool FetchTopTenByTimeRange(float TimePriorToToday, FString Scenario, int OrgUnit);
163
164protected:
165
166#pragma region PrivateFunctions
167 bool FetchTopTen(int UserId, float TimePriorToToday, FString Scenario, int OrgUnit);
168 void HandleLogin(class UVaRestJsonObject* LoginJsonObject);
169 void VerifyModuleAcess();
170 void SetupModuleSettings();
171
172 void OnLoginComplete(const class UVaRestRequestJSON* Request);
173 void OnLoginFail(const class UVaRestRequestJSON* Request);
174 void OnLogoutComplete(const class UVaRestRequestJSON* Request);
175 void OnLogoutFail(const class UVaRestRequestJSON* Request);
176 void OnUserVerificationComplete(const class UVaRestRequestJSON* Request);
177 void OnUserVerificationFail(const class UVaRestRequestJSON* Request);
178 void OnPingComplete(const class UVaRestRequestJSON* Request);
179 void OnPingFail(const class UVaRestRequestJSON* Request);
180 void OnJoinSessionComplete(const class UVaRestRequestJSON* Request);
181 void OnJoinSessionFail(const class UVaRestRequestJSON* Request);
182 void OnCompleteSessionComplete(const class UVaRestRequestJSON* Request);
183 void OnCompleteSessionFail(const class UVaRestRequestJSON* Request);
184 void OnSendSessionEventComplete(const class UVaRestRequestJSON* Request);
185 void OnSendSessionEventFail(const class UVaRestRequestJSON* Request);
186 void OnTopTenComplete(const class UVaRestRequestJSON* Request);
187 void OnTopTenFail(const class UVaRestRequestJSON* Request);
188#pragma endregion PrivateFunctions
189
190private:
191
192#pragma region PrivateVariables
193 class UVaRestSubsystem* VaRestSubsystem;
194 class UApexSDKSettings* ApexSettings;
195
196 FString AuthorizationToken;
197
198 TUniquePtr<ApexWebSocket> ApexSocket;
199#pragma endregion PrivateVariables
200
201public:
202
203#pragma region Events
204 // General Apex Requests
205 UPROPERTY(BlueprintAssignable, Category = "Apex|Event")
206 FOnApexRequestComplete OnRequestComplete;
207
208 UPROPERTY(BlueprintAssignable, Category = "Apex|Event")
209 FOnApexRequestFail OnRequestFail;
210
211 FOnStaticApexRequestComplete OnStaticRequestComplete;
212 FOnStaticApexRequestFail OnStaticRequestFail;
213
214 // Fetch Score Requests
215 UPROPERTY(BlueprintAssignable, Category = "Apex|Event")
216 FOnApexTopTenDataComplete OnFetchTopTenComplete;
217
218 UPROPERTY(BlueprintAssignable, Category = "Apex|Event")
219 FOnApexTopTenDataFail OnFetchTopTenFail;
220
221 FOnStaticApexTopTenDataComplete OnStaticFetchTopTenComplete;
222
223 FOnStaticApexTopTenDataFail OnStaticFetchTopTenFail;
224
225 // Web Socket Events
226 UPROPERTY(BlueprintAssignable, Category = "Apex|Event")
227 FOnApexWebSocketConnected OnWebSocketConnected;
228
229 UPROPERTY(BlueprintAssignable, Category = "Apex|Event")
230 FOnApexWebSocketConnectFailed OnWebSocketConnectFailed;
231
232 UPROPERTY(BlueprintAssignable, Category = "Apex|Event")
233 FOnApexWebSocketDisconnected OnWebSocketDisconnected;
234
235 UPROPERTY(BlueprintAssignable, Category = "Apex|Event")
236 FOnApexAuthCodeRetrieved OnAuthorizationCodeRetrieved;
237
238 FOnStaticApexWebSocketConnected OnStaticWebSocketConnected;
239
240 FOnStaticApexWebSocketConnectFailed OnStaticWebSocketConnectFailed;
241
242 FOnStaticApexWebSocketDisconnected OnStaticWebSocketDisconnected;
243
244 FOnStaticApexAuthCodeRetrieved OnStaticAuthorizationCodeRetrieved;
245#pragma endregion Events
246};
DECLARE_MULTICAST_DELEGATE(FOnStaticApexWebSocketConnected)
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnApexWebSocketConnectFailed, const FString &, Error)
EApexRequestType
UENUM(BlueprintType, Category = "APEX Responses", meta = (ScriptName = "MultiUserConnectionErrorType"...
Definition ApexAPI.h:19
@ Login
Definition ApexAPI.h:21
@ Logout
Definition ApexAPI.h:22
@ CompleteSession
Definition ApexAPI.h:25
@ Ping
Definition ApexAPI.h:20
@ JoinSession
Definition ApexAPI.h:23
@ SessionEvent
Definition ApexAPI.h:24
DECLARE_DYNAMIC_MULTICAST_DELEGATE_ThreeParams(FOnApexWebSocketDisconnected, int32, StatusCode, const FString &, Reason, bool, bWasClean)
DECLARE_MULTICAST_DELEGATE_OneParam(FOnStaticApexWebSocketConnectFailed, const FString &)
DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FOnApexRequestComplete, EApexRequestType, RequestType, const class UVaRestRequestJSON *, Request)
DECLARE_MULTICAST_DELEGATE_TwoParams(FOnStaticApexRequestComplete, EApexRequestType, const class UVaRestRequestJSON *)
DECLARE_DYNAMIC_MULTICAST_DELEGATE(FOnApexWebSocketConnected)
DECLARE_MULTICAST_DELEGATE_ThreeParams(FOnStaticApexWebSocketDisconnected, int32, const FString &, bool)
@ AuthorizationCode
UCLASS(BlueprintType, Blueprintable)
Definition ApexAPI.h:68
FString AuthorizationToken
Definition ApexAPI.h:281
bool WebSocketEnabled
UPROPERTY(BlueprintReadOnly)
Definition ApexAPI.h:164
class UVaRestSubsystem * VaRestSubsystem
Definition ApexAPI.h:278
FOnStaticApexRequestFail OnStaticRequestFail
Definition ApexAPI.h:303
GENERATED_BODY()
FString Platform
UPROPERTY(BlueprintReadOnly)
Definition ApexAPI.h:119
bool SessionInProgress
UPROPERTY(BlueprintReadOnly)
Definition ApexAPI.h:158
FOnStaticApexRequestComplete OnStaticRequestComplete
Definition ApexAPI.h:302
FOnStaticApexAuthCodeRetrieved OnStaticAuthorizationCodeRetrieved
Definition ApexAPI.h:353
FString ClientIP
UPROPERTY(BlueprintReadOnly)
Definition ApexAPI.h:137
FOnApexRequestComplete OnRequestComplete
UPROPERTY(BlueprintAssignable, Category = "Apex|Event")
Definition ApexAPI.h:294
FGuid CurrentSessionGuid
UPROPERTY(BlueprintReadOnly)
Definition ApexAPI.h:143
FString ModuleVersion
UPROPERTY(BlueprintReadOnly)
Definition ApexAPI.h:113
FOnApexTopTenDataFail OnFetchTopTenFail
UPROPERTY(BlueprintAssignable, Category = "Apex|Event")
Definition ApexAPI.h:316
FOnApexWebSocketConnectFailed OnWebSocketConnectFailed
UPROPERTY(BlueprintAssignable, Category = "Apex|Event")
Definition ApexAPI.h:333
FOnApexRequestFail OnRequestFail
UPROPERTY(BlueprintAssignable, Category = "Apex|Event")
Definition ApexAPI.h:300
FOnApexWebSocketConnected OnWebSocketConnected
UPROPERTY(BlueprintAssignable, Category = "Apex|Event")
Definition ApexAPI.h:327
FOnStaticApexWebSocketDisconnected OnStaticWebSocketDisconnected
Definition ApexAPI.h:351
FOnApexTopTenDataComplete OnFetchTopTenComplete
UPROPERTY(BlueprintAssignable, Category = "Apex|Event")
Definition ApexAPI.h:310
FString WebSocketURL
The API Websocket URL.
Definition ApexAPI.h:95
FString ScenarioId
UPROPERTY(BlueprintReadOnly)
Definition ApexAPI.h:101
FOnStaticApexTopTenDataFail OnStaticFetchTopTenFail
Definition ApexAPI.h:320
TUniquePtr< ApexWebSocket > ApexSocket
Definition ApexAPI.h:283
FUserSessionData CurrentActiveLogin
UPROPERTY(BlueprintReadOnly)
Definition ApexAPI.h:149
class UApexSDKSettings * ApexSettings
Definition ApexAPI.h:279
FOnStaticApexTopTenDataComplete OnStaticFetchTopTenComplete
Definition ApexAPI.h:318
FString DeviceModel
UPROPERTY(BlueprintReadOnly)
Definition ApexAPI.h:131
FOnApexAuthCodeRetrieved OnAuthorizationCodeRetrieved
UPROPERTY(BlueprintAssignable, Category = "Apex|Event")
Definition ApexAPI.h:345
FString URL
The API URL.
Definition ApexAPI.h:84
int LoadedModuleId
UPROPERTY(BlueprintReadOnly, Meta=(DisplayName="Module Id"))
Definition ApexAPI.h:107
FOnApexWebSocketDisconnected OnWebSocketDisconnected
UPROPERTY(BlueprintAssignable, Category = "Apex|Event")
Definition ApexAPI.h:339
FString DeviceId
UPROPERTY(BlueprintReadOnly)
Definition ApexAPI.h:125
FOnStaticApexWebSocketConnectFailed OnStaticWebSocketConnectFailed
Definition ApexAPI.h:349
FOnStaticApexWebSocketConnected OnStaticWebSocketConnected
Definition ApexAPI.h:347
UCLASS(config = Engine, defaultconfig)
UCLASS(BlueprintType, Blueprintable)
UCLASS(BlueprintType, Blueprintable)
USTRUCT(BlueprintType)
Definition ApexTypes.h:134
USTRUCT(BlueprintType)
Definition ApexTypes.h:16
USTRUCT(BlueprintType)
Definition ApexTypes.h:184
USTRUCT(BlueprintType)
Definition ApexTypes.h:836
USTRUCT(BlueprintType)
Definition ApexTypes.h:517
USTRUCT(BlueprintType)
USTRUCT(BlueprintType)
Definition XAPITypes.h:1156