diff --git a/.github/workflows/docs_update.yml b/.github/workflows/docs_update.yml new file mode 100644 index 00000000..622dc64e --- /dev/null +++ b/.github/workflows/docs_update.yml @@ -0,0 +1,41 @@ + + +name: MobiledgeX Unity Docs Update + +on: [release] + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Check out Docs branch + uses: actions/checkout@v2 + with: + ref: docs + + - name: Check out the SDK master branch (REST) + uses: actions/checkout@v2 + with: + ref: master + path: ./sdk + + - name: Update Docs + uses: mattnotmitt/doxygen-action@v1.9.2 + with: + doxyfile-path: './config/Doxyfile' + + - name: Clean before commit + run: | + sudo rm -rf ./sdk + sudo mv docs/html/* docs/ + sudo rm -rf docs/html + sudo cp ./config/tab_b.png ./docs/tab_b.png + shell: bash + + - name: Commit Doxygen Updates + uses: stefanzweifel/git-auto-commit-action@v4 + with: + commit_message: Docs Automated Updates + branch: docs + push_options: '--force' + skip_checkout: true diff --git a/.github/workflows/unit_tests.yml b/.github/workflows/unit_tests.yml index 6d92c049..f17de96b 100644 --- a/.github/workflows/unit_tests.yml +++ b/.github/workflows/unit_tests.yml @@ -33,7 +33,7 @@ jobs: run: | rm -rf ./project/EmptyProject/Assets/Tests/Editor rm ./project/EmptyProject/Assets/Tests/Editor.meta - + - name: Run Tests using Unity TestRunner uses: game-ci/unity-test-runner@v2 id: tests diff --git a/Editor/MobiledgeXEditorWindow.cs b/Editor/MobiledgeXEditorWindow.cs index cc67d5da..d65edbac 100644 --- a/Editor/MobiledgeXEditorWindow.cs +++ b/Editor/MobiledgeXEditorWindow.cs @@ -1,5 +1,5 @@ /** - * Copyright 2018-2021 MobiledgeX, Inc. All rights and licenses reserved. + * Copyright 2018-2022 MobiledgeX, Inc. All rights and licenses reserved. * MobiledgeX, Inc. 156 2nd Street #408, San Francisco, CA 94105 * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -224,8 +224,12 @@ void OnInspectorUpdate() string GetSDKVersion() { TextAsset asset = (TextAsset)AssetDatabase.LoadAssetAtPath("Packages/com.mobiledgex.sdk/package.json", typeof(TextAsset)); - string sdkVersion = JsonUtility.FromJson(asset.text).version; - return "v" + sdkVersion; + if (asset != null) + { + string sdkVersion = JsonUtility.FromJson(asset.text).version; + return "v" + sdkVersion; + } + return "DEBUG_VER"; } /// @@ -441,7 +445,6 @@ void AddMobiledgeXPlugins() string iosPluginPath = Path.GetFullPath("Packages/com.mobiledgex.sdk/Runtime/Plugins/iOS/PlatformIntegration.m"); string linkXMLPath = Path.GetFullPath("Packages/com.mobiledgex.sdk/link.xml"); string settingPath = Path.GetFullPath("Packages/com.mobiledgex.sdk/Resources/MobiledgeXSettings.asset"); - string melAARPath = Path.GetFullPath("Packages/com.mobiledgex.sdk/Runtime/Plugins/Android/mel.aar"); try { if (!Directory.Exists(@unityPluginsFolderPath)) @@ -468,7 +471,6 @@ void AddMobiledgeXPlugins() { AssetDatabase.CreateFolder("Assets/Plugins/MobiledgeX", "Android"); } - MoveFile(melAARPath, Path.Combine(@mobiledgeXFolderPath, @"Android/mel.aar"), true); AssetDatabase.Refresh(); } catch (Exception e) diff --git a/Editor/TemplateGenerator.cs b/Editor/TemplateGenerator.cs new file mode 100644 index 00000000..6689a17a --- /dev/null +++ b/Editor/TemplateGenerator.cs @@ -0,0 +1,58 @@ +/** + * Copyright 2018-2022 MobiledgeX, Inc. All rights and licenses reserved. + * MobiledgeX, Inc. 156 2nd Street #408, San Francisco, CA 94105 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#if UNITY_EDITOR +using UnityEngine; +using UnityEditor; +using System.IO; + +namespace MobiledgeX +{ + public class TemplateGenerator : MonoBehaviour + { + [MenuItem("MobiledgeX/Create/GetUrlScript", false, 1)] + static void CreateGetUrlScript() + { + string pathUnityPackage = Application.dataPath+"/Runtime/Scripts/ExampleRest.cs";//used if sdk is imported using unity package + string pathGitUrl = "Packages/com.mobiledgex.sdk/Runtime/Scripts/ExampleRest.cs";//used if sdk is imported using git url + if (!File.Exists(pathGitUrl)) + { + Debug.LogError("Source file not found, Please file an issue to https://github.com/mobiledgex/edge-cloud-sdk-unity/issues/new?body=Reported%20on%20Unity" + Application.unityVersion); + return; + } + string[] lines = File.ReadAllLines(pathGitUrl); + lines[29] = "public class GetUrl : MonoBehaviour"; + string fileLocation = Application.dataPath + "/GetUrl.cs"; + if (File.Exists(fileLocation)) + { + Debug.LogError($"{fileLocation} already exists"); + return; + } + using (StreamWriter outfile = new StreamWriter(fileLocation)) + { + int counter = 0; + while (counter < lines.Length) + { + outfile.WriteLine(lines[counter]); + counter++; + } + } + AssetDatabase.Refresh(); + } + } +} +#endif diff --git a/Runtime/Scripts/MelMessaging.cs.meta b/Editor/TemplateGenerator.cs.meta similarity index 83% rename from Runtime/Scripts/MelMessaging.cs.meta rename to Editor/TemplateGenerator.cs.meta index 17f1d925..9ed43cbc 100644 --- a/Runtime/Scripts/MelMessaging.cs.meta +++ b/Editor/TemplateGenerator.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: a7340f008066f436c80eb93ec935e0f8 +guid: 8257801ad26e54c60bbd71256b8647e2 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Plugins/Android.meta b/Runtime/Plugins/Android.meta deleted file mode 100644 index 6afc8856..00000000 --- a/Runtime/Plugins/Android.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: b38684a80edc040678173b245ee173a2 -folderAsset: yes -DefaultImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Runtime/Plugins/Android/mel.aar b/Runtime/Plugins/Android/mel.aar deleted file mode 100644 index 7f8ca334..00000000 Binary files a/Runtime/Plugins/Android/mel.aar and /dev/null differ diff --git a/Runtime/Plugins/Android/mel.aar.meta b/Runtime/Plugins/Android/mel.aar.meta deleted file mode 100644 index dbfedb23..00000000 --- a/Runtime/Plugins/Android/mel.aar.meta +++ /dev/null @@ -1,32 +0,0 @@ -fileFormatVersion: 2 -guid: 4f54887943de744f686b235b33eea969 -PluginImporter: - externalObjects: {} - serializedVersion: 2 - iconMap: {} - executionOrder: {} - defineConstraints: [] - isPreloaded: 0 - isOverridable: 1 - isExplicitlyReferenced: 0 - validateReferences: 1 - platformData: - - first: - Android: Android - second: - enabled: 1 - settings: {} - - first: - Any: - second: - enabled: 0 - settings: {} - - first: - Editor: Editor - second: - enabled: 0 - settings: - DefaultValueInitialized: true - userData: - assetBundleName: - assetBundleVariant: diff --git a/Runtime/Plugins/MatchingEngineSDKRestLibrary.dll b/Runtime/Plugins/MatchingEngineSDKRestLibrary.dll index 4ce3a3b4..c8dc5b95 100644 Binary files a/Runtime/Plugins/MatchingEngineSDKRestLibrary.dll and b/Runtime/Plugins/MatchingEngineSDKRestLibrary.dll differ diff --git a/Runtime/Scripts/CarrierInfoIntegration.cs b/Runtime/Scripts/CarrierInfoIntegration.cs index 814cfbb2..c7100ea7 100644 --- a/Runtime/Scripts/CarrierInfoIntegration.cs +++ b/Runtime/Scripts/CarrierInfoIntegration.cs @@ -1,5 +1,5 @@ /** - * Copyright 2019-2021 MobiledgeX, Inc. All rights and licenses reserved. + * Copyright 2019-2022 MobiledgeX, Inc. All rights and licenses reserved. * MobiledgeX, Inc. 156 2nd Street #408, San Francisco, CA 94105 * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -25,6 +25,9 @@ namespace MobiledgeX { + /// + /// CarrierInfoException is thrown if there is an error in Roaming Detection. + /// public class CarrierInfoException : Exception { public CarrierInfoException(string message) @@ -37,7 +40,9 @@ public CarrierInfoException(string message, Exception innerException) { } } - + /// + /// CarrierInfoClass is responsible for collecting data about the device and the telecom carrier. + /// public class CarrierInfoClass : CarrierInfo { #pragma warning disable 0649 @@ -125,6 +130,10 @@ public CarrierInfoClass() }*/ } + /// + /// Gets the Android SDK Version (android.os.Build$VERSION) + /// + /// Android SDK Version (integer) public int getAndroidSDKVers() { AndroidJavaClass version = PlatformIntegrationUtil.GetAndroidJavaClass("android.os.Build$VERSION"); @@ -136,6 +145,11 @@ public int getAndroidSDKVers() return PlatformIntegrationUtil.GetStatic(version, "SDK_INT"); } + /// + /// Obtains the TelephonyManager object from the device(Android Only). + /// https://developer.android.com/reference/android/telephony/TelephonyManager + /// + /// Telephony Manager(AndroidJavaObject) public AndroidJavaObject GetTelephonyManager() { AndroidJavaClass unityPlayer = PlatformIntegrationUtil.GetAndroidJavaClass("com.unity3d.player.UnityPlayer"); @@ -195,6 +209,11 @@ public AndroidJavaObject GetTelephonyManager() return telManager; } + /// + /// Gets the current carrier name from the device + /// (Android) Requires TelephonyManager + /// + /// Network Operator Name (string) public string GetCurrentCarrierName() { string networkOperatorName = ""; @@ -222,6 +241,11 @@ public string GetCurrentCarrierName() return networkOperatorName; } + /// + /// MCC-MNC (Mobile Country Code- Mobile Network Code) + /// Gets the MCC-MNC code from the device, used for selecting the regional DME + /// + /// MCC-MNC code (string) public string GetMccMnc() { string mccmnc = null; @@ -252,7 +276,7 @@ public string GetMccMnc() return mccmnc; } - KeyValuePair GetCidKeyValuePair(AndroidJavaObject cellInfo) + private KeyValuePair GetCidKeyValuePair(AndroidJavaObject cellInfo) { KeyValuePair pair = new KeyValuePair(null, 0); @@ -321,6 +345,12 @@ KeyValuePair GetCidKeyValuePair(AndroidJavaObject cellInfo) } + /// + /// Obtains a list of Cellular Info from the device. + /// (Android)Requires Access to TelephonyManager and permission to access the user fine location. + /// https://developer.android.com/reference/android/telephony/CellInfo + /// + /// List of KeyValue Pairs public List> GetCellInfoList() { if (Application.platform != RuntimePlatform.Android) @@ -378,6 +408,10 @@ public List> GetCellInfoList() return cellIDList; } + /// + /// Obtains CellIdentity from the device + /// + /// CellIdentity (unsinged long) public ulong GetCellID() { /* @@ -399,6 +433,11 @@ public ulong GetCellID() return 0; } + /// + /// Obtains the NetworkDataType (GPRS, LTE ... ) + /// (Android)Requires READ_PHONE_STATE permission + /// + /// NetworkDataType (string) public string GetDataNetworkPath() { AndroidJavaObject telManager = GetTelephonyManager(); @@ -427,6 +466,11 @@ public string GetDataNetworkPath() } } + /// + /// Obtains the Signal Strength of the network + /// (Android) Requires TelephonyManager + /// + /// Signal Strength (unsigned long) public ulong GetSignalStrength() { AndroidJavaObject telManager = GetTelephonyManager(); @@ -467,6 +511,10 @@ public ulong GetSignalStrength() [DllImport("__Internal")] private static extern string _getISOCountryCodeFromCarrier(); + /// + /// Gets the current carrier name from the device + /// + /// Network Operator Name (string) public string GetCurrentCarrierName() { string networkOperatorName = ""; @@ -477,6 +525,11 @@ public string GetCurrentCarrierName() return networkOperatorName; } + /// + /// MCC-MNC (Mobile Country Code- Mobile Network Code) + /// Gets the MCC-MNC code from the device used for selecting the regional DME + /// + /// MCC-MNC code (string) public string GetMccMnc() { string mccmnc = null; @@ -487,6 +540,10 @@ public string GetMccMnc() return mccmnc; } + /// + /// Obtains CellIdentity from the device + /// + /// CellIdentity (unsinged long) public ulong GetCellID() { int cellID = 0; @@ -497,16 +554,33 @@ public ulong GetCellID() return (ulong)cellID; } + /// + /// Obtains the NetworkDataType (GPRS, LTE ... ) + /// Requires READ_PHONE_STATE permission on Android Phones + /// + /// NetworkDataType (string) public string GetDataNetworkPath() { return ""; } + /// + /// Obtains the Signal Strength of the network + /// + /// Signal Strength (unsigned long) public ulong GetSignalStrength() { return 0; } + /// + /// Returns wether the device is on the normal provider network or another network. + /// This method compares between the ISO Country code obtained from the DeviceLocation and from the DeviceCarrier + /// (Asynchronous method) (iOS only) + /// + /// (double) + /// (double) + /// boolean value public async Task IsRoaming(double longitude, double latitude) { if (Application.platform == RuntimePlatform.IPhonePlayer) @@ -544,6 +618,13 @@ public async Task IsRoaming(double longitude, double latitude) return false; } + /// + /// Convert GPS (longitude, latitude) to ISOCountryCode + /// (Asynchronous method)(iOS only) + /// + /// (double) + /// (double) + /// ISOCountryCode (string) public async Task ConvertGPSToISOCountryCode(double longitude, double latitude) { if (Application.platform == RuntimePlatform.IPhonePlayer) @@ -563,6 +644,11 @@ public async Task ConvertGPSToISOCountryCode(double longitude, double la return null; } + /// + /// Gets the ISO Country Code from the device location. + /// (iOS only) + /// + /// ISO Country Code (string) public string GetISOCountryCodeFromGPS() { string isoCC = null; @@ -573,6 +659,11 @@ public string GetISOCountryCodeFromGPS() return isoCC; } + /// + /// Gets the ISO Country Code from the device carrier. + /// (iOS only) + /// + /// ISO Country Code (string) public string GetISOCountryCodeFromCarrier() { string isoCC = null; @@ -585,31 +676,52 @@ public string GetISOCountryCodeFromCarrier() #else - // Implement CarrierInfo + /// + /// Gets the current carrier name from the device + /// + /// Network Operator Name (string) public string GetCurrentCarrierName() { Logger.Log("GetCurrentCarrierName is NOT IMPLEMENTED"); return null; } + /// + /// MCC-MNC (Mobile Country Code- Mobile Network Code) + /// Gets the MCC-MNC code from the device used for selecting the regional DME + /// + /// MCC-MNC code (string) public string GetMccMnc() { Logger.Log("GetMccMnc is NOT IMPLEMENTED"); return null; } + /// + /// Obtains CellIdentity from the device + /// + /// CellIdentity (unsinged long) public ulong GetCellID() { Logger.Log("GetCellID is NOT IMPLEMENTED"); return 0; } + /// + /// Obtains the NetworkDataType (GPRS, LTE ... ) + /// Requires READ_PHONE_STATE permission on Android Phones + /// + /// NetworkDataType (string) public string GetDataNetworkPath() { Logger.Log("GetDataNetworkPath is NOT IMPLEMENTED"); return ""; } + /// + /// Obtains the Signal Strength of the network + /// + /// Signal Strength (unsigned long) public ulong GetSignalStrength() { Logger.Log("GetSignalStrength is NOT IMPLEMENTED"); @@ -620,30 +732,53 @@ public ulong GetSignalStrength() } - // Used for testing in UnityEditor (any target platform) + /// + /// Used for testing in UnityEditor (any target platform) + /// public class TestCarrierInfoClass : CarrierInfo { - // Implement CarrierInfo + /// + /// Gets the current carrier name from the device + /// + /// Network Operator Name (string) public string GetCurrentCarrierName() { return ""; } + /// + /// MCC-MNC (Mobile Country Code- Mobile Network Code) + /// Gets the MCC-MNC code from the device used for selecting the regional DME + /// + /// MCC-MNC code (string) public string GetMccMnc() { return ""; } + /// + /// Obtains CellIdentity from the device + /// + /// CellIdentity (unsinged long) public ulong GetCellID() { return 0; } + /// + /// Obtains the NetworkDataType (GPRS, LTE ... ) + /// Requires READ_PHONE_STATE permission on Android Phones + /// + /// NetworkDataType (string) public string GetDataNetworkPath() { return ""; } + /// + /// Obtains the Signal Strength of the network + /// + /// Signal Strength (unsigned long) public ulong GetSignalStrength() { return 0; diff --git a/Runtime/Scripts/DeviceInfoIntegration.cs b/Runtime/Scripts/DeviceInfoIntegration.cs index c612ac0c..24f222f7 100644 --- a/Runtime/Scripts/DeviceInfoIntegration.cs +++ b/Runtime/Scripts/DeviceInfoIntegration.cs @@ -1,5 +1,5 @@ /* - * Copyright 2019-2021 MobiledgeX, Inc. All rights and licenses reserved. + * Copyright 2019-2022 MobiledgeX, Inc. All rights and licenses reserved. * MobiledgeX, Inc. 156 2nd Street #408, San Francisco, CA 94105 * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -21,9 +21,12 @@ namespace MobiledgeX { + /// + /// DeviceInfoIntegration is responsible for collecting Device low level information across different operating systems + /// public class DeviceInfoIntegration : DeviceInfo { - CarrierInfo overrideCarrierInfo; + private CarrierInfo overrideCarrierInfo; public DeviceInfoIntegration(CarrierInfo overrideCarrierInfo = null) { @@ -34,6 +37,10 @@ public DeviceInfoIntegration() { } + /// + /// Retrieves the device information (DataNetworkPath, CarrierName, SignalStrength, DeviceOS, DeviceModel) + /// + /// Device Information Dictionary(string, string) public Dictionary GetDeviceInfo() { CarrierInfo carrierInfo = overrideCarrierInfo; @@ -51,16 +58,28 @@ public Dictionary GetDeviceInfo() return deviceInfo; } #if UNITY_IOS + /// + /// Returns wether the OS supports the network utility Ping (ICMP packets) + /// + /// boolean public bool IsPingSupported() { - return false; + return false; } #elif UNITY_ANDROID + /// + /// Returns wether the OS supports the network utility Ping (ICMP packets) + /// + /// boolean public bool IsPingSupported() { return true; } #else //unsupported platform + /// + /// Returns wether the OS supports the network utility Ping (ICMP packets) + /// + /// boolean public bool IsPingSupported() { return true; @@ -69,15 +88,25 @@ public bool IsPingSupported() } - // Used for DeviceInfo in UnityEditor (any target platform) + /// + /// Used for DeviceInfo in UnityEditor (any target platform) + /// public class TestDeviceInfo : DeviceInfo { + /// + /// Retrieves the device information (DataNetworkPath, CarrierName, SignalStrength, DeviceOS, DeviceModel) + /// + /// Device Information Dictionary(string, string) public Dictionary GetDeviceInfo() { Logger.Log("DeviceInfo not implemented!"); return null; } + /// + /// Returns wether the OS supports the network utility Ping (ICMP packets) + /// + /// boolean public bool IsPingSupported() { return true; diff --git a/Runtime/Scripts/ExampleNonCellular.cs b/Runtime/Scripts/ExampleNonCellular.cs index 4c56ec7b..00d5befb 100644 --- a/Runtime/Scripts/ExampleNonCellular.cs +++ b/Runtime/Scripts/ExampleNonCellular.cs @@ -46,7 +46,7 @@ async void Start() Debug.Log("FindCloudletException: " + fce.Message + "Inner Exception: " + fce.InnerException); // your fallback logic here } - mxi.GetAppPort(LProto.L_PROTO_TCP); // or LProto.L_PROTO_UDP + mxi.GetAppPort(LProto.Tcp); // or LProto.L_PROTO_UDP string url = mxi.GetUrl("http"); // or another L7 proto such as https, ws, wss, udp Debug.Log("url : " + url); // Once you have your edge server url you can start communicating with your Edge server diff --git a/Runtime/Scripts/ExampleQoS.cs b/Runtime/Scripts/ExampleQoS.cs new file mode 100644 index 00000000..7471e75f --- /dev/null +++ b/Runtime/Scripts/ExampleQoS.cs @@ -0,0 +1,84 @@ +/** + * Copyright 2018-2022 MobiledgeX, Inc. All rights and licenses reserved. + * MobiledgeX, Inc. 156 2nd Street #408, San Francisco, CA 94105 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +using System.Collections; +using UnityEngine; +using MobiledgeX; +using DistributedMatchEngine; +using System.Threading.Tasks; + +[RequireComponent(typeof(MobiledgeX.LocationService))] +public class ExampleQoS : MonoBehaviour +{ + MobiledgeXIntegration mxi; + + IEnumerator Start() + { + yield return StartCoroutine(MobiledgeX.LocationService.EnsureLocation()); + GetEdgeConnection(); + + } + + async void GetEdgeConnection() + { + mxi = new MobiledgeXIntegration(); + try + { + await mxi.RegisterAndFindCloudlet(); + } + catch (RegisterClientException rce) + { + Debug.Log("RegisterClientException: " + rce.Message + "Inner Exception: " + rce.InnerException); + mxi.UseWifiOnly(true); + await mxi.RegisterAndFindCloudlet(); + } + catch (FindCloudletException fce) + { + Debug.Log("FindCloudletException: " + fce.Message + "Inner Exception: " + fce.InnerException); + } + mxi.GetAppPort(LProto.Tcp); + string url = mxi.GetUrl("http"); + Debug.Log("url : " + url); + + + //Creates QoS Session + await CreateQoSSession(); + } + + private async Task CreateQoSSession() + { + QosPrioritySessionCreateRequest qoSRequest = mxi.matchingEngine.CreateQosPriorityCreateRequest(QosSessionProfile.LowLatency, mxi.FindCloudletReply, "5000", "3000"); + QosPrioritySessionCreateReply qoSReply = await mxi.matchingEngine.CreateQOSPrioritySession(qoSRequest); + Debug.Log(qoSReply.ToString()); + if (qoSReply.http_status == 200 || qoSReply.http_status == 201) return true; + else return false; + } + + private async Task DeleteQoSSession() + { + QosPrioritySessionDeleteRequest deleteRequest = mxi.matchingEngine.CreateQosPriorityDeleteRequest(QosSessionProfile.LowLatency); + QosPrioritySessionDeleteReply deleteReply = await mxi.matchingEngine.DeleteQOSPrioritySession(deleteRequest); + Debug.Log(deleteReply.ToString()); + if (deleteReply.status == DeleteStatus.Deleted) return true; + else return false; + } + + void OnDestroy() + { + mxi.Dispose(); + } +} diff --git a/Runtime/Scripts/ExampleQoS.cs.meta b/Runtime/Scripts/ExampleQoS.cs.meta new file mode 100644 index 00000000..7858ce0c --- /dev/null +++ b/Runtime/Scripts/ExampleQoS.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 7df6ceeb555644f9b9f63290c220cf14 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {fileID: 2800000, guid: c1c309e3f8e5e4e48becefb11abf31d5, type: 3} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Scripts/ExampleRest.cs b/Runtime/Scripts/ExampleRest.cs index 78a8f5d9..7fcd41a4 100644 --- a/Runtime/Scripts/ExampleRest.cs +++ b/Runtime/Scripts/ExampleRest.cs @@ -65,7 +65,7 @@ async void GetEdgeConnection() mxi.SetFallbackLocation(-122.4194, 37.7749); //Example only (SF location),In Production you can optionally use: MobiledgeXIntegration.LocationFromIPAddress location = await MobiledgeXIntegration.GetLocationFromIP(); await mxi.RegisterAndFindCloudlet(); } - mxi.GetAppPort(LProto.L_PROTO_TCP); // or LProto.L_PROTO_UDP + mxi.GetAppPort(LProto.Tcp); // or LProto.L_PROTO_UDP string url = mxi.GetUrl("http"); // or another L7 proto such as https, ws, wss, udp Debug.Log("url : " + url); // Once you have your edge server url you can start communicating with your Edge server deployed on MobiledgeX Console diff --git a/Runtime/Scripts/ExampleUDP.cs b/Runtime/Scripts/ExampleUDP.cs index 32a6b61c..b6d8ca3f 100644 --- a/Runtime/Scripts/ExampleUDP.cs +++ b/Runtime/Scripts/ExampleUDP.cs @@ -22,7 +22,7 @@ async void GetEdgeConnection() { mxi = new MobiledgeXIntegration(); await mxi.RegisterAndFindCloudlet(); - udpSendPort = mxi.GetAppPort(LProto.L_PROTO_UDP).public_port; + udpSendPort = mxi.GetAppPort(LProto.Udp).public_port; udpHost = mxi.GetHost(); Debug.Log("UDP HOST : " + udpHost); Debug.Log("UDP PORT : " + udpSendPort); diff --git a/Runtime/Scripts/ExampleWebSocket.cs b/Runtime/Scripts/ExampleWebSocket.cs index f8d67d0c..367b0351 100644 --- a/Runtime/Scripts/ExampleWebSocket.cs +++ b/Runtime/Scripts/ExampleWebSocket.cs @@ -33,7 +33,7 @@ async void GetEdgeConnection() await mxi.RegisterAndFindCloudlet(); } - mxi.GetAppPort(LProto.L_PROTO_TCP); + mxi.GetAppPort(LProto.Tcp); string url = mxi.GetUrl("ws"); Debug.Log("WebSocket URL is : " + url); await StartWebSocket(url); diff --git a/Runtime/Scripts/Logger.cs b/Runtime/Scripts/Logger.cs index 989dee40..b3508fa1 100644 --- a/Runtime/Scripts/Logger.cs +++ b/Runtime/Scripts/Logger.cs @@ -1,5 +1,5 @@ /** - * Copyright 2018-2021 MobiledgeX, Inc. All rights and licenses reserved. + * Copyright 2018-2022 MobiledgeX, Inc. All rights and licenses reserved. * MobiledgeX, Inc. 156 2nd Street #408, San Francisco, CA 94105 * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,10 +19,17 @@ namespace MobiledgeX { + /// + /// Internal class for MobiledgeX SDK logs + /// public class Logger { + /// + /// Defines the log level for the SDK, Its advised to set the log level to ErrorsOnly in a production environment. + /// public enum LogType { All, ErrorsAndWarnings, ErrorsOnly }; - public static void LogWarning(string message) + + internal static void LogWarning(string message) { if (MobiledgeXIntegration.settings.logType == LogType.All || MobiledgeXIntegration.settings.logType == LogType.ErrorsAndWarnings) { @@ -30,7 +37,7 @@ public static void LogWarning(string message) } } - public static void Log(string message) + internal static void Log(string message) { if (MobiledgeXIntegration.settings.logType == LogType.All) { diff --git a/Runtime/Scripts/MelMessaging.cs b/Runtime/Scripts/MelMessaging.cs deleted file mode 100644 index 591a2d78..00000000 --- a/Runtime/Scripts/MelMessaging.cs +++ /dev/null @@ -1,128 +0,0 @@ -/** - * Copyright 2018-2021 MobiledgeX, Inc. All rights and licenses reserved. - * MobiledgeX, Inc. 156 2nd Street #408, San Francisco, CA 94105 - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -using System; -using UnityEngine; -using MobiledgeX; -using DistributedMatchEngine.Mel; - -public class MelMessaging : MelMessagingInterface -{ - -#if UNITY_ANDROID - AndroidJavaObject getActivity() - { - AndroidJavaClass unityPlayer = PlatformIntegrationUtil.GetAndroidJavaClass("com.unity3d.player.UnityPlayer"); - if (unityPlayer == null) - { - return null; - } - AndroidJavaObject activity = PlatformIntegrationUtil.GetStatic(unityPlayer, "currentActivity"); - if (activity == null) - { - return null; - } - return activity; - } - - AndroidJavaClass getMel() - { - AndroidJavaClass MelCls = PlatformIntegrationUtil.GetAndroidJavaClass("com.mobiledgex.mel.MelMessaging"); - return MelCls; - } - - public MelMessaging(string appName) - { - // MobiledgeX Vender Interface. Only for Android. - AndroidJavaClass MelCls = getMel(); - - // Fire off intents to update MEL state. - var activity = getActivity(); - if (activity == null) - { - return; - } - MelCls.CallStatic("sendForMelStatus", activity, appName); - } - - public bool IsMelEnabled() - { - AndroidJavaClass MelCls = getMel(); - if (MelCls == null) - { - return false; - } - bool enabled = PlatformIntegrationUtil.CallStatic(MelCls, "isMelEnabled"); - return enabled; - } - - public string GetMelVersion() - { - AndroidJavaClass MelCls = getMel(); - if (MelCls == null) - { - return ""; - } - return PlatformIntegrationUtil.CallStatic(MelCls, "getMelVersion"); - } - - public string GetUid() - { - AndroidJavaClass MelCls = getMel(); - if (MelCls == null) - { - return ""; - } - string uid = PlatformIntegrationUtil.CallStatic(MelCls, "getUid"); - return uid; - } - - public string SetToken(string token, string app_name) - { - AndroidJavaClass MelCls = getMel(); - if (MelCls == null) - { - return ""; - } - object[] pa = new object[3] { getActivity(), token, app_name }; - string sent_token = PlatformIntegrationUtil.CallStatic(MelCls, "sendSetToken", pa); - return sent_token; - } - - // MelMessaging related: - public string GetManufacturer() - { - AndroidJavaClass BuildCls = PlatformIntegrationUtil.GetAndroidJavaClass("android.os.Build"); - string manufacturer = PlatformIntegrationUtil.GetStatic(BuildCls, "MANUFACTURER"); - return manufacturer; - } -#elif UNITY_IOS - public MelMessaging(string app_name) { } - public bool IsMelEnabled() { return false; } - public string GetMelVersion() { return ""; } - public string SetToken(string token, string app_name) { return ""; } - public string GetUid() { return ""; } - public string GetManufacturer() { return "Apple"; } -#else - public MelMessaging(string app_name) { } - public bool IsMelEnabled() { return false; } - public string GetMelVersion() { return ""; } - public string SetToken(string token, string app_name) { return ""; } - public string GetUid() { return ""; } - public string GetManufacturer() { return ""; } -#endif -} diff --git a/Runtime/Scripts/MobiledgeXIntegration.cs b/Runtime/Scripts/MobiledgeXIntegration.cs index 1581df34..10639e74 100644 --- a/Runtime/Scripts/MobiledgeXIntegration.cs +++ b/Runtime/Scripts/MobiledgeXIntegration.cs @@ -1,5 +1,5 @@ /** -* Copyright 2018-2021 MobiledgeX, Inc. All rights and licenses reserved. +* Copyright 2018-2022 MobiledgeX, Inc. All rights and licenses reserved. * MobiledgeX, Inc. 156 2nd Street #408, San Francisco, CA 94105 * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -34,55 +34,94 @@ namespace MobiledgeX { public partial class MobiledgeXIntegration : IDisposable { - public static string sdkVersion { get; set; } + internal static string sdkVersion { get; set; } /// /// Scriptable Object Holding MobiledgeX Settings (OrgName, AppName, AppVers) /// public static MobiledgeXSettings settings = Resources.Load("MobiledgeXSettings"); + private PlatformIntegration pIntegration; + /// - /// MatchingEngine objects + /// MobiledgeX MatchingEngine, this is MobiledgeX C# SDK + /// Please refer to the documentation here + /// https://api.mobiledgex.net/swagger/mexdemo/edge-cloud-sdk-csharp/html/index.html /// - PlatformIntegration pIntegration; public MatchingEngine matchingEngine; - /// - /// MatchingEngine API parameters + /// carrierName depends on the available subscriber SIM card and roaming carriers, and must be supplied by platform API. + /// + public string carrierName { get; set; } = ""; + /// + /// Organization name + /// + public string orgName { get; set; } = ""; + /// + /// Your MobiledgeX console appName + /// + public string appName { get; set; } = ""; + /// + /// Your app version uploaded to MobiledgeX docker registry. + /// + public string appVers { get; set; } = ""; + /// + /// An opaque string value supplied by the developer. + /// + public string developerAuthToken { get; set; } = ""; + /// + /// Cellular Identity /// - public string carrierName { get; set; } = ""; // carrierName depends on the available subscriber SIM card and roaming carriers, and must be supplied by platform API. - public string orgName { get; set; } = ""; // Organization name - public string appName { get; set; } = ""; // Your appName, if you have created this in the MobiledgeX console. - public string appVers { get; set; } = ""; // Your app version uploaded to the docker registry. - public string developerAuthToken { get; set; } = ""; // This is an opaque string value supplied by the developer. public uint cellID { get; set; } = 0; + /// + /// The UniqueIdentifier type + /// public string uniqueIDType { get; set; } = ""; + /// + /// The UniqueIdentifier for the device + /// public string uniqueID { get; set; } = ""; + /// + /// The Device Location + /// public Loc location { get; set; } = new Loc(); - /// - /// Public MatchingEngine Reply/ State properties + /// Whether the most recent registerClient call was successful + /// + public bool RegisterStatus { get { return latestRegisterStatus; } } + /// + /// Stored to be used in GetUrl, GetHost, GetPort, Get[]Connection + /// + public FindCloudletReply FindCloudletReply { get { return latestFindCloudletReply; } } + /// + /// Whether the most recent verifyLocation call was successful + /// + public bool VerifyLocationStatus { get { return latestVerifyLocationStatus; } } + /// + /// FindCloudlet mode (Proximity Mode, Performance Mode) + /// + public FindCloudletMode Mode { get { return mode; } } + /// + /// Latest Application Port object /// - public bool RegisterStatus { get { return latestRegisterStatus; } } // Whether the most recent registerClient call was successful - public FindCloudletReply FindCloudletReply { get { return latestFindCloudletReply; } } // Stored to be used in GetUrl, GetHost, GetPort, Get[]Connection - public bool VerifyLocationStatus { get { return latestVerifyLocationStatus; } } // Whether the most recent verifyLocation call was successful - public FindCloudletMode Mode { get { return mode; } } // FindCloudlet mode public AppPort AppPort { get { return latestAppPort; } } + /// + /// ApplicationPorts List + /// public AppPort[] AppPortList { get { return latestAppPortList; } } /// /// MatchingEngine Reply/ State variables (for internal use) /// - bool latestRegisterStatus = false; // Whether the most recent registerClient call was successful - FindCloudletReply latestFindCloudletReply = null; // Stored to be used in GetUrl, GetHost, GetPort, Get[]Connection - bool latestVerifyLocationStatus = false; // Whether the most recent verifyLocation call was successful - FindCloudletMode mode = FindCloudletMode.PROXIMITY; // FindCloudlet mode - AppPort latestAppPort = null; - AppPort[] latestAppPortList = null; - Location fallbackLocation = new Location(0, 0); - MelMessaging melMessaging; - - string region + private bool latestRegisterStatus = false; // Whether the most recent registerClient call was successful + private FindCloudletReply latestFindCloudletReply = null; // Stored to be used in GetUrl, GetHost, GetPort, Get[]Connection + private bool latestVerifyLocationStatus = false; // Whether the most recent verifyLocation call was successful + private FindCloudletMode mode = FindCloudletMode.PROXIMITY; // FindCloudlet mode + private AppPort latestAppPort = null; + private AppPort[] latestAppPortList = null; + private Location fallbackLocation = new Location(0, 0); + + private string region { get { @@ -121,11 +160,6 @@ public MobiledgeXIntegration(CarrierInfo carrierInfo = null, NetInterface netInt netInterface == null ? pIntegration.NetInterface : netInterface, uniqueId == null ? pIntegration.UniqueID : uniqueId, deviceInfo == null ? pIntegration.DeviceInfo : deviceInfo); - if (settings.MEL_ENABLED) - { - melMessaging = new MelMessaging(appName); - matchingEngine.SetMelMessaging(melMessaging); - } } /// @@ -142,11 +176,6 @@ public MobiledgeXIntegration(string orgName, string appName, string appVers, str pIntegration = new PlatformIntegration(); matchingEngine = new MatchingEngine(pIntegration.CarrierInfo, pIntegration.NetInterface, pIntegration.UniqueID, pIntegration.DeviceInfo); - if (settings.MEL_ENABLED) - { - melMessaging = new MelMessaging(appName); - matchingEngine.SetMelMessaging(melMessaging); - } } /// @@ -205,17 +234,17 @@ public async Task VerifyLocation(string dmeHost = null, uint dmePort = 0) // GPS and Tower Status: switch (reply.gps_location_status) { - case VerifyLocationReply.GPSLocationStatus.LOC_ROAMING_COUNTRY_MISMATCH: - case VerifyLocationReply.GPSLocationStatus.LOC_ERROR_UNAUTHORIZED: - case VerifyLocationReply.GPSLocationStatus.LOC_ERROR_OTHER: - case VerifyLocationReply.GPSLocationStatus.LOC_UNKNOWN: + case VerifyLocationReply.GPSLocationStatus.RoamingCountryMismatch: + case VerifyLocationReply.GPSLocationStatus.ErrorUnauthorized: + case VerifyLocationReply.GPSLocationStatus.ErrorOther: + case VerifyLocationReply.GPSLocationStatus.Unknown: return false; } switch (reply.tower_status) { - case VerifyLocationReply.TowerStatus.NOT_CONNECTED_TO_SPECIFIED_TOWER: - case VerifyLocationReply.TowerStatus.TOWER_UNKNOWN: + case VerifyLocationReply.TowerStatus.NotConnectedToSpecifiedTower: + case VerifyLocationReply.TowerStatus.TowerUnknown: return false; } @@ -253,10 +282,10 @@ public AppPort GetAppPort(LProto proto, int port = 0) switch (proto) { - case LProto.L_PROTO_TCP: + case LProto.Tcp: appPortsDict = matchingEngine.GetTCPAppPorts(latestFindCloudletReply); break; - case LProto.L_PROTO_UDP: + case LProto.Udp: appPortsDict = matchingEngine.GetUDPAppPorts(latestFindCloudletReply); break; default: diff --git a/Runtime/Scripts/MobiledgeXIntegrationConfig.cs b/Runtime/Scripts/MobiledgeXIntegrationConfig.cs index efd2cb89..7b38ecdb 100644 --- a/Runtime/Scripts/MobiledgeXIntegrationConfig.cs +++ b/Runtime/Scripts/MobiledgeXIntegrationConfig.cs @@ -1,5 +1,5 @@ /** -* Copyright 2018-2021 MobiledgeX, Inc. All rights and licenses reserved. +* Copyright 2018-2022 MobiledgeX, Inc. All rights and licenses reserved. * MobiledgeX, Inc. 156 2nd Street #408, San Francisco, CA 94105 * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -79,7 +79,12 @@ public void SetFallbackLocation(double longitude, double latitude) fallbackLocation.Longitude = longitude; fallbackLocation.Latitude = latitude; } - + /// + /// Gets the location from the IP Address + /// The location retrieved from this method is very arbitrary (ex. Country Location),this method becomes handy if the user rejects the precise location permissions. + /// The method uses FreeGeoIP API https://freegeoip.app/json/ , please refer to the FreeGeoIP API rate limiting for more details + /// + /// LocationFromIPAddress Task public static async Task GetLocationFromIP() { HttpClient httpClient = new HttpClient(); @@ -88,6 +93,10 @@ public static async Task GetLocationFromIP() HttpResponseMessage response = await httpClient.GetAsync("https://freegeoip.app/json/").ConfigureAwait(false); string responseBodyStr = response.Content.ReadAsStringAsync().Result; LocationFromIPAddress location = Messaging.Deserialize(responseBodyStr); + if (location.latitude == 0 && location.longitude == 0) + { + throw new Exception("Location API returned {0,0}, Overriding Location to (37.3382, 121.8863)"); + } return location; } catch (Exception) @@ -100,6 +109,9 @@ public static async Task GetLocationFromIP() } } + /// + /// Used for deserializing the FreeGeoIP API response, used in GetLocationFromIP() + /// [DataContract] public class LocationFromIPAddress { @@ -109,14 +121,28 @@ public class LocationFromIPAddress public float latitude; } + /// + /// Helper class used for deserializing JSON and Byte Streams + /// + /// DataType compatible with jsonString and Stream Objects public static class Messaging { + /// + /// Deserializes jsonString into a C# Object + /// + /// UTF8 jsonString + /// C# Object (T) public static T Deserialize(string jsonString) { MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(jsonString ?? "")); return Deserialize(ms); } + /// + /// Deserializes a Stream into a C# Object + /// + /// Stream Object + /// C# Object (T) public static T Deserialize(Stream stream) { DataContractJsonSerializer deserializer = new DataContractJsonSerializer(typeof(T)); diff --git a/Runtime/Scripts/MobiledgeXIntegrationHelper.cs b/Runtime/Scripts/MobiledgeXIntegrationHelper.cs index 91f6d41e..7424ebe0 100644 --- a/Runtime/Scripts/MobiledgeXIntegrationHelper.cs +++ b/Runtime/Scripts/MobiledgeXIntegrationHelper.cs @@ -1,5 +1,5 @@ /** -* Copyright 2018-2021 MobiledgeX, Inc. All rights and licenses reserved. +* Copyright 2018-2022 MobiledgeX, Inc. All rights and licenses reserved. * MobiledgeX, Inc. 156 2nd Street #408, San Francisco, CA 94105 * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -28,6 +28,10 @@ namespace MobiledgeX { + /// + /// AppPort Exception is thrown if the SDK is not able to detect the AppPort. + /// For example: EmptyFindCloudlet, Port not found or Protocol is not supported. + /// public class AppPortException : Exception { public AppPortException(string message) @@ -41,6 +45,9 @@ public AppPortException(string message, Exception innerException) } } + /// + /// Location Struct used in MobiledgeX SDK + /// public struct Location { public Location(double longitude, double latitude) @@ -139,7 +146,7 @@ public async Task Register(string dmeHost = null, uint dmePort = 0) Debug.LogError("MobiledgeX: Register reply NULL!"); throw new RegisterClientException("RegisterClient returned null."); } - if (reply.status != ReplyStatus.RS_SUCCESS) + if (reply.status != ReplyStatus.Success) { Debug.LogError("MobiledgeX: Register Failed: " + reply.status); throw new RegisterClientException("Bad RegisterClient. RegisterClient status is " + reply.status); @@ -226,7 +233,7 @@ public async Task FindCloudlet(string dmeHost = null, uint dmePort = 0) { throw new FindCloudletException("FindCloudletReply returned null. Make Sure you created App Instances for your Application and they are deployed in the correct region."); } - if (reply.status != FindCloudletReply.FindStatus.FIND_FOUND) + if (reply.status != FindCloudletReply.FindStatus.Found) { throw new FindCloudletException("Unable to findCloudlet. Status is " + reply.status); } @@ -235,7 +242,7 @@ public async Task FindCloudlet(string dmeHost = null, uint dmePort = 0) Logger.Log("FindCloudlet with DME result: " + reply.status); latestFindCloudletReply = reply; latestAppPortList = reply.ports; - return reply.status == FindCloudletReply.FindStatus.FIND_FOUND; + return reply.status == FindCloudletReply.FindStatus.Found; } /// diff --git a/Runtime/Scripts/MobiledgeXSettings.cs b/Runtime/Scripts/MobiledgeXSettings.cs index 21cc1e86..5ea49fbf 100644 --- a/Runtime/Scripts/MobiledgeXSettings.cs +++ b/Runtime/Scripts/MobiledgeXSettings.cs @@ -1,5 +1,5 @@ /** - * Copyright 2018-2021 MobiledgeX, Inc. All rights and licenses reserved. + * Copyright 2018-2022 MobiledgeX, Inc. All rights and licenses reserved. * MobiledgeX, Inc. 156 2nd Street #408, San Francisco, CA 94105 * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,17 +19,46 @@ namespace MobiledgeX { + /// + /// MobiledgeXSettings defines the settings of the connection to MobiledgeX platform + /// public class MobiledgeXSettings : ScriptableObject { + /// + /// MobiledgeX SDK Version + /// [HideInInspector] public string sdkVersion; + /// + /// (Required)Organization name + /// + [Tooltip("(Required)Organization name")] public string orgName; + /// + /// (Required)Application name + /// + [Tooltip("Required)Application Name")] public string appName; + /// + /// (Required)Application version must match the image version sumbitted to MobiledgeX docker registry. + /// + [Tooltip("(Required)Application version must match the image version sumbitted to MobiledgeX docker registry.")] public string appVers; + /// + /// (Optional)Public key (string value) supplied by the developer for authentication + /// + [Tooltip("(Optional)Public key (string value) supplied by the developer for authentication")] public string authPublicKey; + /// + /// The Regional DME, Select the region your app is deployed in. + /// Mapped regions are the following: {EU, US,JP, Nearest} + /// + [Tooltip("The Regional DME, Select the region your app is deployed in.\nMapped regions are the following: {EU, US,JP, Nearest}")] public string region; + /// + /// Defines the log level for the SDK, set the log level to ErrorsOnly in production. + /// + [Tooltip("Defines the log level for the SDK, set the log level to ErrorsOnly in production.")] public Logger.LogType logType = Logger.LogType.ErrorsAndWarnings; - [Tooltip("Set to true, If MEL mode is Enabled on your device.")] - public bool MEL_ENABLED; } } diff --git a/Runtime/Scripts/MobiledgeXWebSocketClient.cs b/Runtime/Scripts/MobiledgeXWebSocketClient.cs index 9d0bd0b0..cb33df25 100644 --- a/Runtime/Scripts/MobiledgeXWebSocketClient.cs +++ b/Runtime/Scripts/MobiledgeXWebSocketClient.cs @@ -241,7 +241,6 @@ public void Dispose() if (ws != null) { ws.Abort(); - ws.CloseAsync(WebSocketCloseStatus.NormalClosure, "Dispose", tokenSource.Token).ConfigureAwait(false).GetAwaiter().GetResult(); ws = null; } } diff --git a/Tests/Runtime/MobiledgeX_RuntimeTests.cs b/Tests/Runtime/MobiledgeX_RuntimeTests.cs index 44d58859..110a23b6 100644 --- a/Tests/Runtime/MobiledgeX_RuntimeTests.cs +++ b/Tests/Runtime/MobiledgeX_RuntimeTests.cs @@ -1,5 +1,5 @@ /** -* Copyright 2018-2021 MobiledgeX, Inc. All rights and licenses reserved. +* Copyright 2018-2022 MobiledgeX, Inc. All rights and licenses reserved. * MobiledgeX, Inc. 156 2nd Street #408, San Francisco, CA 94105 * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -29,23 +29,17 @@ namespace MobiledgeX public class MobiledgeX_RuntimeTests { MobiledgeXIntegration mxi; + string dmeHostOverride; + uint dmePortOverride; + #region Testing Setup [OneTimeSetUp] public void MobiledgeXEnvironmentSetup() { MobiledgeXIntegration.settings.region = "EU"; //For Testing Purposes, works in Editor only. - if (!UnityEditorInternal.InternalEditorUtility.isHumanControllingUs) - { - return; - } - if (!File.Exists(Path.Combine(Application.dataPath, "Plugins/MobiledgeX/iOS/PlatformIntegration.m")) && - !File.Exists(Path.Combine(Application.dataPath, "Plugins/MobiledgeX/link.xml")) && - !File.Exists(Path.Combine(Application.dataPath, "Plugins/MobiledgeX/MatchingEngineSDKRestLibrary.dll")) && - !File.Exists(Path.Combine(Application.dataPath, "Resources/MobiledgeXSettings.asset"))) - { - Assert.Fail("MobiledgeX Plugins are not loaded in the project, Can't perform tests"); - } + dmeHostOverride = "eu-stage.dme.mobiledgex.net"; + dmePortOverride = 38001; } #endregion @@ -53,7 +47,7 @@ public void MobiledgeXEnvironmentSetup() #region Run Time Tests [Test] - [TestCase("MobiledgeX-Samples", "sdktest", "9.0")] + [TestCase("Ahmed-Org", "sdk-test", "9.0")] public void RegisterClient(string orgName, string appName, string appVers) { using (MobiledgeXIntegration mxi = new MobiledgeXIntegration(new CarrierInfoClass(), null, new UniqueIDClass(), new TestDeviceInfo())) @@ -70,7 +64,7 @@ public void RegisterClient(string orgName, string appName, string appVers) } [Test] - [TestCase("MobiledgeX-Samples", "sdktest", "9.0")] + [TestCase("Ahmed-Org", "sdk-test", "9.0")] public void FindCloudlet(string orgName, string appName, string appVers) { using (MobiledgeXIntegration mxi = new MobiledgeXIntegration(new CarrierInfoClass(), null, new UniqueIDClass(), new TestDeviceInfo())) @@ -89,9 +83,9 @@ public void FindCloudlet(string orgName, string appName, string appVers) } [Test] - [TestCase("MobiledgeX-Samples", "sdktest", "9.0", "http", 8085)] - [TestCase("MobiledgeX-Samples", "sdktest", "9.0", "https", 2015)] - [TestCase("MobiledgeX-Samples", "sdktest", "9.0", "tcp", 2016)] + [TestCase("Ahmed-Org", "sdk-test", "9.0", "http", 8085)] + [TestCase("Ahmed-Org", "sdk-test", "9.0", "https", 2015)] + [TestCase("Ahmed-Org", "sdk-test", "9.0", "tcp", 2016)] public void GetUrl(string orgName, string appName, string appVers, string proto, int port) { using (MobiledgeXIntegration mxi = new MobiledgeXIntegration(new CarrierInfoClass(), null, new UniqueIDClass(), new TestDeviceInfo())) @@ -110,7 +104,11 @@ public void GetUrl(string orgName, string appName, string appVers, string proto, } [Test] - [TestCase("MobiledgeX-Samples", "sdktest", "9.0", "http", 8085)] + [TestCase("Ahmed-Org", "sdk-test", "9.0", "http", 8085)] + [TestCase("Ahmed-Org", "sdk-test", "9.0", "https", 2015)] + [TestCase("Ahmed-Org", "sdk-test", "9.0", "tcp", 2016)] + [TestCase("Ahmed-Org", "sdk-test", "9.0", "ws", 3765)] + [TestCase("Ahmed-Org", "sdk-test", "9.0", "udp", 2015)] public void GetHost(string orgName, string appName, string appVers, string proto, int port) { using (MobiledgeXIntegration mxi = new MobiledgeXIntegration(new CarrierInfoClass(), null, new UniqueIDClass(), new TestDeviceInfo())) @@ -161,7 +159,7 @@ public void RegisterClientFaliure(string orgName, string appName, string appVers } [Test] - [TestCase("MobiledgeX-Samples", "sdktest", "9.0", 104.1954, 35.8617)] + [TestCase("Ahmed-Org", "sdk-test", "9.0", 104.1954, 35.8617)] public void FindCloudletFaliure(string orgName, string appName, string appVers, double latitude, double longitude) { using (MobiledgeXIntegration mxi = new MobiledgeXIntegration(new CarrierInfoClass(), null, new UniqueIDClass(), new TestDeviceInfo())) @@ -197,7 +195,7 @@ public void FindCloudletFaliure(string orgName, string appName, string appVers, } [Test] - [TestCase("MobiledgeX-Samples", "sdktest", "9.0", "ws", 3765, 2000)] + [TestCase("Ahmed-Org", "sdk-test", "9.0", "ws", 3765, 2000)] public void WebSocketTest(string orgName, string appName, string appVers, string proto, int port, int timeOutMs) { using (MobiledgeXIntegration mxi = new MobiledgeXIntegration(new CarrierInfoClass(), null, new UniqueIDClass(), new TestDeviceInfo())) @@ -221,7 +219,7 @@ public void WebSocketTest(string orgName, string appName, string appVers, string [Test] - [TestCase("MobiledgeX-Samples", "sdktest", "9.0", 2000)] + [TestCase("Ahmed-Org", "sdk-test", "9.0", 2000)] public void UDPTest(string orgName, string appName, string appVers, int timeOutMs) { using (MobiledgeXIntegration mxi = new MobiledgeXIntegration(new CarrierInfoClass(), null, new UniqueIDClass(), new TestDeviceInfo())) @@ -232,7 +230,7 @@ public void UDPTest(string orgName, string appName, string appVers, int timeOutM var task = Task.Run(async () => { string hostName = await GetHostHelper(mxi, "udp"); - MobiledgeXUDPClient udpClient = new MobiledgeXUDPClient(hostName, mxi.GetAppPort(LProto.L_PROTO_UDP).public_port); + MobiledgeXUDPClient udpClient = new MobiledgeXUDPClient(hostName, mxi.GetAppPort(LProto.Udp).public_port); return UDPMessageHelper(udpClient, "ping", timeOutMs); }); Assert.True(task.Result == "pong"); @@ -245,14 +243,14 @@ public void UDPTest(string orgName, string appName, string appVers, int timeOutM public async Task RegisterHelper(MobiledgeXIntegration mxi) { - bool check = await mxi.Register(); + bool check = await mxi.Register(dmeHostOverride, dmePortOverride); await Task.Delay(TimeSpan.FromMilliseconds(1000)); return check; } public async Task FindCloudletHelper(MobiledgeXIntegration mxi) { - bool foundCloudlet = await mxi.FindCloudlet(); + bool foundCloudlet = await mxi.FindCloudlet(dmeHostOverride, dmePortOverride); await Task.Delay(TimeSpan.FromMilliseconds(1000)); return foundCloudlet; } @@ -278,14 +276,14 @@ public async Task GetUrlHelper(MobiledgeXIntegration mxi, string proto, switch (proto) { case "udp": - appPort = mxi.GetAppPort(LProto.L_PROTO_UDP, port); + appPort = mxi.GetAppPort(LProto.Udp, port); break; case "ws": case "wss": case "http": case "https": default: - appPort = mxi.GetAppPort(LProto.L_PROTO_TCP, port); + appPort = mxi.GetAppPort(LProto.Tcp, port); break; } @@ -318,14 +316,14 @@ public async Task GetHostHelper(MobiledgeXIntegration mxi, string proto, switch (proto) { case "udp": - appPort = mxi.GetAppPort(LProto.L_PROTO_UDP, port); + appPort = mxi.GetAppPort(LProto.Udp, port); break; case "ws": case "wss": case "http": case "https": default: - appPort = mxi.GetAppPort(LProto.L_PROTO_TCP, port); + appPort = mxi.GetAppPort(LProto.Tcp, port); break; } return mxi.GetHost(appPort);