Documentation for the Unity C# Library
Loading...
Searching...
No Matches
ApexSystem.cs
Go to the documentation of this file.
1using System;
2using System.Collections.Generic;
3using System.Net.Http;
4using System.Text.RegularExpressions;
5using System.Threading.Tasks;
6using Newtonsoft.Json;
10using TinCan;
11using UnityEngine;
12using UnityEngine.XR;
13
14#if MANAGE_XR
15using MXR.SDK;
16#endif
17
18namespace PixoVR.Apex
19{
20 public delegate void PlatformResponse(ResponseType type, bool wasSuccessful, object responseData);
21
22 [DefaultExecutionOrder(-50)]
23 public class ApexSystem : ApexSingleton<ApexSystem>
24 {
25 private enum VersionParts : int
26 {
27 Major = 0,
28 Minor,
29 Patch,
30 }
31
32 public static string ServerIP
33 {
34 get { return Instance.serverIP; }
35 set { }
36 }
37
38 public static int ModuleID
39 {
40 get { return Instance.moduleID; }
41 set { Instance.moduleID = value; }
42 }
43
44 public static string ModuleName
45 {
46 get { return Instance.moduleName; }
47 set { Instance.moduleName = value; }
48 }
49
50 public static string ModuleVersion
51 {
52 get { return Instance.moduleVersion; }
53 set { Instance.moduleVersion = value; }
54 }
55
56 public static string ScenarioID
57 {
58 get { return Instance.scenarioID; }
59 set { Instance.scenarioID = value; }
60 }
61
63 {
64 get { return Instance.currentActiveLogin; }
65 set { }
66 }
67
68 public static bool RunSetupOnAwake
69 {
70 get { return Instance.runSetupOnAwake; }
71 set { Instance.runSetupOnAwake = value; }
72 }
73
74 public static bool LoginCheckModuleAccess
75 {
76 get { return Instance.loginCheckModuleAccess; }
77 set { }
78 }
79
80 public static string DeviceSerialNumber
81 {
82 get { return Instance.deviceSerialNumber; }
83 set { }
84 }
85
86 public static string PassedLoginToken
87 {
88 get { return Instance.loginToken; }
89 set { }
90 }
91
92 public static string OptionalData
93 {
94 get { return Instance.optionalParameter; }
95 set { Instance.optionalParameter = value; }
96 }
97
98 public static string ReturnTarget
99 {
100 get { return Instance.returnTargetParameter; }
101 set
102 {
103 if (value != null)
104 {
105 Instance.returnTargetParameter = value;
106 }
107 else
108 {
109 Instance.returnTargetParameter = "";
110 }
111
112 if (Instance.returnTargetParameter.Contains("://"))
113 {
114 TargetType = "url";
115 }
116 else
117 {
118 TargetType = "app";
119 }
120 }
121 }
122
123 public static string TargetType
124 {
125 get { return Instance.targetTypeParameter; }
126 private set { Instance.targetTypeParameter = value; }
127 }
128
129 [SerializeField, EndpointDisplay]
131
132 [SerializeField]
133 protected string serverIP = "";
134
135 [SerializeField]
136 protected int moduleID = 0;
137
138 [SerializeField]
139 protected string moduleName = "Generic";
140
141 [SerializeField]
142 protected string moduleVersion = "0.00.00";
143
144 [SerializeField]
145 protected string scenarioID = "Generic";
146
147 [SerializeField]
148 public bool runSetupOnAwake = true;
149
150 [SerializeField]
151 public bool loginCheckModuleAccess = true;
152
153 [SerializeField]
154 protected float heartbeatTime = 5.0f;
155
156 protected string webSocketUrl;
157 protected string deviceID;
158 protected string deviceModel;
159 protected string platform;
160 protected string clientIP;
161 protected Guid currentSessionID;
162 protected int heartbeatSessionID;
163 protected float heartbeatTimer;
164 protected bool sessionInProgress;
165 protected bool userAccessVerified = false;
166 protected string deviceSerialNumber = "";
167
168 protected string loginToken = "";
169 protected string optionalParameter = "";
170 protected string returnTargetParameter = "";
171 protected string targetTypeParameter = "";
172
174 protected APIHandler apexAPIHandler;
176 protected Task<bool> socketConnectTask;
177 protected Task socketDisconnectTask;
178
181
187
190
196
199
206 public PlatformResponse OnPlatformResponse = null;
215
219 void Awake()
220 {
223#if UNITY_IOS || UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX
225#endif
226 if (runSetupOnAwake)
228 Debug.Log("[ApexSystem] Running on awake!");
229 SetupAPI();
232 DontDestroyOnLoad(gameObject);
233#if MANAGE_XR
234 InitMXRSDK();
235#endif
238#if MANAGE_XR
239 async void InitMXRSDK()
241 Debug.Log("Initializing the ManageXR SDK");
242 await MXRManager.InitAsync();
243 MXRManager.System.OnDeviceStatusChange += OnDeviceStatusChanged;
244 deviceSerialNumber = MXRManager.System.DeviceStatus.serial;
245 Debug.Log($"Device serial set to {deviceSerialNumber}");
247
248 void OnDeviceStatusChanged(DeviceStatus newDeviceStatus)
250 deviceSerialNumber = newDeviceStatus.serial;
251 Debug.Log($"Device serial number changed to {deviceSerialNumber}");
253#endif
255 void SetupDeepLinking()
257 Application.deepLinkActivated += OnDeepLinkActivated;
258 if (!string.IsNullOrEmpty(Application.absoluteURL))
260 // Cold start and Application.absoluteURL not null so process Deep Link.
261 OnDeepLinkActivated(Application.absoluteURL);
263 }
265 void OnDeepLinkActivated(string url)
266 {
267 // Update DeepLink Manager global variable, so URL can be accessed from anywhere.
268 var urlArguments = PixoPlatformUtilities.ParseURLArguments(url);
269 _ParsePassedData(urlArguments);
270 }
271
273 {
274 Debug.Log("SetupPlatformConfiguration");
275
276#if UNITY_ANDROID
278 {
279 Debug.Log("Found pixoconfig.cnf");
280
281 string configContent = PixoAndroidUtils.ReadFileFromSharedStorage("pixoconfig.cnf");
282
283 if (configContent.Length > 0)
284 {
285 Debug.Log("Configuration is not empty.");
286 ConfigurationTypes configData = JsonConvert.DeserializeObject<ConfigurationTypes>(configContent);
287 if (configData == null)
288 {
289 Debug.Log("Failed to deserialize the config.");
290 return;
291 }
292
293 // Parse out the platform target to utilize the unity built in config values
294 if (configData.Platform.Contains("NA", StringComparison.CurrentCultureIgnoreCase))
295 {
296 if (configData.Platform.Contains("Production", StringComparison.CurrentCultureIgnoreCase))
297 {
298 Debug.Log("NA Production platform target.");
299 PlatformTargetServer = PlatformServer.NA_PRODUCTION;
300 }
301
302 if (configData.Platform.Contains("Dev", StringComparison.CurrentCultureIgnoreCase))
304 Debug.Log("NA Dev platform target.");
306 }
307
308 if (configData.Platform.Contains("Stage", StringComparison.CurrentCultureIgnoreCase))
309 {
310 Debug.Log("NA Stage platform target.");
312 }
314 else if (configData.Platform.Contains("SA", StringComparison.CurrentCultureIgnoreCase))
315 {
316 Debug.Log("SA Production platform target.");
317 PlatformTargetServer = PlatformServer.SA_PRODUCTION;
318 }
319
320 // TODO (MGruber): Add a custom value, but this requires multiple configuration values to be saved.
321 // Need to save the normal headset api endpoint, web api endpoint and platform api endpoint. 3 VALUES! D:
322 }
323 }
324#endif
325 }
326
327 void SetupAPI()
328 {
329 Debug.Log("Mac Address: " + ApexUtils.GetMacAddress());
330 if (serverIP.Length == 0)
331 {
333 }
334
336
337 if (apexAPIHandler != null)
338 {
339 Debug.Log("[ApexSystem] Apex API Handler is not null!");
340 }
341
342 // TODO: Move to new plugin
345 apexAPIHandler.OnAPIResponse += OnAPIResponse;
346
347 if (webSocket != null)
348 {
350 {
352 }
353 }
354
355 webSocket = new ApexWebsocket();
357 webSocket.OnConnectFailed.AddListener((reason) => OnWebSocketConnectFailed(reason));
358 webSocket.OnReceive.AddListener((data) => OnWebSocketReceive(data));
359 webSocket.OnClosed.AddListener((reason) => OnWebSocketClosed(reason));
360
362
363 var applicationArugments = PixoPlatformUtilities.ParseApplicationArguments();
364 _ParsePassedData(applicationArugments);
365 if(!string.IsNullOrEmpty(loginToken))
366 {
367 Debug.Log($"[ApexSystem] Login Token: {loginToken}");
368 }
369 }
370
371 // TODO: Rename the entered 'returnTarget' and the passed returnTargetParameter.
372 void _ExitApplication(string returnTarget)
373 {
374 Debug.Log("ApexSystem::_ExitApplication");
375 if (returnTarget == null)
376 {
377 returnTarget = "";
378 }
379
380 string returnTargetType = "app";
381
382 if (returnTarget.Contains("://"))
383 {
384 returnTargetType = "url";
385 }
386
387 Debug.Log("[ApexSystem] " + returnTarget + " " + returnTargetType);
388
389 string parameters = "";
390
391 Debug.Log("[ApexSystem] Building parameters for url.");
392
393 if (CurrentActiveLogin != null)
394 {
395 parameters += "pixotoken=" + CurrentActiveLogin.Token;
396 }
397 else if (!string.IsNullOrEmpty(loginToken))
398 {
399 parameters += "pixotoken=" + loginToken;
400 }
401
402 if (optionalParameter != null)
403 {
404 if (optionalParameter.Length > 0)
405 {
406 if (parameters.Length > 0)
407 parameters += "&";
408 parameters += "optional=" + optionalParameter;
409 }
410 }
411
412 if (returnTarget.Length > 0)
413 {
414 if (parameters.Length > 0)
415 parameters += "&";
416 parameters += "returntarget=" + returnTarget;
417 }
418
419 if (returnTargetType.Length > 0)
421 if (parameters.Length > 0)
422 parameters += "&";
423 parameters += "targettype=" + returnTargetType;
424 }
425
426 Debug.Log("[ApexSystem] Checking the return target parameter.");
427
428 if (!string.IsNullOrEmpty(returnTargetParameter))
429 {
430 Debug.Log("[ApexSystem] Had a valid return target parameter.");
431 if (targetTypeParameter.Equals("url", StringComparison.OrdinalIgnoreCase))
432 {
433 Debug.Log("[ApexSystem] Return Target is a URL.");
434
435 string returnURL = returnTargetParameter;
436 if (!string.IsNullOrEmpty(parameters))
437 {
438 if (!returnURL.Contains('?'))
439 returnURL += "?";
440 else
441 returnURL += "&";
442
443 returnURL += parameters;
444 }
445 Debug.Log("Custom Target: " + returnURL);
447 return;
448 }
449 else
450 {
451 Debug.Log($"[ApexSystem] Return Target is a package name. {returnTargetParameter}");
452
453 List<string> keys = new List<string>(),
454 values = new List<string>();
455
456 Debug.Log("[ApexSystem] Adding pixo token.");
457
458 if (CurrentActiveLogin != null)
459 {
460 keys.Add("pixotoken");
461 values.Add(CurrentActiveLogin.Token);
462 }
463 else if (!string.IsNullOrEmpty(loginToken))
464 {
465 keys.Add("pixotoken");
466 values.Add(loginToken);
467 }
468
469 Debug.Log("[ApexSystem] Adding optional.");
470
471 if (!string.IsNullOrEmpty(optionalParameter))
472 {
473 keys.Add("optional");
474 values.Add(optionalParameter);
475 }
476
477 Debug.Log("[ApexSystem] Adding return target.");
478
479 if (!string.IsNullOrEmpty(returnTarget))
480 {
481 keys.Add("returntarget");
482 values.Add(returnTarget);
483 }
484
485 Debug.Log("[ApexSystem] Adding return target type.");
486
487 if (!string.IsNullOrEmpty(returnTargetType))
488 {
489 keys.Add("targettype");
490 values.Add(returnTargetType);
491 }
492
493 PixoPlatformUtilities.OpenApplication(returnTargetParameter, keys.ToArray(), values.ToArray());
494 return;
495 }
496 }
497
499 }
500
501 string GetEndpointFromTarget(PlatformServer target)
502 {
503 return target.ToUrlString();
504 }
505
506 string GetWebEndpointFromPlatformTarget(PlatformServer target)
507 {
508 int targetValue = (int)target;
509 WebPlatformServer webTarget = (WebPlatformServer)targetValue;
510
511 return webTarget.ToUrlString();
512 }
513
514 string GetPlatformEndpointFromPlatformTarget(PlatformServer target)
515 {
516 int targetValue = (int)target;
517 APIPlatformServer apiTarget = (APIPlatformServer)targetValue;
518
519 return apiTarget.ToUrlString();
520 }
521
523 {
525
526 if (webSocketUrl.Contains("://"))
527 {
528 webSocketUrl = webSocketUrl.Split(new string[] { "://" }, 2, StringSplitOptions.RemoveEmptyEntries)[1];
529 }
530
531 if (webSocketUrl.Contains("/"))
532 {
533 webSocketUrl = webSocketUrl.Split(new string[] { "/" }, 2, StringSplitOptions.RemoveEmptyEntries)[0];
534 }
535
536 webSocketUrl = "wss://" + webSocketUrl + "/ws";
537 }
538
539 void Start()
540 {
542 {
543 Debug.LogWarning($"{moduleVersion} is an invalid module version.");
544 }
545 deviceID = SystemInfo.deviceUniqueIdentifier;
546 deviceModel = SystemInfo.deviceModel;
547 platform =
548 XRSettings.loadedDeviceName.Length > 0 ? XRSettings.loadedDeviceName : Application.platform.ToString();
549 clientIP = Utils.ApexUtils.GetLocalIP();
550 }
551
552 private void FixedUpdate()
553 {
554 if (webSocket != null)
555 {
557 }
558
560 {
561 heartbeatTimer -= Time.fixedDeltaTime;
563 if (heartbeatTimer <= 0.0f)
564 {
567 }
568 }
569 }
571 void ConnectWebsocket()
572 {
573 socketConnectTask = Task.Run(() => webSocket.Connect(new Uri(webSocketUrl)));
574 }
575
577 {
578 socketDisconnectTask = Task.Run(() => webSocket.CloseSocket());
579 }
580
582 {
583 Debug.Log("Websocket connected successfully.");
584 }
585
586 void OnWebSocketConnectFailed(string reason)
588 Debug.LogError("Websocket failed to connect with error: " + reason);
589 }
590
591 void OnWebSocketReceive(string data)
592 {
593 Debug.Log("Websocket received: " + data);
594 try
595 {
596 if (data.Contains("auth_code"))
597 {
598 var authCode = JsonConvert.DeserializeObject<AuthorizationCode>(data);
599 OnAuthorizationCodeReceived.Invoke(authCode.Code);
601
602 if (data.Contains("Token", StringComparison.OrdinalIgnoreCase))
603 {
604 object loginResponse = JsonConvert.DeserializeObject<LoginResponseContent>(data);
605 HandleLogin(true, loginResponse);
606 }
607 }
608 catch (Exception ex)
609 {
610 Debug.Log(ex.Message);
611 }
612 }
613
614 void OnWebSocketClosed(System.Net.WebSockets.WebSocketCloseStatus reason)
615 {
616 Debug.Log("Websocket closed with reason: " + reason);
617 }
618
620 {
621 if (IsModuleVersionOnlyNumerical() == false)
622 return false;
623
624 string[] moduleVersionParts = moduleVersion.Split('.');
625
626 if (moduleVersionParts.Length != 3)
627 return false;
628
629 if (!IsModuleMajorVersionPartValid(moduleVersionParts[(int)VersionParts.Major]))
630 return false;
631
632 if (!IsModuleNonMajorVersionPartValid(moduleVersionParts[(int)VersionParts.Minor]))
633 return false;
635 if (!IsModuleNonMajorVersionPartValid(moduleVersionParts[(int)VersionParts.Patch]))
636 return false;
637
638 return true;
640
641 static readonly Regex VersionValidator = new Regex(@"^[0123456789.]+$");
642
644 {
645 return VersionValidator.IsMatch(moduleVersion);
646 }
647
648 bool IsModuleNonMajorVersionPartValid(string modulePart)
649 {
650 if (modulePart.Length <= 0)
651 return false;
652
653 if (modulePart.Length > 2)
654 return false;
655
656 return true;
657 }
658
659 bool IsModuleMajorVersionPartValid(string modulePart)
660 {
661 if (modulePart.Length <= 0)
662 return false;
663
664 if (modulePart.StartsWith("0"))
665 return false;
666
667 return true;
668 }
669
670 [Obsolete("ReturnToHub has been deprecated, please use ExitApplication.", true)]
671 public static void ReturnToHub()
672 {
673 Instance._ReturnToHub();
674 }
675
676 public static void ExitApplication(string returnTarget = "")
677 {
678 Instance._ExitApplication(returnTarget);
679 }
680
681 public static bool RequestAuthorizationCode()
682 {
683 return Instance._RequestAuthorizationCode();
684 }
685
686 public static void ChangePlatformServer(PlatformServer newServer)
687 {
688 Instance._ChangePlatformServer(newServer);
690
691 public static void Ping()
692 {
693 Instance._Ping();
694 }
695
696 public static bool LoginWithToken()
697 {
698 return LoginWithToken(Instance.loginToken);
699 }
700
701 public static bool LoginWithToken(string token)
702 {
703 return Instance._LoginWithToken(token);
704 }
705
706 public static bool Login(LoginData login)
708 return Instance._Login(login);
709 }
710
711 public static bool Login(string username, string password)
712 {
713 return Instance._Login(username, password);
714 }
715
716 public static bool CheckModuleAccess(int targetModuleID = -1)
717 {
718 return Instance._CheckModuleAccess(targetModuleID);
720
721 public static bool JoinSession(string scenarioID = null, Extension contextExtension = null)
722 {
723 return Instance._JoinSession(scenarioID, contextExtension);
725
726 public static bool CompleteSession(
727 SessionData currentSessionData,
728 Extension contextExtension = null,
729 Extension resultExtension = null
730 )
731 {
732 return Instance._CompleteSession(currentSessionData, contextExtension, resultExtension);
733 }
735 public static bool SendSimpleSessionEvent(string action, string targetObject, Extension contextExtension)
736 {
737 return Instance._SendSimpleSessionEvent(action, targetObject, contextExtension);
738 }
740 public static bool SendSessionEvent(Statement eventStatement)
741 {
742 return Instance._SendSessionEvent(eventStatement);
743 }
745 public static bool GetCurrentUser()
746 {
747 return GetUser();
748 }
750 public static bool GetUser(int userId = -1)
751 {
752 return Instance._GetUser(userId);
753 }
755 public static bool GetCurrentUserModules()
756 {
757 return GetUserModules();
758 }
760 public static bool GetUserModules(int userId = -1)
761 {
762 return Instance._GetUserModules(userId);
763 }
765 public static bool GetModulesList(string platformName)
766 {
767 return Instance._GetModuleList(platformName);
768 }
770 public static bool GetQuickIDAuthUsers(string serialNumber)
771 {
772 return Instance._GetQuickIDAuthUsers(serialNumber);
773 }
775 public static bool QuickIDLogin(string serialNumber, string username)
776 {
777 return Instance._QuickIDLogin(serialNumber, username);
778 }
779
780 protected void _ChangePlatformServer(PlatformServer newServer)
781 {
782 PlatformTargetServer = newServer;
784 SetupAPI();
785 }
786
787 protected void _Ping()
790 }
791
792 public bool _LoginWithToken(string token)
794 if (token.Length <= 0)
795 {
796 return false;
797 }
799 Debug.Log($"[ApexSystem] Logging in with token: {token}");
801
802 return true;
804
805 protected bool _Login(LoginData login)
806 {
807 Debug.Log("[ApexSystem] _Login called.");
808 if (apexAPIHandler == null)
809 {
810 Debug.Log("[ApexSystem] API Handler is null.");
811 OnLoginFailed.Invoke(
813 "There was an error reaching the platform, please contact your administrator."
814 )
815 );
816 return false;
817 }
819 if (login.Login.Length <= 0)
820 {
821 Debug.Log("[Login] No user name.");
822 OnLoginFailed.Invoke(GenerateFailureResponse("No username or email entered."));
823 return false;
824 }
825
826 if (login.Password.Length <= 0)
827 {
828 Debug.Log("[Login] No password.");
829 login.Password = "<empty>";
830 }
831
832 apexAPIHandler.Login(login);
833
834 Debug.Log("[ApexSystem] Login called.");
836 return true;
837 }
838
839 protected bool _Login(string username, string password)
841 return _Login(new LoginData(username, password));
842 }
843
844 protected FailureResponse GenerateFailureResponse(string message)
845 {
846 FailureResponse failureResponse = new FailureResponse();
847 failureResponse.Error = "true";
848 failureResponse.HttpCode = "400";
849 failureResponse.Message = message;
850
851 return failureResponse;
852 }
854 protected void _ParsePassedData(Dictionary<string, string> arguments)
855 {
856 if (arguments == null)
857 {
858 Debug.Log("No arguments found for the application.");
859 return;
860 }
861
862 if (arguments.ContainsKey("optional"))
863 optionalParameter = arguments["optional"];
864
865 if (arguments.ContainsKey("returntarget"))
866 returnTargetParameter = arguments["returntarget"];
867
868 if (arguments.ContainsKey("targettype"))
869 targetTypeParameter = arguments["targettype"];
870
871 if (arguments.ContainsKey("pixotoken"))
872 loginToken = arguments["pixotoken"];
873 }
874
875
876
877 public bool _CheckModuleAccess(int targetModuleID = -1)
878 {
879 Debug.Log("[ApexSystem] _CheckModuleAccess called.");
880
881 if (currentActiveLogin == null)
882 {
883 Debug.LogError("[ApexSystem] Cannot check user's module access with no active login.");
884 return false;
885 }
886
887 if (targetModuleID <= -1)
888 {
889 targetModuleID = moduleID;
890 }
891
893
894 return true;
895 }
896
897 protected bool _JoinSession(string newScenarioID = null, Extension contextExtension = null)
898 {
899 if (currentActiveLogin == null)
900 {
901 Debug.LogError("[ApexSystem] Cannot join session with no active login.");
902 return false;
903 }
904
905 if (userAccessVerified == false)
906 {
907 return false;
908 }
909
910 if (newScenarioID != null)
911 {
912 scenarioID = newScenarioID;
913 }
914
915 if (sessionInProgress == true)
916 {
917 Debug.LogError(
918 "[ApexSystem] Session is already in progress."
919 + " The previous session didn't complete or a new session was started during an active session."
920 );
921 }
922
923 currentSessionID = Guid.NewGuid();
924
925 Statement sessionStatement = new Statement();
926 Agent sessionActor = new Agent();
927 sessionActor.mbox = currentActiveLogin.Email;
928
929 Verb sessionVerb = new Verb();
930 sessionVerb.id = ApexVerbs.JOINED_SESSION;
931 sessionVerb.display = new LanguageMap();
932 sessionVerb.display.Add("en", "Joined Session");
933
934 Activity sessionActivity = new Activity();
935 sessionActivity.id = string.Format("https://pixovr.com/xapi/objects/{0}/{1}", moduleID, scenarioID);
936
937 Context sessionContext = new Context();
938 sessionContext.registration = currentSessionID;
939 sessionContext.revision = moduleVersion;
940 sessionContext.platform = platform;
941
942 sessionContext.extensions = AppendStandardContextExtension(contextExtension);
943
944 sessionStatement.actor = sessionActor;
945 sessionStatement.verb = sessionVerb;
946 sessionStatement.target = sessionActivity;
947 sessionStatement.context = sessionContext;
948
949 JoinSessionData sessionData = new JoinSessionData();
950 sessionData.DeviceId = deviceID;
951 sessionData.IpAddress = clientIP;
952 sessionData.ModuleId = moduleID;
953 sessionData.Uuid = currentSessionID.ToString();
954 sessionData.EventType = ApexEventTypes.PIXOVR_SESSION_JOINED;
955 sessionData.JsonData = sessionStatement;
956
958
959 return true;
960 }
961
962 protected bool _SendSimpleSessionEvent(string verbName, string targetObject, Extension contextExtension)
963 {
964 if (userAccessVerified == false)
965 return false;
966
967 if (verbName == null)
968 return false;
969
970 if (verbName.Length == 0)
971 return false;
972
973 Statement sessionStatement = new Statement();
974 Agent sessionActor = new Agent();
975 sessionActor.mbox = currentActiveLogin.Email;
976
977 Verb sessionVerb = new Verb();
978 sessionVerb.id = new Uri("https://pixovr.com/xapi/verbs/" + verbName.Replace(' ', '_').ToLower());
979 sessionVerb.display = new LanguageMap();
980 sessionVerb.display.Add("en", verbName);
981
982 Activity sessionActivity = new Activity();
983 sessionActivity.id = string.Format(
984 "https://pixovr.com/xapi/objects/{0}/{1}/{2}",
985 moduleID,
987 targetObject.Replace(' ', '_').ToLower()
988 );
989
990 Context sessionContext = new Context();
991 sessionContext.registration = currentSessionID;
992 sessionContext.revision = moduleVersion;
993 sessionContext.platform = platform;
994
995 sessionContext.extensions = AppendStandardContextExtension(contextExtension);
996
997 sessionStatement.actor = sessionActor;
998 sessionStatement.verb = sessionVerb;
999 sessionStatement.target = sessionActivity;
1000 sessionStatement.context = sessionContext;
1001
1002 SessionEventData sessionEvent = new SessionEventData();
1003 sessionEvent.DeviceId = deviceID;
1004 sessionEvent.ModuleId = ModuleID;
1005 sessionEvent.Uuid = currentSessionID.ToString();
1006 sessionEvent.EventType = ApexEventTypes.PIXOVR_SESSION_EVENT;
1007 sessionEvent.JsonData = sessionStatement;
1008
1011 return true;
1012 }
1013
1014 protected bool _SendSessionEvent(Statement eventStatement)
1015 {
1016 if (userAccessVerified == false)
1017 {
1018 return false;
1019 }
1020
1021 if (currentActiveLogin == null)
1022 {
1023 Debug.LogError("[ApexSystem] Cannot send a session event with no active login.");
1024 return false;
1025 }
1026
1027 if (sessionInProgress == false)
1028 {
1029 Debug.LogError("[ApexSystem] No session in progress to send event for.");
1030 return false;
1031 }
1032
1033 if (eventStatement == null)
1034 {
1035 Debug.LogError("[ApexSystem] No event data to send.");
1036 return false;
1037 }
1038
1039 if (eventStatement.actor != null)
1040 {
1041 Debug.LogWarning("[ApexSystem] Actor data should not be filled out.");
1042 }
1043
1044 if (eventStatement.verb == null)
1045 {
1046 Debug.LogError("[ApexSystem] Verb missing from eventStatement.");
1047 return false;
1048 }
1049
1050 if (eventStatement.verb.id == null)
1051 {
1052 Debug.LogError("[ApexSystem] verb.id missing from eventStatement.");
1053 return false;
1054 }
1055
1056 if (eventStatement.target == null)
1057 {
1058 Debug.LogError("[ApexSystem] Object (target) missing from eventStatement.");
1059 return false;
1060 }
1061
1062 eventStatement.actor = new Agent();
1063 eventStatement.actor.mbox = currentActiveLogin.Email;
1064
1065 if (eventStatement.context == null)
1066 {
1067 eventStatement.context = new Context();
1068 }
1069
1070 eventStatement.context.registration = currentSessionID;
1071 eventStatement.context.revision = ModuleVersion;
1072 eventStatement.context.platform = platform;
1073
1074 eventStatement.context.extensions = AppendStandardContextExtension(eventStatement.context.extensions);
1075
1076 SessionEventData sessionEvent = new SessionEventData();
1077 sessionEvent.DeviceId = deviceID;
1078 sessionEvent.ModuleId = ModuleID;
1079 sessionEvent.Uuid = currentSessionID.ToString();
1080 sessionEvent.EventType = ApexEventTypes.PIXOVR_SESSION_EVENT;
1081 sessionEvent.JsonData = eventStatement;
1082
1084
1085 return true;
1086 }
1087
1088 protected bool _CompleteSession(
1089 SessionData currentSessionData,
1090 Extension contextExtension,
1091 Extension resultExtension
1092 )
1093 {
1094 if (userAccessVerified == false)
1095 {
1096 return false;
1097 }
1098
1099 if (currentActiveLogin == null)
1100 {
1101 Debug.LogError("[ApexSystem] Cannot complete session with no active login.");
1102 return false;
1103 }
1104
1105 if (sessionInProgress == false)
1106 {
1107 Debug.LogError("[ApexSystem] No session in progress to complete.");
1108 return false;
1109 }
1110
1111 // Create our actor
1112 Agent sessionActor = new Agent();
1113 sessionActor.mbox = currentActiveLogin.Email;
1114
1115 // Create our verb
1116 Verb sessionVerb = new Verb();
1117 sessionVerb.id = ApexVerbs.COMPLETED_SESSION;
1118 sessionVerb.display = new LanguageMap();
1119 sessionVerb.display.Add("en", "Completed Session");
1120
1121 // Create the session activity
1122 Activity sessionActivity = new Activity();
1123 sessionActivity.id = string.Format("https://pixovr.com/xapi/objects/{0}/{1}", moduleID, scenarioID);
1124
1125 // Create our context
1126 Context sessionContext = new Context();
1127 sessionContext.registration = currentSessionID;
1128 sessionContext.revision = moduleVersion;
1129 sessionContext.platform = platform;
1130
1131 sessionContext.extensions = AppendStandardContextExtension(contextExtension);
1132
1133 // Create our results
1134 Result sessionResult = new Result();
1135 sessionResult.completion = currentSessionData.Complete;
1136 sessionResult.success = currentSessionData.Success;
1137 // Add score to the results
1138 sessionResult.score = new Score();
1139 sessionResult.score.min = currentSessionData.MinimumScore;
1140 sessionResult.score.max = currentSessionData.MaximumScore;
1141 sessionResult.score.raw = currentSessionData.Score;
1142 sessionResult.score.scaled = DetermineScaledScore(
1143 currentSessionData.ScaledScore,
1144 currentSessionData.Score,
1145 currentSessionData.MaximumScore
1146 );
1147 sessionResult.duration = TimeSpan.FromSeconds(currentSessionData.Duration);
1148 if (resultExtension != null)
1149 {
1150 sessionResult.extensions = new Extensions(resultExtension.ToJObject());
1151 }
1152
1153 // Create our statement and add the pieces
1154 Statement sessionStatement = new Statement();
1155 sessionStatement.actor = sessionActor;
1156 sessionStatement.verb = sessionVerb;
1157 sessionStatement.target = sessionActivity;
1158 sessionStatement.context = sessionContext;
1159 sessionStatement.result = sessionResult;
1160
1161 CompleteSessionData sessionData = new CompleteSessionData();
1162 sessionData.DeviceId = deviceID;
1163 sessionData.ModuleId = moduleID;
1164 sessionData.Uuid = currentSessionID.ToString();
1165 sessionData.EventType = ApexEventTypes.PIXOVR_SESSION_COMPLETE;
1166 sessionData.JsonData = sessionStatement;
1167 sessionData.SessionDuration = currentSessionData.Duration;
1168 sessionData.Score = currentSessionData.Score;
1169 sessionData.ScoreMin = currentSessionData.MinimumScore;
1170 sessionData.ScoreMax = currentSessionData.MaximumScore;
1171 sessionData.ScoreScaled = DetermineScaledScore(
1172 currentSessionData.ScaledScore,
1173 currentSessionData.Score,
1174 currentSessionData.MaximumScore
1175 );
1176
1178
1179 return true;
1180 }
1181
1182 protected bool _SendHeartbeat()
1183 {
1184 Debug.Log("Sending heartbeat...");
1185 if (!sessionInProgress)
1186 return false;
1187
1188 if (currentActiveLogin == null)
1189 return false;
1190
1192
1193 return true;
1194 }
1195
1196 protected bool _GetUser(int userId = -1)
1197 {
1198 if (currentActiveLogin == null)
1199 return false;
1200
1201 if (userId < 0)
1202 {
1203 userId = currentActiveLogin.ID;
1204 }
1205
1207 return true;
1208 }
1209
1210 protected bool _GetUserModules(int userId = -1)
1211 {
1212 if (currentActiveLogin == null)
1213 return false;
1214
1215 if (userId < 0)
1216 {
1217 userId = currentActiveLogin.ID;
1218 }
1219
1221 return true;
1222 }
1223
1224 protected bool _GetModuleList(string platformName)
1225 {
1226 if (currentActiveLogin == null)
1227 return false;
1228
1230 return true;
1231 }
1232
1233 protected bool _GetQuickIDAuthUsers(string serialNumber)
1234 {
1235 if (String.IsNullOrEmpty(serialNumber)) return false;
1237 return true;
1238 }
1239
1240
1241 protected bool _QuickIDLogin(string serialNumber, string username)
1242 {
1243 if (String.IsNullOrEmpty(serialNumber) || string.IsNullOrEmpty(username)) return false;
1244 var loginData = new QuickIDLoginData(serialNumber, username);
1245 apexAPIHandler.QuickIDLogin(loginData);
1246 return true;
1247 }
1248
1249 private float DetermineScaledScore(float scaledScore, float score, float maxScore)
1250 {
1251 float determinedScaledScore = scaledScore;
1252
1253 if (scaledScore < Mathf.Epsilon && score >= Mathf.Epsilon)
1254 {
1255 determinedScaledScore = (score / maxScore) * 100f;
1256 }
1257
1258 return determinedScaledScore;
1259 }
1260
1261 private Extensions AppendStandardContextExtension(Extensions currentContextExtensions)
1262 {
1263 return AppendStandardContextExtension(new Extension(currentContextExtensions.ToJObject()));
1264 }
1265
1266 private Extensions AppendStandardContextExtension(Extension currentContextExtension)
1267 {
1268 Extension contextExtension;
1269 if (currentContextExtension != null)
1270 {
1271 contextExtension = currentContextExtension;
1273 else
1274 {
1275 contextExtension = new Extension();
1276 }
1277
1278 contextExtension.Add(ApexExtensionStrings.MODULE_ID, moduleID.ToString());
1279 contextExtension.AddSimple("device_id", deviceID);
1280 contextExtension.AddSimple("device_model", deviceModel);
1281 contextExtension.AddSimple("sdk_version", "unity-" + ApexUtils.SDKVersion);
1282
1283 if(string.IsNullOrEmpty(deviceSerialNumber))
1284 {
1285 contextExtension.AddSimple("device_serial", deviceSerialNumber.ToString());
1286 }
1287
1288 return new Extensions(contextExtension.ToJObject());
1290
1291 protected void OnAPIResponse(ResponseType response, HttpResponseMessage message, object responseData)
1292 {
1293 Debug.Log("[ApexSystem] On API Response");
1294 bool success = message.IsSuccessStatusCode;
1295 if (responseData is FailureResponse)
1296 {
1297 success = success && (responseData is IFailure) && (!(responseData as FailureResponse).HasErrored());
1298 }
1299
1300 switch (response)
1301 {
1302 case ResponseType.RT_PING:
1303 {
1304 if (success)
1305 {
1306 Debug.Log("[ApexSystem] Ping successful.");
1307 OnPingSuccess.Invoke(message);
1308 }
1309 else
1310 {
1311 Debug.Log("[ApexSystem] Ping failed.");
1312 OnPingFailed.Invoke(message);
1313 }
1314 break;
1315 }
1316 case ResponseType.RT_LOGIN:
1317 {
1318 Debug.Log("[ApexSystem] Calling to handle login.");
1319 HandleLogin(success, responseData);
1320 break;
1321 }
1322 case ResponseType.RT_GET_USER:
1323 {
1324 if (success)
1325 {
1326 OnGetUserSuccess.Invoke(responseData as GetUserResponseContent);
1327 }
1328 else
1329 {
1330 FailureResponse failureData = responseData as FailureResponse;
1331 Debug.Log(string.Format("[ApexSystem] Failed to get user.\nError: {0}", failureData.Message));
1332 OnGetUserFailed.Invoke(responseData as FailureResponse);
1333 }
1334 break;
1335 }
1336 case ResponseType.RT_GET_USER_MODULES:
1337 {
1338 if (success)
1340 OnGetUserModulesSuccess.Invoke(responseData as GetUserModulesResponse);
1341 }
1342 else
1343 {
1344 FailureResponse failureData = responseData as FailureResponse;
1345 Debug.Log(string.Format("[ApexSystem] Failed to get user.\nError: {0}", failureData.Message));
1346 OnGetUserFailed.Invoke(responseData as FailureResponse);
1347 }
1348 break;
1349 }
1350 case ResponseType.RT_SESSION_JOINED:
1351 {
1352 if (success)
1353 {
1354 JoinSessionResponse joinSessionResponse = responseData as JoinSessionResponse;
1355 Debug.Log(string.Format("[ApexSystem] Session Id is {0}.", joinSessionResponse.SessionId));
1356 heartbeatSessionID = joinSessionResponse.SessionId;
1357 sessionInProgress = true;
1358 OnJoinSessionSuccess.Invoke(message);
1359 }
1360 else
1361 {
1362 FailureResponse failureData = responseData as FailureResponse;
1363 Debug.Log(
1364 string.Format("[ApexSystem] Failed to join session.\nError: {0}", failureData.Message)
1365 );
1366 currentSessionID = Guid.Empty;
1367 sessionInProgress = false;
1368 OnJoinSessionFailed.Invoke(responseData as FailureResponse);
1369 }
1370 break;
1371 }
1372 case ResponseType.RT_SESSION_COMPLETE:
1373 {
1374 if (success)
1375 {
1376 sessionInProgress = false;
1377 currentSessionID = Guid.Empty;
1378 OnCompleteSessionSuccess.Invoke(message);
1379 }
1380 else
1381 {
1382 FailureResponse failureData = responseData as FailureResponse;
1383 Debug.Log(
1384 string.Format("[ApexSystem] Failed to complete session.\nError: {0}", failureData.Message)
1385 );
1386 OnCompleteSessionFailed.Invoke(responseData as FailureResponse);
1387 }
1388 break;
1389 }
1390 case ResponseType.RT_SESSION_EVENT:
1391 {
1392 if (success)
1393 {
1394 Debug.Log("[ApexSystem] Session event sent.");
1395 OnSendEventSuccess.Invoke(message);
1396 }
1397 else
1398 {
1399 FailureResponse failureData = responseData as FailureResponse;
1400 Debug.Log(
1401 string.Format("[ApexSystem] Failed to send session event.\nError: {0}", failureData.Message)
1402 );
1403 OnSendEventFailed.Invoke(responseData as FailureResponse);
1404 }
1405 break;
1406 }
1407 case ResponseType.RT_GET_USER_ACCESS:
1408 {
1409 if (success)
1410 {
1411 var userAccessResponseContent = responseData as UserAccessResponseContent;
1412 if (userAccessResponseContent.Access)
1413 {
1414 if (userAccessResponseContent.PassingScore.HasValue)
1415 {
1416 currentActiveLogin.MinimumPassingScore = userAccessResponseContent.PassingScore.Value;
1417 }
1418
1419 userAccessVerified = true;
1421 }
1422 else
1423 {
1424 currentActiveLogin = null;
1425 userAccessVerified = false;
1426 OnModuleAccessFailed.Invoke(
1427 new FailureResponse()
1428 {
1429 Error = "True",
1430 HttpCode = "401",
1431 Message = "User does not have access to module",
1432 }
1433 );
1434 }
1435 }
1436 else
1437 {
1438 FailureResponse failureData = responseData as FailureResponse;
1439 Debug.Log(
1440 string.Format(
1441 "[ApexSystem] Failed to get users module access data.\nError: {0}",
1442 failureData.Message
1443 )
1444 );
1445
1446 OnModuleAccessFailed.Invoke(responseData as FailureResponse);
1447 }
1448 break;
1449 }
1450 case ResponseType.RT_GET_MODULES_LIST:
1451 {
1452 if (success)
1453 {
1454 OnGetOrganizationModulesSuccess.Invoke(responseData as List<OrgModule>);
1455 }
1456 else
1457 {
1458 FailureResponse failureData = responseData as FailureResponse;
1459 Debug.Log(
1460 string.Format("[ApexSystem] Failed to get org modules.\nError: {0}", failureData.Message)
1461 );
1462
1463 OnGetOrganizationModulesFailed.Invoke(responseData as FailureResponse);
1464 }
1465
1466 break;
1467 }
1468 case ResponseType.RT_GEN_AUTH_LOGIN:
1469 {
1470 if (success)
1471 {
1473 }
1474 else
1475 {
1476 FailureResponse failureData = responseData as FailureResponse;
1477 Debug.Log(string.Format("[ApexSystem] Failed to get module.\nError: {0}", failureData.Message));
1478 OnGeneratedAssistedLoginFailed.Invoke(responseData as FailureResponse);
1479 }
1480 break;
1481 }
1482 case ResponseType.RT_QUICK_ID_AUTH_GET_USERS:
1483 {
1484 if (success)
1485 {
1487 }
1488 else
1489 {
1490 FailureResponse failureData = responseData as FailureResponse;
1491 Debug.Log(string.Format("[ApexSystem] Failed to get Quick ID Authentication users.\nError: {0}", failureData.Message));
1492 OnGetQuickIDAuthGetUsersFailed.Invoke(responseData as FailureResponse);
1493 }
1494 break;
1495 }
1496
1497 case ResponseType.RT_QUICK_ID_AUTH_LOGIN:
1498 {
1499 HandleLogin(success, responseData);
1500 if (success)
1501 {
1502 OnQuickIDAuthLoginSuccess.Invoke(responseData as LoginResponseContent);
1503 }
1504 else
1505 {
1506 FailureResponse failureData = responseData as FailureResponse;
1507 Debug.Log(string.Format("[ApexSystem] Failed to authenticate with Quick ID Authentication.\nError: {0}", failureData.Message));
1508 OnQuickIDAuthLoginFailed.Invoke(responseData as FailureResponse);
1509 }
1510 break;
1511 }
1512
1513 default:
1514 {
1515 break;
1516 }
1517 }
1518
1519 if (OnPlatformResponse != null)
1520 {
1521 OnPlatformResponse.Invoke(response, success, responseData);
1522 }
1523 }
1524
1525 protected void HandleLogin(bool successful, object responseData)
1526 {
1527 Debug.Log("[ApexSystem] Handling Login");
1528 userAccessVerified = false;
1529
1530 if (successful)
1531 {
1532 currentActiveLogin = responseData as LoginResponseContent;
1533
1534 OnLoginSuccess.Invoke();
1535
1537 {
1539 }
1540 }
1541 else
1542 {
1543 FailureResponse failureData = responseData as FailureResponse;
1544 Debug.Log(string.Format("[ApexSystem] Failed to log in.\nError: {0}", failureData.Message));
1545 OnLoginFailed.Invoke(responseData as FailureResponse);
1546 }
1547 }
1548
1549 void _ReturnToHub()
1550 {
1551 var token = currentActiveLogin.Token;
1552
1553 if (
1554 serverIP.Contains("apexsa.", StringComparison.CurrentCultureIgnoreCase)
1555 || serverIP.Contains("saudi.", StringComparison.CurrentCultureIgnoreCase)
1556 )
1557 {
1558 Debug.Log($"pixovr://com.PixoVR.SA_TrainingAcademy?pixotoken={token}");
1559 Application.OpenURL($"pixovr://com.PixoVR.SA_TrainingAcademy?pixotoken={token}");
1560 }
1561 else
1562 {
1563 Debug.Log($"pixovr://com.PixoVR.PixoHub?pixotoken={token}");
1564 Application.OpenURL($"pixovr://com.PixoVR.PixoHub?pixotoken={token}");
1565 }
1566 }
1567
1569 {
1570 if (!webSocket.IsConnected())
1571 {
1575 }
1576
1577 public static bool GenerateOneTimeLoginForCurrentUser()
1578 {
1579 if (Instance.currentActiveLogin == null)
1580 return false;
1581
1582 return Instance._GenerateOneTimeLoginForUser();
1583 }
1584
1586 {
1587 if (currentActiveLogin == null)
1588 {
1589 Debug.LogError("[ApexSystem] No current user logged in.");
1590 return false;
1591 }
1592
1594 }
1595
1598 if (currentActiveLogin == null)
1599 {
1600 Debug.LogError("[ApexSystem] No user logged in to generate code.");
1601 return false;
1602 }
1603
1605 return true;
1606 }
1607 }
1608}
async void SendHeartbeat(string authToken, int sessionId)
async void GetUserModules(string authToken, int userId)
async void QuickIDLogin(QuickIDLoginData login)
async void JoinSession(string authToken, JoinSessionData joinData)
async void LoginWithToken(string token)
async void CompleteSession(string authToken, CompleteSessionData completionData)
async void Login(LoginData login)
async void SendSessionEvent(string authToken, SessionEventData sessionEvent)
void SetPlatformEndpoint(string endpointUrl)
async void GetQuickIDAuthenticationUsers(string serialNumber)
async void GetUserData(string authToken, int userId)
void SetWebEndpoint(string endpointUrl)
async void GetModuleAccess(int moduleId, int userId, string serialNumber)
async void GenerateAssistedLogin(string authToken)
async void GetModuleList(string authToken, string platform)
const string PIXOVR_SESSION_COMPLETE
const string PIXOVR_SESSION_EVENT
const string PIXOVR_SESSION_JOINED
static readonly string MODULE_ID
ApexWebsocket webSocket
OnHttpResponseEvent OnPingSuccess
Extensions AppendStandardContextExtension(Extensions currentContextExtensions)
OnGeneratedAssistedLoginSuccessEvent OnGeneratedAssistedLoginSuccess
bool runSetupOnAwake
[SerializeField]
static string PassedLoginToken
Definition ApexSystem.cs:87
static bool LoginCheckModuleAccess
Definition ApexSystem.cs:75
static bool QuickIDLogin(string serialNumber, string username)
static bool GetCurrentUser()
static bool RunSetupOnAwake
Definition ApexSystem.cs:69
FailureResponse GenerateFailureResponse(string message)
OnApexFailureEvent OnJoinSessionFailed
string GetPlatformEndpointFromPlatformTarget(PlatformServer target)
void _ChangePlatformServer(PlatformServer newServer)
int moduleID
[SerializeField]
static bool Login(string username, string password)
OnApexFailureEvent OnGeneratedAssistedLoginFailed
static string ModuleName
Definition ApexSystem.cs:45
OnHttpResponseEvent OnPingFailed
static bool SendSessionEvent(Statement eventStatement)
OnGetQuickIDAuthUsersSuccessEvent OnGetQuickIDAuthGetUsersSuccess
string GetWebEndpointFromPlatformTarget(PlatformServer target)
void OnAPIResponse(ResponseType response, HttpResponseMessage message, object responseData)
OnHttpResponseEvent OnJoinSessionSuccess
static void ReturnToHub()
OnApexFailureEvent OnGetUserFailed
OnAuthCodeReceived OnAuthorizationCodeReceived
OnGetOrgModulesSuccessEvent OnGetOrganizationModulesSuccess
bool _JoinSession(string newScenarioID=null, Extension contextExtension=null)
bool _Login(LoginData login)
static bool RequestAuthorizationCode()
bool _CompleteSession(SessionData currentSessionData, Extension contextExtension, Extension resultExtension)
void SetupPlatformConfiguration()
PlatformResponse OnPlatformResponse
static bool GetUser(int userId=-1)
OnHttpResponseEvent OnCompleteSessionSuccess
static bool GetQuickIDAuthUsers(string serialNumber)
string moduleVersion
[SerializeField]
string GetEndpointFromTarget(PlatformServer target)
bool _SendSimpleSessionEvent(string verbName, string targetObject, Extension contextExtension)
OnApexFailureEvent OnCompleteSessionFailed
OnLoginSuccessEvent OnLoginSuccess
void OnWebSocketConnectFailed(string reason)
static bool CheckModuleAccess(int targetModuleID=-1)
OnApexFailureEvent OnSendEventFailed
OnQuickIDAuthLoginSuccessEvent OnQuickIDAuthLoginSuccess
void OnWebSocketReceive(string data)
void HandleLogin(bool successful, object responseData)
static bool GetUserModules(int userId=-1)
static LoginResponseContent CurrentActiveLogin
Definition ApexSystem.cs:63
bool _GetQuickIDAuthUsers(string serialNumber)
static bool SendSimpleSessionEvent(string action, string targetObject, Extension contextExtension)
static string ReturnTarget
Definition ApexSystem.cs:99
static string ServerIP
Definition ApexSystem.cs:33
static string TargetType
float DetermineScaledScore(float scaledScore, float score, float maxScore)
APIHandler apexAPIHandler
static bool GetCurrentUserModules()
void _ExitApplication(string returnTarget)
static bool GetModulesList(string platformName)
Task< bool > socketConnectTask
OnApexFailureEvent OnGetQuickIDAuthGetUsersFailed
static void ChangePlatformServer(PlatformServer newServer)
static string ModuleVersion
Definition ApexSystem.cs:51
static bool LoginWithToken()
bool _Login(string username, string password)
static bool JoinSession(string scenarioID=null, Extension contextExtension=null)
bool loginCheckModuleAccess
[SerializeField]
bool _GenerateOneTimeLoginForCurrentUser()
OnApexFailureEvent OnGetUserModulesFailed
bool _SendSessionEvent(Statement eventStatement)
OnApexFailureEvent OnLoginFailed
static bool Login(LoginData login)
static string ScenarioID
Definition ApexSystem.cs:57
void _ParsePassedData(Dictionary< string, string > arguments)
static string DeviceSerialNumber
Definition ApexSystem.cs:81
LoginResponseContent currentActiveLogin
bool _LoginWithToken(string token)
static void ExitApplication(string returnTarget="")
static readonly Regex VersionValidator
OnApexFailureEvent OnGetOrganizationModulesFailed
float heartbeatTime
[SerializeField]
OnApexFailureEvent OnModuleAccessFailed
OnApexFailureEvent OnQuickIDAuthLoginFailed
static string OptionalData
Definition ApexSystem.cs:93
string scenarioID
[SerializeField]
OnModuleAccessSuccessEvent OnModuleAccessSuccess
bool _GetUser(int userId=-1)
OnGetUserSuccessEvent OnGetUserSuccess
OnHttpResponseEvent OnSendEventSuccess
bool _QuickIDLogin(string serialNumber, string username)
static bool GenerateOneTimeLoginForCurrentUser()
bool _CheckModuleAccess(int targetModuleID=-1)
bool _GenerateOneTimeLoginForUser()
static bool CompleteSession(SessionData currentSessionData, Extension contextExtension=null, Extension resultExtension=null)
bool IsModuleVersionOnlyNumerical()
string serverIP
[SerializeField]
void OnWebSocketClosed(System.Net.WebSockets.WebSocketCloseStatus reason)
bool _GetModuleList(string platformName)
static bool LoginWithToken(string token)
PlatformServer PlatformTargetServer
OnGetUserModulesSuccessEvent OnGetUserModulesSuccess
Extensions AppendStandardContextExtension(Extension currentContextExtension)
string moduleName
[SerializeField]
bool IsModuleNonMajorVersionPartValid(string modulePart)
bool _GetUserModules(int userId=-1)
bool IsModuleMajorVersionPartValid(string modulePart)
void OnDeepLinkActivated(string url)
static readonly Uri JOINED_SESSION
static readonly Uri COMPLETED_SESSION
async Task< bool > Connect(Uri endpoint, int attemptTries=3)
OnWebSocketReceive OnReceive
OnWebSocketConnectFailed OnConnectFailed
OnWebSocketClosed OnClosed
OnWebSocketConnectSuccessful OnConnectSuccess
[Serializable]
Definition ApexTypes.cs:163
static bool DoesFileExistInSharedLocation(string fileName)
static string ReadFileFromSharedStorage(string fileName)
static bool OpenApplication(string applicationPath, string[] argumentKeys, string[] argumentValues)
static Dictionary< string, string > ParseURLArguments(string url)
static Dictionary< string, string > ParseApplicationArguments()
static string GetMacAddress()
Definition ApexUtils.cs:21
void Add(Uri key, string value)
void AddSimple(string key, string value)
override JObject ToJObject(TCAPIVersion version)
delegate void PlatformResponse(ResponseType type, bool wasSuccessful, object responseData)