Skip to content

Commit

Permalink
Add workaround for compatibility issue between Unity's WebRTC and Ocu…
Browse files Browse the repository at this point in the history
…lus/OpenXR SDK
  • Loading branch information
bnco committed Jan 26, 2024
1 parent f262fdc commit 2ca2da6
Show file tree
Hide file tree
Showing 17 changed files with 152 additions and 33 deletions.
8 changes: 8 additions & 0 deletions Unity/Assets/Editor/Packaging.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

66 changes: 66 additions & 0 deletions Unity/Assets/Editor/Packaging/AddPackageWebRTC.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#if !UNITY_WEBRTC_NO_VULKAN_HOOK && !UBIQ_SKIPCHECK_WEBRTCCOMPATIBILITY
using UnityEngine;
using UnityEditor;
using UnityEditor.PackageManager;
using UnityEditor.PackageManager.Requests;

namespace Ubiq.Samples.Demo.Editor
{
[InitializeOnLoad]
public class AddPackageWebRTC
{
private const string FORK_URL = "https://github.com/UCL-VR/unity-webrtc-no-vulkan-hook.git";
#if UNITY_WEBRTC
AddAndRemoveRequest request;
#else
AddRequest request;
#endif
AddAndRemoveRequest foo;

static AddPackageWebRTC()
{
Debug.Log("Ubiq attempting to add WebRTC to project requirements." +
" Please wait...");
var instance = new AddPackageWebRTC();
#if UNITY_WEBRTC
Debug.LogWarning("Ubiq has detected an existing com.unity.webrtc" +
" package. This package has compatibility issues with the" +
" Oculus/OpenXR SDK. Ubiq will remove this package and" +
" replace it with a modified fork which is compatible. If you" +
" would prefer to skip this check and prevent this behaviour," +
" add the string UBIQ_SKIPCHECK_WEBRTCCOMPATIBILITY to your" +
" scripting define symbols.");
instance.request = Client.AddAndRemove(
packagesToAdd : new string[] {FORK_URL},
packagesToRemove : new string[] {"com.unity.webrtc"}
);
#else
instance.request = Client.Add(FORK_URL);
#endif
EditorApplication.update += instance.Update;
}

void Update()
{
if (request == null)
{
EditorApplication.update -= Update;
}

if (request.Status == StatusCode.Failure)
{
var error = request.Error != null ? request.Error.message : "None specified";
Debug.LogError($"Ubiq was unable to add WebRTC to project requirements. Error: {error}");
EditorApplication.update -= Update;
}

if (request.Status == StatusCode.Success)
{
EditorApplication.update -= Update;
Debug.Log("Ubiq added WebRTC to project requirements.");
AssetDatabase.Refresh();
}
}
}
}
#endif
11 changes: 11 additions & 0 deletions Unity/Assets/Editor/Packaging/AddPackageWebRTC.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 13 additions & 1 deletion Unity/Assets/Editor/Ubiq.Editor.asmdef
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"name": "Ubiq.Editor",
"rootNamespace": "",
"references": [
"GUID:ab979a98ba0be4546bceb48f770b11c8",
"GUID:4be54a12296e0404db7080c914e17b05"
Expand All @@ -13,6 +14,17 @@
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": [],
"versionDefines": [
{
"name": "com.unity.webrtc",
"expression": "0.0.0",
"define": "UNITY_WEBRTC"
},
{
"name": "com.unity.webrtc-no-vulkan-hook",
"expression": "0.0.0",
"define": "UNITY_WEBRTC_NO_VULKAN_HOOK"
}
],
"noEngineReferences": false
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@
"iOS",
"LinuxStandalone64",
"CloudRendering",
"Lumin",
"macOSStandalone",
"PS4",
"PS5",
"QNX",
"Stadia",
"Switch",
"tvOS",
"WSA",
"VisionOS",
"WebGL",
"WindowsStandalone32",
"WindowsStandalone64",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
using System;
using System.Collections.Generic;
using UnityEngine;

namespace Ubiq.Voip.Implementations.Null
namespace Ubiq.Voip.Implementations
{
public class PeerConnectionImpl : IPeerConnectionImpl
public class NullPeerConnectionImpl : IPeerConnectionImpl
{
#pragma warning disable CS0067
public event IceConnectionStateChangedDelegate iceConnectionStateChanged;
public event PeerConnectionStateChangedDelegate peerConnectionStateChanged;
#pragma warning restore CS0067
public void Dispose() {}
public PlaybackStats GetLastFramePlaybackStats() => new PlaybackStats();
public void ProcessSignalingMessage(string json) {}
public void Setup(IPeerConnectionContext context, bool polite, List<IceServerDetails> iceServers)
public void Setup(IPeerConnectionContext context, bool polite, List<IceServerDetails> iceServers, Action<AudioStats> playbackStatsPushed, Action<AudioStats> recordStatsPushed, Action<IceConnectionState> iceConnectionStateChanged, Action<PeerConnectionState> peerConnectionStateChanged)
{
// Pretend we are connected to silence/hide warnings
if (iceConnectionStateChanged != null)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#if UNITY_WEBRTC || UNITY_WEBRTC_NO_VULKAN_HOOK
using System;
using UnityEngine;
using System.Collections.Concurrent;
Expand Down Expand Up @@ -70,4 +71,5 @@ private void OnAudioFilterRead(float[] data, int channels)
statsQueue.Enqueue(new AudioStats(length,volumeSum,0));
}
}
}
}
#endif
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#if UNITY_WEBRTC || UNITY_WEBRTC_NO_VULKAN_HOOK
using System;
using System.Collections;
using System.Collections.Generic;
Expand Down Expand Up @@ -486,4 +487,5 @@ private static void Send(IPeerConnectionContext context, RTCIceCandidate ic)
)));
}
}
}
}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ public static class PeerConnectionImplFactory
{
public static IPeerConnectionImpl Create()
{
#if UNITY_WEBRTC || UNITY_WEBRTC_NO_VULKAN_HOOK
return new Ubiq.Voip.Implementations.Unity.PeerConnectionImpl();
#else
return new Ubiq.Voip.Implementations.NullPeerConnectionImpl();
#endif
}
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#if UNITY_WEBRTC || UNITY_WEBRTC_NO_VULKAN_HOOK
using System;
using System.Collections;
using System.Collections.Generic;
Expand Down Expand Up @@ -144,4 +145,5 @@ public void RemoveUser(GameObject user)
users.Remove(user);
}
}
}
}
#endif
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#if UNITY_WEBRTC || UNITY_WEBRTC_NO_VULKAN_HOOK
using UnityEngine;

