Documentation for the Unreal C++ Plugin
Loading...
Searching...
No Matches
ApexAPI.h
Go to the documentation of this file.
1// Copyright 2022 PixoVR Corp. All Rights Reserved.
2
3// This cannot be #pragma once'd.
4#undef PACKAGE_SCOPE
5#ifdef APEXSDK_PACKAGE
6#define PACKAGE_SCOPE public
7#else
8#define PACKAGE_SCOPE protected
9#endif
10
11#pragma once
12
13#include "CoreMinimal.h"
14#include "Subsystems/GameInstanceSubsystem.h"
15#include "Misc/DateTime.h"
16#include "ApexSDKDefines.h"
17#include "XAPITypes.h"
18#include "ApexTypes.h"
19#include "ApexWebSocket.h"
20#include "ApexAPI.generated.h"
21
22UENUM(BlueprintType, Category = "APEX Responses", meta = (ScriptName = "MultiUserConnectionErrorType"))
24{
25 Ping,
27 Logout,
31};
33#pragma region EventDelegates
34DECLARE_DYNAMIC_MULTICAST_DELEGATE(FOnApexWebSocketConnected);
35DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnApexWebSocketConnectFailed, const FString&, Error);
36DECLARE_DYNAMIC_MULTICAST_DELEGATE_ThreeParams(FOnApexWebSocketDisconnected, int32, StatusCode, const FString&, Reason, bool, bWasClean);
37DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnApexAuthCodeRetrieved, const FString&, AuthorizationCode);
39DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FOnApexRequestComplete, EApexRequestType, RequestType, const class UVaRestRequestJSON*, Request);
40DECLARE_DYNAMIC_MULTICAST_DELEGATE_ThreeParams(FOnApexRequestFail, EApexRequestType, RequestType, const class UVaRestRequestJSON*, Request, FAPEXRequestFailed, FailedRequestResponse);
41
42DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FOnApexTopTenDataComplete, const class UVaRestRequestJSON*, Request, FTopTenData, TopTenData);
43DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FOnApexTopTenDataFail, const class UVaRestRequestJSON*, Request, FAPEXRequestFailed, FailedFetchResponse);
44
45DECLARE_MULTICAST_DELEGATE(FOnStaticApexWebSocketConnected);
46DECLARE_MULTICAST_DELEGATE_OneParam(FOnStaticApexWebSocketConnectFailed, const FString&);
47DECLARE_MULTICAST_DELEGATE_ThreeParams(FOnStaticApexWebSocketDisconnected, int32, const FString&, bool);
48DECLARE_MULTICAST_DELEGATE_OneParam(FOnStaticApexAuthCodeRetrieved, const FString&);
50DECLARE_MULTICAST_DELEGATE_TwoParams(FOnStaticApexRequestComplete, EApexRequestType, const class UVaRestRequestJSON*);
51DECLARE_MULTICAST_DELEGATE_TwoParams(FOnStaticApexRequestFail, EApexRequestType, const class UVaRestRequestJSON*);
52
53DECLARE_MULTICAST_DELEGATE_TwoParams(FOnStaticApexTopTenDataComplete, const class UVaRestRequestJSON*, FTopTenData);
54DECLARE_MULTICAST_DELEGATE_TwoParams(FOnStaticApexTopTenDataFail, const class UVaRestRequestJSON*, FAPEXRequestFailed);
55#pragma endregion EventDelegates
67UCLASS(BlueprintType, Blueprintable)
68class APEXSDK_API UApexAPI : public UGameInstanceSubsystem
69{
70 GENERATED_BODY()
71
72public:
73
74#pragma region PublicProperties
76 // TODO (MG): Move all of these properties to PACKAGE_SCOPE and create getters/setters as needed
82 UPROPERTY(BlueprintReadOnly)
83 FString URL;
84
90 UPROPERTY(BlueprintReadOnly)
91 FString WebSocketURL;
92
93 UPROPERTY(BlueprintReadOnly)
94 FString ScenarioId;
95
96 UPROPERTY(BlueprintReadWrite, Meta=(DisplayName="Module Id"))
97 int LoadedModuleId;
98
99 UPROPERTY(BlueprintReadOnly)
100 FString ModuleVersion;
101
102 UPROPERTY(BlueprintReadOnly)
103 FString Platform;
105 UPROPERTY(BlueprintReadOnly)
106 FString DeviceId;
107
108 UPROPERTY(BlueprintReadOnly)
109 FString DeviceModel;
111 UPROPERTY(BlueprintReadOnly)
112 FString ClientIP;
113
114 UPROPERTY(BlueprintReadOnly)
115 FGuid CurrentSessionGuid;
117 UPROPERTY(BlueprintReadOnly)
118 FUserSessionData CurrentActiveLogin;
119
120#pragma endregion PublicProperties
121
123
124 UPROPERTY(BlueprintReadOnly)
125 bool bSessionInProgress;
126
127 UPROPERTY(BlueprintReadOnly)
128 bool bWebSocketEnabled;
129
130 UPROPERTY(BlueprintReadOnly)
131 FString ReturnTarget;
132
133 UPROPERTY(BlueprintReadOnly)
134 FString ReturnTargetType;
135
136 UPROPERTY(BlueprintReadOnly)
137 FString ReturnParameters;
138
139public:
141
142 virtual void Initialize(FSubsystemCollectionBase& Collection) override;
143
144 UFUNCTION(BlueprintCallable, Category = "Apex|API")
145 void ExitApplication(const FString& InReturnTarget, const FString& InReturnTargetType);
147 UFUNCTION(BlueprintCallable, Category = "Apex|API")
148 void Ping();
149
150 UFUNCTION(BlueprintPure, BlueprintCallable, Category = "Apex|API")
151 bool HasLaunchAuthToken();
153 UFUNCTION(BlueprintPure, BlueprintCallable, Category = "Apex|API")
154 bool IsLoggedIn();
155
156 UFUNCTION(BlueprintCallable, Category = "Apex|API")
157 void LoginWithAuthToken();
159 UFUNCTION(BlueprintCallable, Category = "Apex|API")
160 void Login(const FString& InUserName, const FString& InPassword, bool bShouldLogout = true);
161
162 UFUNCTION(BlueprintCallable, Category = "Apex|API")
163 void Logout();
164
165 UFUNCTION(BlueprintCallable, Category = "Apex|API")
166 bool IsWebSocketConnected();
167
168 UFUNCTION(BlueprintCallable, Category = "Apex|API", meta = (Tooltip = "This function only needs to be called when a user has logged out."))
169 void ConnectWebSocketService();
170
171 UFUNCTION(BlueprintCallable, Category = "Apex|API")
172 void RequestAuthorizationCode();
173
174 UFUNCTION(BlueprintCallable, Category = "Apex|API")
175 bool JoinSession(FString InScenarioId, const FXAPIExtension& InContextExtension, bool bIsMultiplayer = false);
176
177 UFUNCTION(BlueprintCallable, Category = "Apex|API")
178 bool CompleteSession(const FSessionData& InSessionData);
179
180 UFUNCTION(BlueprintCallable, Category = "Apex|API")
181 bool SendSessionEvent(const FXAPIStatement& InStatement);
182
183 UFUNCTION(BlueprintCallable, Category = "Apex|API")
184 bool FetchTopTen(FString Scenario, int OrgUnit);
185
186 UFUNCTION(BlueprintCallable, Category = "Apex|API", meta = (DisplayName = "Fetch Top Ten By User"))
187 bool FetchTopTenByCurrentUser(FString Scenario);
188
189 UFUNCTION(BlueprintCallable, Category = "Apex|API", meta=(DisplayName = "Fetch Top Ten By User"))
190 bool FetchTopTenByUser(int UserId, FString Scenario, int OrgUnit);
191
192 UFUNCTION(BlueprintCallable, Category = "Apex|API")
193 bool FetchTopTenByTimeRange(float TimePriorToToday, FString Scenario, int OrgUnit);
194
195 UFUNCTION(BlueprintCallable, Category = "Apex|API")
196 void FilloutLaunchToken();
197
198 UFUNCTION(BlueprintCallable, Category = "Apex|API")
199 void VerifyModuleAccess(int InModuleId);
200
201 // Overrides the current destination of where the app will exit to.
202 UFUNCTION(BlueprintCallable, Category = "Apex|SDK")
203 void SetExitTarget(const FString& InExitTarget, const FString& InExitTargetType);
204
205 UFUNCTION(BlueprintCallable, Category = "Apex|SDK")
206 void SetExitParameters(const FString& SetExitTarget);
207
208protected:
209
210#pragma region PrivateFunctions
211 TSharedRef<FJsonObject> GetUserJsonObject(TSharedRef<FJsonObject>& RootJsonObject);
212 bool FetchTopTen(int UserId, float TimePriorToToday, FString Scenario, int OrgUnit);
213 void HandleLogin(class UVaRestJsonObject* LoginJsonObject);
214 void SetupModuleSettings();
215 void SendHeartbeat();
216 void ParseIntentData(const FString& InIntentData);
217
218 void OnLoginComplete(const class UVaRestRequestJSON* Request);
219 void OnLoginFail(const class UVaRestRequestJSON* Request);
220 void OnLogoutComplete(const class UVaRestRequestJSON* Request);
221 void OnLogoutFail(const class UVaRestRequestJSON* Request);
222 void OnUserVerificationComplete(const class UVaRestRequestJSON* Request);
223 void OnUserVerificationFail(const class UVaRestRequestJSON* Request);
224 void OnPingComplete(const class UVaRestRequestJSON* Request);
225 void OnPingFail(const class UVaRestRequestJSON* Request);
226 void OnJoinSessionComplete(const class UVaRestRequestJSON* Request);
227 void OnJoinSessionFail(const class UVaRestRequestJSON* Request);
228 void OnCompleteSessionComplete(const class UVaRestRequestJSON* Request);
229 void OnCompleteSessionFail(const class UVaRestRequestJSON* Request);
230 void OnSendSessionEventComplete(const class UVaRestRequestJSON* Request);
231 void OnSendSessionEventFail(const class UVaRestRequestJSON* Request);
232 void OnTopTenComplete(const class UVaRestRequestJSON* Request);
233 void OnTopTenFail(const class UVaRestRequestJSON* Request);
234#pragma endregion PrivateFunctions
235
236private:
237
238#pragma region PrivateVariables
239 class UVaRestSubsystem* VaRestSubsystem;
240 class UApexSDKSettings* ApexSettings;
241 class UPixoLauncherSubsystem* LauncherSubsystem;
242
243 FString LaunchToken;
244 FTimerHandle HeartbeatHandle;
245 int SessionId;
246
247 TUniquePtr<ApexWebSocket> ApexSocket;
248#pragma endregion PrivateVariables
249
250public:
251
252#pragma region Events
253 // General Apex Requests
254 UPROPERTY(BlueprintAssignable, Category = "Apex|Event")
255 FOnApexRequestComplete OnRequestComplete;
256
257 UPROPERTY(BlueprintAssignable, Category = "Apex|Event")
258 FOnApexRequestFail OnRequestFail;
259
260 FOnStaticApexRequestComplete OnStaticRequestComplete;
261 FOnStaticApexRequestFail OnStaticRequestFail;
262
263 // Fetch Score Requests
264 UPROPERTY(BlueprintAssignable, Category = "Apex|Event")
265 FOnApexTopTenDataComplete OnFetchTopTenComplete;
266
267 UPROPERTY(BlueprintAssignable, Category = "Apex|Event")
268 FOnApexTopTenDataFail OnFetchTopTenFail;
269
270 FOnStaticApexTopTenDataComplete OnStaticFetchTopTenComplete;
271
272 FOnStaticApexTopTenDataFail OnStaticFetchTopTenFail;
273
274 // Web Socket Events
275 UPROPERTY(BlueprintAssignable, Category = "Apex|Event")
276 FOnApexWebSocketConnected OnWebSocketConnected;
277
278 UPROPERTY(BlueprintAssignable, Category = "Apex|Event")
279 FOnApexWebSocketConnectFailed OnWebSocketConnectFailed;
280
281 UPROPERTY(BlueprintAssignable, Category = "Apex|Event")
282 FOnApexWebSocketDisconnected OnWebSocketDisconnected;
283
284 UPROPERTY(BlueprintAssignable, Category = "Apex|Event")
285 FOnApexAuthCodeRetrieved OnAuthorizationCodeRetrieved;
286
287 FOnStaticApexWebSocketConnected OnStaticWebSocketConnected;
288
289 FOnStaticApexWebSocketConnectFailed OnStaticWebSocketConnectFailed;
290
291 FOnStaticApexWebSocketDisconnected OnStaticWebSocketDisconnected;
292
293 FOnStaticApexAuthCodeRetrieved OnStaticAuthorizationCodeRetrieved;
294#pragma endregion Events
295};
#define Error(pmt,...)
Definition ApexAPI.cpp:16
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:27
@ Login
Definition ApexAPI.h:29
@ Logout
Definition ApexAPI.h:30
@ CompleteSession
Definition ApexAPI.h:33
@ Ping
Definition ApexAPI.h:28
@ JoinSession
Definition ApexAPI.h:31
@ SessionEvent
Definition ApexAPI.h:32
DECLARE_DYNAMIC_MULTICAST_DELEGATE_ThreeParams(FOnApexWebSocketDisconnected, int32, StatusCode, const FString &, Reason, bool, bWasClean)
DECLARE_MULTICAST_DELEGATE_OneParam(FOnStaticApexWebSocketConnectFailed, const FString &)
#define PACKAGE_SCOPE
Definition ApexAPI.h:8
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:76
bool bWebSocketEnabled
UPROPERTY(BlueprintReadOnly)
Definition ApexAPI.h:174
FString ReturnTargetType
UPROPERTY(BlueprintReadOnly)
Definition ApexAPI.h:186
class UVaRestSubsystem * VaRestSubsystem
Definition ApexAPI.h:359
FOnStaticApexRequestFail OnStaticRequestFail
Definition ApexAPI.h:387
FString ReturnParameters
UPROPERTY(BlueprintReadOnly)
Definition ApexAPI.h:192
GENERATED_BODY()
FString Platform
UPROPERTY(BlueprintReadOnly)
Definition ApexAPI.h:128
class UPixoLauncherSubsystem * LauncherSubsystem
Definition ApexAPI.h:361
int SessionId
Definition ApexAPI.h:365
FOnStaticApexRequestComplete OnStaticRequestComplete
Definition ApexAPI.h:386
FOnStaticApexAuthCodeRetrieved OnStaticAuthorizationCodeRetrieved
Definition ApexAPI.h:437
FString ClientIP
UPROPERTY(BlueprintReadOnly)
Definition ApexAPI.h:146
FOnApexRequestComplete OnRequestComplete
UPROPERTY(BlueprintAssignable, Category = "Apex|Event")
Definition ApexAPI.h:378
FTimerHandle HeartbeatHandle
Definition ApexAPI.h:364
FGuid CurrentSessionGuid
UPROPERTY(BlueprintReadOnly)
Definition ApexAPI.h:152
FString ModuleVersion
UPROPERTY(BlueprintReadOnly)
Definition ApexAPI.h:122
FOnApexTopTenDataFail OnFetchTopTenFail
UPROPERTY(BlueprintAssignable, Category = "Apex|Event")
Definition ApexAPI.h:400
FOnApexWebSocketConnectFailed OnWebSocketConnectFailed
UPROPERTY(BlueprintAssignable, Category = "Apex|Event")
Definition ApexAPI.h:417
FOnApexRequestFail OnRequestFail
UPROPERTY(BlueprintAssignable, Category = "Apex|Event")
Definition ApexAPI.h:384
FOnApexWebSocketConnected OnWebSocketConnected
UPROPERTY(BlueprintAssignable, Category = "Apex|Event")
Definition ApexAPI.h:411
FString LaunchToken
Definition ApexAPI.h:363
FOnStaticApexWebSocketDisconnected OnStaticWebSocketDisconnected
Definition ApexAPI.h:435
FOnApexTopTenDataComplete OnFetchTopTenComplete
UPROPERTY(BlueprintAssignable, Category = "Apex|Event")
Definition ApexAPI.h:394
FString WebSocketURL
The API Websocket URL.
Definition ApexAPI.h:104
FString ScenarioId
UPROPERTY(BlueprintReadOnly)
Definition ApexAPI.h:110
FOnStaticApexTopTenDataFail OnStaticFetchTopTenFail
Definition ApexAPI.h:404
TUniquePtr< ApexWebSocket > ApexSocket
Definition ApexAPI.h:367
FUserSessionData CurrentActiveLogin
UPROPERTY(BlueprintReadOnly)
Definition ApexAPI.h:158
class UApexSDKSettings * ApexSettings
Definition ApexAPI.h:360
FOnStaticApexTopTenDataComplete OnStaticFetchTopTenComplete
Definition ApexAPI.h:402
FString DeviceModel
UPROPERTY(BlueprintReadOnly)
Definition ApexAPI.h:140
FOnApexAuthCodeRetrieved OnAuthorizationCodeRetrieved
UPROPERTY(BlueprintAssignable, Category = "Apex|Event")
Definition ApexAPI.h:429
FString URL
The API URL.
Definition ApexAPI.h:93
int LoadedModuleId
UPROPERTY(BlueprintReadWrite, Meta=(DisplayName="Module Id"))
Definition ApexAPI.h:116
FOnApexWebSocketDisconnected OnWebSocketDisconnected
UPROPERTY(BlueprintAssignable, Category = "Apex|Event")
Definition ApexAPI.h:423
FString DeviceId
UPROPERTY(BlueprintReadOnly)
Definition ApexAPI.h:134
bool bSessionInProgress
UPROPERTY(BlueprintReadOnly)
Definition ApexAPI.h:168
FString ReturnTarget
UPROPERTY(BlueprintReadOnly)
Definition ApexAPI.h:180
FOnStaticApexWebSocketConnectFailed OnStaticWebSocketConnectFailed
Definition ApexAPI.h:433
FOnStaticApexWebSocketConnected OnStaticWebSocketConnected
Definition ApexAPI.h:431
UCLASS(config = Engine, defaultconfig)
UCLASS(BlueprintType, Blueprintable, DisplayName = "PixoVR Launcher")
USTRUCT(BlueprintType)
Definition ApexTypes.h:99
USTRUCT(BlueprintType)
Definition ApexTypes.h:193
USTRUCT(BlueprintType)
Definition ApexTypes.h:855
USTRUCT(BlueprintType)
Definition ApexTypes.h:536
USTRUCT(BlueprintType)
USTRUCT(BlueprintType)
Definition XAPITypes.h:1157