Пример #1
0
        private IEnumerator SdpAnswer()
        {
            yield return(new WaitForSeconds(1f));

            _mainThreadWorkQueue.Enqueue(() =>
            {
                PeerConnection.HandleConnectionMessageAsync(sdpAnswerReceiveVideo).ContinueWith(_ =>
                {
                    _nativePeer.CreateAnswer();
                    sdpAnswerReceiveVideo = null;
                }, TaskContinuationOptions.OnlyOnRanToCompletion | TaskContinuationOptions.RunContinuationsAsynchronously);
            });
        }
Пример #2
0
 private void Peer2_LocalSdpReadytoSend(Microsoft.MixedReality.WebRTC.SdpMessage message)
 {
     InvokeOnAppThread(async() =>
     {
         if (Peer1.Peer == null)
         {
             Debug.Log("Discarding SDP message for peer #1 (disabled)");
             return;
         }
         await Peer1.HandleConnectionMessageAsync(message);
         _remoteApplied1.Set();
         if (message.Type == Microsoft.MixedReality.WebRTC.SdpMessageType.Offer)
         {
             Peer1.Peer.CreateAnswer();
         }
     });
 }
Пример #3
0
        /// <summary>
        /// Internal coroutine helper for receiving HTTP data from the DSS server using GET
        /// and processing it as needed
        /// </summary>
        /// <returns>the message</returns>
        private IEnumerator CO_GetAndProcessFromServer()
        {
            if (HttpServerAddress.Length == 0)
            {
                throw new InvalidOperationException("Cannot receive SDP messages from remote peer; invalid empty HTTP server address.");
            }
            if (LocalPeerId.Length == 0)
            {
                throw new InvalidOperationException("Cannot receive SDP messages from remote peer; invalid empty local peer ID.");
            }

            var www = UnityWebRequest.Get($"{HttpServerAddress}data/{LocalPeerId}");

            yield return(www.SendWebRequest());

            if (!www.isNetworkError && !www.isHttpError)
            {
                var json = www.downloadHandler.text;

                var msg = JsonUtility.FromJson <NodeDssMessage>(json);

                // if the message is good
                if (msg != null)
                {
                    // depending on what type of message we get, we'll handle it differently
                    // this is the "glue" that allows two peers to establish a connection.
                    DebugLogLong($"Received SDP message: type={msg.MessageType} data={msg.Data}");
                    switch (msg.MessageType)
                    {
                    case NodeDssMessage.Type.Offer:
                        // Apply the offer coming from the remote peer to the local peer
                        var sdpOffer = new WebRTC.SdpMessage {
                            Type = SdpMessageType.Offer, Content = msg.Data
                        };
                        PeerConnection.HandleConnectionMessageAsync(sdpOffer).ContinueWith(_ =>
                        {
                            // If the remote description was successfully applied then immediately send
                            // back an answer to the remote peer to acccept the offer.
                            _nativePeer.CreateAnswer();
                        }, TaskContinuationOptions.OnlyOnRanToCompletion | TaskContinuationOptions.RunContinuationsAsynchronously);
                        break;

                    case NodeDssMessage.Type.Answer:
                        // No need to wait for completion; there is nothing interesting to do after it.
                        var sdpAnswer = new WebRTC.SdpMessage {
                            Type = SdpMessageType.Answer, Content = msg.Data
                        };
                        _ = PeerConnection.HandleConnectionMessageAsync(sdpAnswer);
                        break;

                    case NodeDssMessage.Type.Ice:
                        // this "parts" protocol is defined above, in OnIceCandidateReadyToSend listener
                        _nativePeer.AddIceCandidate(msg.ToIceCandidate());
                        break;

                    default:
                        Debug.Log("Unknown message: " + msg.MessageType + ": " + msg.Data);
                        break;
                    }

                    timeSincePollMs = PollTimeMs + 1f; //fast forward next request
                }
                else if (AutoLogErrors)
                {
                    Debug.LogError($"Failed to deserialize JSON message : {json}");
                }
            }
            else if (AutoLogErrors && www.isNetworkError)
            {
                Debug.LogError($"Network error trying to send data to {HttpServerAddress}: {www.error}");
            }
            else
            {
                // This is very spammy because the node-dss protocol uses 404 as regular "no data yet" message, which is an HTTP error
                //Debug.LogError($"HTTP error: {www.error}");
            }

            lastGetComplete = true;
        }
