diff --git a/Runtime/Scripts/VRBroadcast.cs b/Runtime/Scripts/VRBroadcast.cs index 58440a3..02f0b62 100644 --- a/Runtime/Scripts/VRBroadcast.cs +++ b/Runtime/Scripts/VRBroadcast.cs @@ -12,6 +12,7 @@ using System.Linq; using UnityEngine; using Unity.RenderStreaming; +using Newtonsoft.Json; namespace FusedVR.VRStreaming { /// @@ -21,6 +22,14 @@ namespace FusedVR.VRStreaming { public class VRBroadcast : SignalingHandlerBase, IOfferHandler, IAddChannelHandler, IDisconnectHandler, IDeletedConnectionHandler { + #region Variables + /// + /// Check if client is listening for the same GameID + /// + [SerializeField] + [Tooltip("This ID should match the input from the Web Browser. Leave blank to match against anything")] + private string gameID = ""; + /// /// Streams (video, audio, data) that need to be sent to the client /// @@ -31,6 +40,7 @@ public class VRBroadcast : SignalingHandlerBase, /// List of all connectionIds that are connected /// private List connectionIds = new List(); + #endregion #region Disconnect public void OnDeletedConnection(SignalingEventData eventData) { @@ -63,13 +73,20 @@ private void Disconnect(string connectionId) { /// Determines whether to accept offer and if so that to apply sources and submit answer /// public void OnOffer(SignalingEventData data) { + + string inputGID = GetGameID(data.sdp); + if ( gameID.Length != 0 && inputGID != gameID) { + Debug.Log($"Offer Doesn't Match My GameID : {inputGID}"); + return; + } + if (connectionIds.Count >= 1) { //if there is more than 1 connection, let's skip this offer - Debug.Log($"Already answered this connectionId : {connectionIds[0]}"); + Debug.LogWarning($"Already answered this connectionId : {connectionIds[0]}"); return; } if (connectionIds.Contains(data.connectionId)) { //if connection is already connected, skip offer - Debug.Log($"Already answered this connectionId : {data.connectionId}"); + Debug.LogWarning($"Already answered this connectionId : {data.connectionId}"); return; } connectionIds.Add(data.connectionId); //confirm we will use this connection @@ -93,5 +110,13 @@ public void OnAddChannel(SignalingEventData data) { FirstOrDefault(r => r.Channel == null && !r.IsLocal); channel?.SetChannel(data.connectionId, data.channel); } + + private string GetGameID(string sdp) { + string[] parameters = sdp.Split('\n'); //split on new line + string customParam = parameters[parameters.Length - 2].Split('=')[1]; //get line before last new line and split on = + string value = ""; //get dictionary value + JsonConvert.DeserializeObject>(customParam).TryGetValue("user", out value); + return value; + } } } diff --git a/package.json b/package.json index 52f28b1..4607805 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,8 @@ "displayName": "FusedVR Streaming", "description": "This VR Streaming Package contains a minimal SDK & prefabs to implement VR Streaming (CloudXR) using WebRTC and Unity Remote Rendering", "dependencies": { - "com.unity.renderstreaming": "3.0.1-preview" + "com.unity.renderstreaming": "3.0.1-preview", + "com.unity.nuget.newtonsoft-json": "2.0.0" }, "keywords": [ "vr",