namespace Ubiq.Voip.Implementations.Unity
Expand Down Expand Up @@ -26,4 +27,5 @@ void OnAudioFilterRead(float[] data, int channels)
}
}
}
}
}
#endif
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#if UNITY_WEBRTC || UNITY_WEBRTC_NO_VULKAN_HOOK
using UnityEngine;

namespace Ubiq.Voip.Implementations.Unity
Expand Down Expand Up @@ -31,4 +32,5 @@ void OnAudioFilterRead(float[] data, int channels)
}
}
}
}
}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,17 @@
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": [],
"versionDefines": [
{
"name": "com.unity.webrtc",
"expression": "0.0.0",
"define": "UNITY_WEBRTC"
},
{
"name": "com.unity.webrtc-no-vulkan-hook",
"expression": "0.0.0",
"define": "UNITY_WEBRTC_NO_VULKAN_HOOK"
}
],
"noEngineReferences": false
}
24 changes: 12 additions & 12 deletions Unity/Assets/Samples/Demo (XRI)/Demo.unity
Original file line number Diff line number Diff line change
Expand Up @@ -677,32 +677,32 @@ PrefabInstance:
- target: {fileID: 2111886246478503278, guid: 46c1f5d5a11cf5042886aabd56e7b9d7,
type: 3}
propertyPath: m_AnchorMax.y
value: 1
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2111886246478503278, guid: 46c1f5d5a11cf5042886aabd56e7b9d7,
type: 3}
propertyPath: m_AnchorMin.y
value: 1
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2111886246478503278, guid: 46c1f5d5a11cf5042886aabd56e7b9d7,
type: 3}
propertyPath: m_SizeDelta.x
value: 30
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2111886246478503278, guid: 46c1f5d5a11cf5042886aabd56e7b9d7,
type: 3}
propertyPath: m_SizeDelta.y
value: 40
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2111886246478503278, guid: 46c1f5d5a11cf5042886aabd56e7b9d7,
type: 3}
propertyPath: m_AnchoredPosition.x
value: 53
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2111886246478503278, guid: 46c1f5d5a11cf5042886aabd56e7b9d7,
type: 3}
propertyPath: m_AnchoredPosition.y
value: -22.5
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2407431680527197411, guid: 46c1f5d5a11cf5042886aabd56e7b9d7,
type: 3}
Expand Down Expand Up @@ -982,32 +982,32 @@ PrefabInstance:
- target: {fileID: 5293975139575421772, guid: 46c1f5d5a11cf5042886aabd56e7b9d7,
type: 3}
propertyPath: m_AnchorMax.y
value: 1
value: 0
objectReference: {fileID: 0}
- target: {fileID: 5293975139575421772, guid: 46c1f5d5a11cf5042886aabd56e7b9d7,
type: 3}
propertyPath: m_AnchorMin.y
value: 1
value: 0
objectReference: {fileID: 0}
- target: {fileID: 5293975139575421772, guid: 46c1f5d5a11cf5042886aabd56e7b9d7,
type: 3}
propertyPath: m_SizeDelta.x
value: 30
value: 0
objectReference: {fileID: 0}
- target: {fileID: 5293975139575421772, guid: 46c1f5d5a11cf5042886aabd56e7b9d7,
type: 3}
propertyPath: m_SizeDelta.y
value: 40
value: 0
objectReference: {fileID: 0}
- target: {fileID: 5293975139575421772, guid: 46c1f5d5a11cf5042886aabd56e7b9d7,
type: 3}
propertyPath: m_AnchoredPosition.x
value: 21
value: 0
objectReference: {fileID: 0}
- target: {fileID: 5293975139575421772, guid: 46c1f5d5a11cf5042886aabd56e7b9d7,
type: 3}
propertyPath: m_AnchoredPosition.y
value: -22.5
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8225375711087241992, guid: 46c1f5d5a11cf5042886aabd56e7b9d7,
type: 3}
Expand Down
2 changes: 1 addition & 1 deletion Unity/Packages/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"com.unity.timeline": "1.7.6",
"com.unity.toolchain.win-x86_64-linux-x86_64": "2.0.4",
"com.unity.ugui": "1.0.0",
"com.unity.webrtc": "3.0.0-pre.7",
"com.unity.webrtc-no-vulkan-hook": "https://github.com/UCL-VR/unity-webrtc-no-vulkan-hook.git",
"com.unity.xr.interaction.toolkit": "2.5.2",
"com.unity.xr.management": "4.4.0",
"com.unity.xr.oculus": "4.1.2",
Expand Down
8 changes: 4 additions & 4 deletions Unity/Packages/packages-lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -145,16 +145,16 @@
"com.unity.modules.imgui": "1.0.0"
}
},
"com.unity.webrtc": {
"version": "3.0.0-pre.7",
"com.unity.webrtc-no-vulkan-hook": {
"version": "https://github.com/UCL-VR/unity-webrtc-no-vulkan-hook.git",
"depth": 0,
"source": "registry",
"source": "git",
"dependencies": {
"com.unity.modules.jsonserialize": "1.0.0",
"com.unity.editorcoroutines": "1.0.0",
"com.unity.modules.audio": "1.0.0"
},
"url": "https://packages.unity.com"
"hash": "deac61d7009e3d04bd7f8e1f8d33227bdddac153"
},
"com.unity.xr.core-utils": {
"version": "2.2.3",
Expand Down

0 comments on commit 2ca2da6

Please sign in to comment.