Пример #4
0
        /// <summary>
        /// Internal coroutine helper for receiving HTTP data from the DSS server using GET
        /// and processing it as needed
        /// </summary>
        /// <returns>the message</returns>
        private IEnumerator CO_GetAndProcessFromServer()
        {
            if (HttpServerAddress.Length == 0)
            {
                throw new InvalidOperationException("Cannot receive SDP messages from remote peer; invalid empty HTTP server address.");
            }
            if (LocalPeerId.Length == 0)
            {
                throw new InvalidOperationException("Cannot receive SDP messages from remote peer; invalid empty local peer ID.");
            }

            var www = UnityWebRequest.Get($"{HttpServerAddress}data/{LocalPeerId}");

            yield return(www.SendWebRequest());

            if (!www.isNetworkError && !www.isHttpError)
            {
                var json = www.downloadHandler.text;

                NodeDssMessage msg;

                if (Encrypt)
                {
                    EncryptedMessage encryptedMessage = JsonUtility.FromJson <EncryptedMessage>(json);
                    msg = EncryptedMessage.DecryptMessage(encryptedMessage.Cipher, encryptedMessage.Hmac, this.Key, this.IV);
                }
                else
                {
                    msg = JsonUtility.FromJson <NodeDssMessage>(json);
                }

                // {"Cipher":"U2FsdGVkX19P8RU1udAyP+QY2vllyVQgrWG4sn/3nItpon6PlKbIPyRCIanVhTMvJB6ipBByQuEqIg+/s/E+i6V8i3JFFZi4jzc45Dgy8cJCYpEwDSV6UCdG7MncTCcou/a85iWMDqLv5spi4CFtQ0lUq0pDpk6/itv2ki6Puh2CoPOpjyGW1VLp05mUp+FnOMTcEWT9tTzyBjgk5UOtAprAKW0VW9RZw29GwTj9sTInSbmvndxcjno4GClsgdEgIdVaTqGmXupEaCsKIHaJ7+cDHcTvR1mPRUkZxd3JN3GOYiMOt4R5B9rsxtkE4vZV4R0oDcSeUOj+mETbiBFLX1RDAiour7+Fl/YZYZs9Gtegm2cozxib8jDh+5vP71VkB1SQ8I/dNsIbmiYJ4hAh75Utu2YgH0g8UroeSJM5ds7Mw7wZstxpZ6Y7xZ11oUkhyYOkM+YZuNyVhMLi98RTEJmAVGypNZyrC9BVWE1vNiWDWpgpAPKNkL/WzDATqOV6Va963nQL0GMkxwXootBI+dUmVjEPzQ+8CtCNZj/9mJiqyJ1rI+bYfA7l0QJ9Eovrsm9kh9JFzx4FD0UI4pr+GW6VVXSW46Phd+gN7sXgvVMESEJt52JqehCVT+PEneyDv73rZhuQfk40ZqZ7agYVRAVn21cQb86MA7wqPKgMv3IEI2NDsYczetpZphpqZMZIDiT5MAd3PhfzHzSs45B7NVBwcT0k3VrG3s/2revnwBSAwa21racxQzv/h/qDTi3xmFE/90IeyoRsUuqqZ8BwpU0UUVNvghVFsTZ+yArApvxeS0qGL9wXR+7OkzWod9oBqC/OZTbpycVjirqbUwcD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UtJOtpoLfqF5ORqFZHcTdgzWYRGut2vbpcIkbHqYgycAHR9QIxew0BMB0H7tih3ZSvvDKlBBAGnAojgt6yc7SoJB/q1ygT2z0+IgIw4hwNXZTl+07IfSD5eVRbPSUDS0Q3NxPsb4VHkFIeveZsOEUQ9DseTJcGAixBqdWKoNcyV7bIfJYEyafD6xqGCTyryIw5RLkzc33KhVWYjlywiKVqVWTyC1xYcnKBm6J1kHJ1MTFSre07FqFxMNzkdIvLGSaQxig9g6CWcPz5p0waLm86qxY+kX/MowiibVVosNqGFPn03K0JncxKdHdbpwvI8IUc/4zoEabPfR3lE8ePxPHKxWveAU0Fjq9ARNxwmDHD5O1JX+k+uTcGkTGPGESOALi1jek52AEefTSfcqYQPAdAHmP9zHsTfyOzG4/VEuYSrioIQi8H2txnvVxN4PxKP49BwKPK6blBYd2kxA1Q7T1eSOakMsC4FPu6hbSbAm2l4FUyNj7SrHaHResgwHFWC9IU3ZxJC1VP+RQLIACfJ/spyt6uL4i1TNGMxyAGLeRLbCAclSiEqJVJDjiWp0kow/02zOI3QBgWKapH0EF2ere+lFMcnNwKPpq6dYxJZYIO9wwG744ioL2W2SMoWZ8B2a592FdTNshqDsszrJ/FT8PH7yzWoPLMbW3DYKXXvrEb0uWAg9ROwhHnWO2tOKZFMU02XaQjrWXzmiihacjuwsu70mOVquTja/HyH7o1yJ5wxVKHtcv39Hnbi5k4T2w87PG+kB1Hs5IJ/BvtxB9uS+K8U7dFNXJLSOz8kvBTCZrj02YVuhSDQB7oWtnyuJdSJe1Wg10QAWHVg=","Hmac":"b4302c1cc75d5916f009768e9396194d6bb7ff4fead75c62534779a778bb7f94"}



                // if the message is good
                if (msg != null)
                {
                    // depending on what type of message we get, we'll handle it differently
                    // this is the "glue" that allows two peers to establish a connection.
                    DebugLogLong($"Received SDP message: type={msg.MessageType} data={msg.Data}");
                    switch (msg.MessageType)
                    {
                    case NodeDssMessage.Type.Offer:
                        // Apply the offer coming from the remote peer to the local peer
                        var sdpOffer = new WebRTC.SdpMessage {
                            Type = SdpMessageType.Offer, Content = msg.Data
                        };
                        PeerConnection.HandleConnectionMessageAsync(sdpOffer).ContinueWith(_ =>
                        {
                            // If the remote description was successfully applied then immediately send
                            // back an answer to the remote peer to acccept the offer.
                            _nativePeer.CreateAnswer();
                            _nativePeer.DataChannelAdded += OnDataChannelAdded;
                        }, TaskContinuationOptions.OnlyOnRanToCompletion | TaskContinuationOptions.RunContinuationsAsynchronously);
                        break;

                    case NodeDssMessage.Type.Answer:
                        // No need to wait for completion; there is nothing interesting to do after it.
                        var sdpAnswer = new WebRTC.SdpMessage {
                            Type = SdpMessageType.Answer, Content = msg.Data
                        };
                        _ = PeerConnection.HandleConnectionMessageAsync(sdpAnswer);
                        break;

                    case NodeDssMessage.Type.Ice:
                        // this "parts" protocol is defined above, in OnIceCandidateReadyToSend listener
                        var iceCandidate = msg.ToIceCandidate();
                        break;

                    default:
                        Debug.Log("Unknown message: " + msg.MessageType + ": " + msg.Data);
                        break;
                    }

                    timeSincePollMs = PollTimeMs + 1f; //fast forward next request
                }
                else if (AutoLogErrors)
                {
                    Debug.LogError($"Failed to deserialize JSON message : {json}");
                }
            }
            else if (AutoLogErrors && www.isNetworkError)
            {
                Debug.LogError($"Network error trying to send data to {HttpServerAddress}: {www.error}");
            }
            else
            {
                // This is very spammy because the node-dss protocol uses 404 as regular "no data yet" message, which is an HTTP error
                //Debug.LogError($"HTTP error: {www.error}");
            }

            lastGetComplete = true;
        }
