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
81 UPROPERTY(BlueprintReadOnly)
82 FString URL;
83
89 UPROPERTY(BlueprintReadOnly)
90 FString WebSocketURL;
91
92 UPROPERTY(BlueprintReadOnly)
93 FString ScenarioId;
94
95 UPROPERTY(BlueprintReadWrite, Meta=(DisplayName="Module Id"))
96 int LoadedModuleId;
97
98 UPROPERTY(BlueprintReadOnly)
99 FString ModuleVersion;
100
101 UPROPERTY(BlueprintReadOnly)
102 FString Platform;
104 UPROPERTY(BlueprintReadOnly)
105 FString DeviceId;
106
107 UPROPERTY(BlueprintReadOnly)
108 FString DeviceModel;
110 UPROPERTY(BlueprintReadOnly)
111 FString ClientIP;
112
113 UPROPERTY(BlueprintReadOnly)
114 FGuid CurrentSessionGuid;
116 UPROPERTY(BlueprintReadOnly)
117 FUserSessionData CurrentActiveLogin;
118#pragma endregion PublicProperties
119
122 UPROPERTY(BlueprintReadOnly)
123 bool bSessionInProgress;
124
125 UPROPERTY(BlueprintReadOnly)
126 bool bWebSocketEnabled;
128public:
129 UApexAPI();
130
131 virtual void Initialize(FSubsystemCollectionBase& Collection) override;
132
133 UFUNCTION(BlueprintCallable, Category = "Apex|API")
134 void Ping();
135
136 UFUNCTION(BlueprintPure, BlueprintCallable, Category = "Apex|API")
137 bool HasLaunchAuthToken();
138
139 UFUNCTION(BlueprintPure, BlueprintCallable, Category = "Apex|API")
140 bool IsLoggedIn();
141
142 UFUNCTION(BlueprintCallable, Category = "Apex|API")
143 void LoginWithAuthToken();
144
145 UFUNCTION(BlueprintCallable, Category = "Apex|API")
146 void Login(const FString& InUserName, const FString& InPassword, bool bShouldLogout = true);
147
148 UFUNCTION(BlueprintCallable, Category = "Apex|API")
149 void Logout();
150
151 UFUNCTION(BlueprintCallable, Category = "Apex|API")
152 bool IsWebSocketConnected();
153
154 UFUNCTION(BlueprintCallable, Category = "Apex|API", meta = (Tooltip = "This function only needs to be called when a user has logged out."))
155 void ConnectWebSocketService();
156
157 UFUNCTION(BlueprintCallable, Category = "Apex|API")
158 void RequestAuthorizationCode();
159
160 UFUNCTION(BlueprintCallable, Category = "Apex|API")
161 bool JoinSession(FString InScenarioId, const FXAPIExtension& InContextExtension, bool bIsMultiplayer = false);
162
163 UFUNCTION(BlueprintCallable, Category = "Apex|API")
164 bool CompleteSession(const FSessionData& InSessionData);
165
166 UFUNCTION(BlueprintCallable, Category = "Apex|API")
167 bool SendSessionEvent(const FXAPIStatement& InStatement);
168
169 UFUNCTION(BlueprintCallable, Category = "Apex|API")
170 bool FetchTopTen(FString Scenario, int OrgUnit);
171
172 UFUNCTION(BlueprintCallable, Category = "Apex|API", meta = (DisplayName = "Fetch Top Ten By User"))
173 bool FetchTopTenByCurrentUser(FString Scenario);
174
175 UFUNCTION(BlueprintCallable, Category = "Apex|API", meta=(DisplayName = "Fetch Top Ten By User"))
176 bool FetchTopTenByUser(int UserId, FString Scenario, int OrgUnit);
177
178 UFUNCTION(BlueprintCallable, Category = "Apex|API")
179 bool FetchTopTenByTimeRange(float TimePriorToToday, FString Scenario, int OrgUnit);
180
181 UFUNCTION(BlueprintCallable, Category = "Apex|API")
182 void FilloutLaunchToken();
183
184 UFUNCTION(BlueprintCallable, Category = "Apex|API")
185 void VerifyModuleAccess(int InModuleId);
186
187protected:
188
189#pragma region PrivateFunctions
190 TSharedRef<FJsonObject> GetUserJsonObject(TSharedRef<FJsonObject>& RootJsonObject);
191 bool FetchTopTen(int UserId, float TimePriorToToday, FString Scenario, int OrgUnit);
192 void HandleLogin(class UVaRestJsonObject* LoginJsonObject);
193 void SetupModuleSettings();
194 void SendHeartbeat();
195
196 void OnLoginComplete(const class UVaRestRequestJSON* Request);
197 void OnLoginFail(const class UVaRestRequestJSON* Request);
198 void OnLogoutComplete(const class UVaRestRequestJSON* Request);
199 void OnLogoutFail(const class UVaRestRequestJSON* Request);
200 void OnUserVerificationComplete(const class UVaRestRequestJSON* Request);
201 void OnUserVerificationFail(const class UVaRestRequestJSON* Request);
202 void OnPingComplete(const class UVaRestRequestJSON* Request);
203 void OnPingFail(const class UVaRestRequestJSON* Request);
204 void OnJoinSessionComplete(const class UVaRestRequestJSON* Request);
205 void OnJoinSessionFail(const class UVaRestRequestJSON* Request);
206 void OnCompleteSessionComplete(const class UVaRestRequestJSON* Request);
207 void OnCompleteSessionFail(const class UVaRestRequestJSON* Request);
208 void OnSendSessionEventComplete(const class UVaRestRequestJSON* Request);
209 void OnSendSessionEventFail(const class UVaRestRequestJSON* Request);
210 void OnTopTenComplete(const class UVaRestRequestJSON* Request);
211 void OnTopTenFail(const class UVaRestRequestJSON* Request);
212#pragma endregion PrivateFunctions
213
214private:
215
216#pragma region PrivateVariables
217 class UVaRestSubsystem* VaRestSubsystem;
218 class UApexSDKSettings* ApexSettings;
219 class UPixoLauncherSubsystem* LauncherSubsystem;
220
221 FString LaunchToken;
222 FTimerHandle HeartbeatHandle;
223 int SessionId;
224
225 TUniquePtr<ApexWebSocket> ApexSocket;
226#pragma endregion PrivateVariables
227
228public:
229
230#pragma region Events
231 // General Apex Requests
232 UPROPERTY(BlueprintAssignable, Category = "Apex|Event")
233 FOnApexRequestComplete OnRequestComplete;
234
235 UPROPERTY(BlueprintAssignable, Category = "Apex|Event")
236 FOnApexRequestFail OnRequestFail;
237
238 FOnStaticApexRequestComplete OnStaticRequestComplete;
239 FOnStaticApexRequestFail OnStaticRequestFail;
240
241 // Fetch Score Requests
242 UPROPERTY(BlueprintAssignable, Category = "Apex|Event")
243 FOnApexTopTenDataComplete OnFetchTopTenComplete;
244
245 UPROPERTY(BlueprintAssignable, Category = "Apex|Event")
246 FOnApexTopTenDataFail OnFetchTopTenFail;
247
248 FOnStaticApexTopTenDataComplete OnStaticFetchTopTenComplete;
249
250 FOnStaticApexTopTenDataFail OnStaticFetchTopTenFail;
251
252 // Web Socket Events
253 UPROPERTY(BlueprintAssignable, Category = "Apex|Event")
254 FOnApexWebSocketConnected OnWebSocketConnected;
255
256 UPROPERTY(BlueprintAssignable, Category = "Apex|Event")
257 FOnApexWebSocketConnectFailed OnWebSocketConnectFailed;
258
259 UPROPERTY(BlueprintAssignable, Category = "Apex|Event")
260 FOnApexWebSocketDisconnected OnWebSocketDisconnected;
261
262 UPROPERTY(BlueprintAssignable, Category = "Apex|Event")
263 FOnApexAuthCodeRetrieved OnAuthorizationCodeRetrieved;
264
265 FOnStaticApexWebSocketConnected OnStaticWebSocketConnected;
266
267 FOnStaticApexWebSocketConnectFailed OnStaticWebSocketConnectFailed;
268
269 FOnStaticApexWebSocketDisconnected OnStaticWebSocketDisconnected;
270
271 FOnStaticApexAuthCodeRetrieved OnStaticAuthorizationCodeRetrieved;
272#pragma endregion Events
273};
#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:172
class UVaRestSubsystem * VaRestSubsystem
Definition ApexAPI.h:319
FOnStaticApexRequestFail OnStaticRequestFail
Definition ApexAPI.h:347
GENERATED_BODY()
FString Platform
UPROPERTY(BlueprintReadOnly)
Definition ApexAPI.h:127
class UPixoLauncherSubsystem * LauncherSubsystem
Definition ApexAPI.h:321
int SessionId
Definition ApexAPI.h:325
FOnStaticApexRequestComplete OnStaticRequestComplete
Definition ApexAPI.h:346
FOnStaticApexAuthCodeRetrieved OnStaticAuthorizationCodeRetrieved
Definition ApexAPI.h:397
FString ClientIP
UPROPERTY(BlueprintReadOnly)
Definition ApexAPI.h:145
FOnApexRequestComplete OnRequestComplete
UPROPERTY(BlueprintAssignable, Category = "Apex|Event")
Definition ApexAPI.h:338
FTimerHandle HeartbeatHandle
Definition ApexAPI.h:324
FGuid CurrentSessionGuid
UPROPERTY(BlueprintReadOnly)
Definition ApexAPI.h:151
FString ModuleVersion
UPROPERTY(BlueprintReadOnly)
Definition ApexAPI.h:121
FOnApexTopTenDataFail OnFetchTopTenFail
UPROPERTY(BlueprintAssignable, Category = "Apex|Event")
Definition ApexAPI.h:360
FOnApexWebSocketConnectFailed OnWebSocketConnectFailed
UPROPERTY(BlueprintAssignable, Category = "Apex|Event")
Definition ApexAPI.h:377
FOnApexRequestFail OnRequestFail
UPROPERTY(BlueprintAssignable, Category = "Apex|Event")
Definition ApexAPI.h:344
FOnApexWebSocketConnected OnWebSocketConnected
UPROPERTY(BlueprintAssignable, Category = "Apex|Event")
Definition ApexAPI.h:371
FString LaunchToken
Definition ApexAPI.h:323
FOnStaticApexWebSocketDisconnected OnStaticWebSocketDisconnected
Definition ApexAPI.h:395
FOnApexTopTenDataComplete OnFetchTopTenComplete
UPROPERTY(BlueprintAssignable, Category = "Apex|Event")
Definition ApexAPI.h:354
FString WebSocketURL
The API Websocket URL.
Definition ApexAPI.h:103
FString ScenarioId
UPROPERTY(BlueprintReadOnly)
Definition ApexAPI.h:109
FOnStaticApexTopTenDataFail OnStaticFetchTopTenFail
Definition ApexAPI.h:364
TUniquePtr< ApexWebSocket > ApexSocket
Definition ApexAPI.h:327
FUserSessionData CurrentActiveLogin
UPROPERTY(BlueprintReadOnly)
Definition ApexAPI.h:157
class UApexSDKSettings * ApexSettings
Definition ApexAPI.h:320
FOnStaticApexTopTenDataComplete OnStaticFetchTopTenComplete
Definition ApexAPI.h:362
FString DeviceModel
UPROPERTY(BlueprintReadOnly)
Definition ApexAPI.h:139
FOnApexAuthCodeRetrieved OnAuthorizationCodeRetrieved
UPROPERTY(BlueprintAssignable, Category = "Apex|Event")
Definition ApexAPI.h:389
FString URL
The API URL.
Definition ApexAPI.h:92
int LoadedModuleId
UPROPERTY(BlueprintReadWrite, Meta=(DisplayName="Module Id"))
Definition ApexAPI.h:115
FOnApexWebSocketDisconnected OnWebSocketDisconnected
UPROPERTY(BlueprintAssignable, Category = "Apex|Event")
Definition ApexAPI.h:383
FString DeviceId
UPROPERTY(BlueprintReadOnly)
Definition ApexAPI.h:133
bool bSessionInProgress
UPROPERTY(BlueprintReadOnly)
Definition ApexAPI.h:166
FOnStaticApexWebSocketConnectFailed OnStaticWebSocketConnectFailed
Definition ApexAPI.h:393
FOnStaticApexWebSocketConnected OnStaticWebSocketConnected
Definition ApexAPI.h:391
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