Skip to content

Commit

Permalink
Update package management to unload old webrtc packages and install new
Browse files Browse the repository at this point in the history
  • Loading branch information
bnco-dev committed Nov 14, 2024
1 parent 86afa92 commit 724063e
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 17 deletions.
8 changes: 6 additions & 2 deletions Unity/Assets/Ubiq/Editor/Packages/AddPackageWebRTC.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,13 @@ static void Update()
" behaviour, add the string" +
" UBIQ_DISABLE_WEBRTCCOMPATIBILITYCHECK to your scripting define" +
" symbols.");
PackageManagerHelper.RemoveProvider("com.unity.webrtc");
PackageManagerHelper.RemovePackage("com.unity.webrtc");
#endif
PackageManagerHelper.AddPackage("https://github.com/UCL-VR/unity-webrtc-ubiq-fork.git");
// Remove previous versions
PackageManagerHelper.RemovePackage("com.unity.webrtc-no-vulkan-hook");
PackageManagerHelper.RemovePackage("com.unity.webrtc-ubiq-fork");

PackageManagerHelper.AddPackage("https://github.com/UCL-VR/unity-webrtc-ubiq-fork.git#v3.0.1-pre.7");
EditorApplication.update -= Update;
}
}
Expand Down
63 changes: 49 additions & 14 deletions Unity/Assets/Ubiq/Editor/Packages/PackageManagerHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,28 +106,45 @@ private static IEnumerator Process()

private static IEnumerator ProcessPackages()
{
var upmRequest = null as AddAndRemoveRequest;
if (packageRequests.Count > 0)
{
GetUnique(packageRequests, out var adds, out var removes);
LogPackageModificationMessage(adds,removes);

#if !UBIQ_DISABLE_PACKAGEIMPORT
upmRequest = Client.AddAndRemove(adds,removes);
#else
#if UBIQ_DISABLE_PACKAGEIMPORT
#if !UBIQ_SILENCEWARNING_DISABLEPACKAGEIMPORT
Debug.LogWarning("Ubiq will not modify packages as the" +
Debug.LogWarning("Ubiq will not modify packages as the" +
" scripting define symbol UBIQ_DISABLE_PACKAGEIMPORT is" +
" present. Please ensure you manage the required packages" +
" manually, or Ubiq may not function as intended. To" +
" silence this warning, add the string"
" UBIQ_SILENCEWARNING_DISABLEPACKAGEIMPORT to your scripting"
" define symbols.");
#endif
packageRequests.Clear();
yield break;
#endif
packageRequests.Clear();

if (packageRequests.Count == 0)
{
yield break;
}

GetUnique(packageRequests, out var adds, out var removes);
packageRequests.Clear();
LogPackageModificationMessage(adds,removes);

// First check if the packages for removal are present
var listRequest = Client.List(
offlineMode:true,includeIndirectDependencies:false);
while (listRequest != null)
{
if (listRequest.IsCompleted)
{
Filter(ref removes, listRequest.Result);
listRequest = null;
}

yield return null;
}

// Now do the actual add/remove
var upmRequest = Client.AddAndRemove(adds,removes);
while (upmRequest != null)
{
if (upmRequest.Status == StatusCode.Failure)
Expand All @@ -138,17 +155,17 @@ private static IEnumerator ProcessPackages()
Debug.LogError($"Ubiq was unable to modify project requirements. Error: {error}");
upmRequest = null;
}

if (upmRequest.Status == StatusCode.Success)
else if (upmRequest.Status == StatusCode.Success)
{
var collection = (PackageCollection)upmRequest.Result;
Debug.Log("Ubiq successfully modified project requirements.");
upmRequest = null;
assetsDirty = true;
}

yield return null;
}

yield return null;
}

private static IEnumerator ProcessSamples()
Expand Down Expand Up @@ -247,6 +264,24 @@ private static List<SampleInfo> GetRequiredSamples(List<SampleRequest> requests)
}
return samples;
}

private static void Filter(ref string[] names, PackageCollection collection)
{
var result = new List<string>();
foreach (var requestedPackage in names)
{
foreach (var existingPackage in collection)
{
if (existingPackage.name == requestedPackage)
{
result.Add(requestedPackage);
break;
}
}
}

names = result.ToArray();
}

private static void GetUnique(List<PackageRequest> requests,
out string[] adds, out string[] removes)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
},
{
"name": "com.unity.webrtc-ubiq-fork",
"expression": "0.0.0",
"expression": "3.0.1-pre.7",
"define": "UNITY_WEBRTC_UBIQ_FORK"
}
],
Expand Down

0 comments on commit 724063e

Please sign in to comment.