Пример #5
0
        public void OnReceivedData(object sender, EventArgs args)
        {
            if (args == null)
            {
                return;
            }

            // return early if wrong type of EventArgs
            var myArgs = args as TextEventArgs;

            if (myArgs == null)
            {
                Debug.Log("Got somethin elseg from ws:" + args.ToString());
                return;
            }

            var json = myArgs.Text;

            var msg = JsonConvert.DeserializeObject <OpenViduMessageJson>(json);

            // if the message is good
            if (msg != null)
            {
                if (!String.IsNullOrEmpty(msg.Method))
                {
                    if (msg.Method.Equals("iceCandidate"))
                    {
                        OpenViduIceCandidateEvent msg2 = JsonConvert.DeserializeObject <OpenViduIceCandidateEvent>(json);
                        var ic = new IceCandidate
                        {
                            SdpMid        = msg2.Params.SdpMid,
                            SdpMlineIndex = msg2.Params.SdpMLineIndex,
                            Content       = msg2.Params.Candidate,
                        };
                        Debug.Log("<color=white>IceCandidate</color>(SdpMid=" + ic.SdpMid +
                                  ", SdpMlineIndex=" + ic.SdpMlineIndex +
                                  ", Content=" + ic.Content +
                                  ")");
                        _nativePeer.AddIceCandidate(ic);
                    }
                    else
                    {
                        Debug.Log("<color=red>" + json + "</color>");
                    }
                }
                else if (messages.Contains(msg.id))
                {
                    //var id = Int32.Parse(msg.Id);
                    long         id          = msg.id;
                    OpenViduType messageType = (OpenViduType)messages[id];

                    switch (messageType)
                    {
                    case OpenViduType.Ping:
                        break;

                    case OpenViduType.JoinRoom:
                        joinRoomAnswer = JsonConvert.DeserializeObject <OpenViduJoinRoomAnswer>(json);



                        LocalPeerId = joinRoomAnswer.result.id;

                        startConnection = true;

                        break;

                    case OpenViduType.PublishVideo:
                        Debug.Log("<color=yellow>" + json + "</color>");
                        var msg2 = JsonConvert.DeserializeObject <OpenViduPublishVideoAnswer>(json);

                        sdpAnswer = new WebRTC.SdpMessage {
                            Type = SdpMessageType.Answer, Content = msg2.Result.SdpAnswer
                        };

                        break;

                    case OpenViduType.ReceiveVideoFrom:
                        Debug.Log("<color=yellow>" + json + "</color>");
                        var msg3 = JsonConvert.DeserializeObject <OpenViduReceiveVideoAnswer>(json);
                        sdpAnswerReceiveVideo = new WebRTC.SdpMessage {
                            Type = SdpMessageType.Answer, Content = msg3.Result.SdpAnswer
                        };

                        _mainThreadWorkQueue.Enqueue(() =>
                        {
                            PeerConnection.HandleConnectionMessageAsync(sdpAnswerReceiveVideo);

                            /*PeerConnection.HandleConnectionMessageAsync(sdpAnswerReceiveVideo).ContinueWith(_ =>
                             * {
                             *  _nativePeer.CreateAnswer(); //this only works if local video is not published
                             * }, TaskContinuationOptions.OnlyOnRanToCompletion | TaskContinuationOptions.RunContinuationsAsynchronously);*/
                        });

                        break;

                    case OpenViduType.OnIceCandidate:
                        msg = JsonConvert.DeserializeObject <OpenViduOnIceCandidateAnswer>(json);
                        break;

                    default:
                        break;
                    }

                    timeSincePollMs = PollTimeMs + 1f; //fast forward next request
                }
            }
            else if (AutoLogErrors)
            {
                Debug.LogError($"Failed to deserialize JSON message : {json}");
            }
        }