Esempio n. 1
0
 private void AddActionsToSignalingWebSocket()
 {
     signaling.OnMessage += (sender, message) =>
     {
         logger.LogDebug($"Received message: {message.Data}");
         if (message.Data == "{\"data\":{\"getRemoteMedia\":true}}")
         {
             Negotiate();
             return;
         }
         if (message.Data == "{\"data\":{\"candidate\":null}}")
         {
             return;
         }
         string correct_message = ConvertString(message.Data);
         logger.LogDebug($"After nesting:{correct_message}");
         if (RTCIceCandidateInit.TryParse(correct_message, out var IceCandidate))
         {
             logger.LogDebug($"Got remote candidate: {correct_message}");
             pc.addIceCandidate(IceCandidate);
         }
         else if (RTCSessionDescriptionInit.TryParse(correct_message, out var SDP))
         {
             logger.LogDebug($"Setting SDP: {correct_message}");
             var result = pc.setRemoteDescription(SDP);
             if (result != SetDescriptionResultEnum.OK)
             {
                 logger.LogWarning($"Failed to set remote description, {result}.");
                 pc.Close("failed to set remote description");
             }
         }
     };
 }
        public void ToJsonUnitTest()
        {
            logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name);
            logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name);

            var candidate = RTCIceCandidate.Parse("1390596646 1 udp 1880747346 192.168.11.50 61680 typ host generation 0");

            Assert.NotNull(candidate);
            Assert.Equal(RTCIceCandidateType.host, candidate.type);
            Assert.Equal(RTCIceProtocol.udp, candidate.protocol);

            logger.LogDebug(candidate.toJSON());

            bool parseResult = RTCIceCandidateInit.TryParse(candidate.toJSON(), out var init);

            Assert.True(parseResult);

            Assert.Equal(0, init.sdpMLineIndex);
            Assert.Equal("0", init.sdpMid);

            var initCandidate = RTCIceCandidate.Parse(init.candidate);

            Assert.Equal(RTCIceCandidateType.host, initCandidate.type);
            Assert.Equal(RTCIceProtocol.udp, initCandidate.protocol);
        }
Esempio n. 3
0
        private void DoProcessMessage(Message message)
        {
            switch (message.type)
            {
            case "Offer":
                // var offer = JsonUtility.FromJson<RTCSessionDescriptionInit>(message.args);
                if (RTCSessionDescriptionInit.TryParse(message.args, out RTCSessionDescriptionInit offer))
                {
                    Debug.Log($"Got remote SDP, type {offer.type}");

                    var result = rtcPeerConnection.setRemoteDescription(offer);
                    if (result != SetDescriptionResultEnum.OK)
                    {
                        Debug.Log($"Failed to set remote description, {result}.");
                        rtcPeerConnection.Close("Failed to set remote description");
                    }
                    else
                    {
                        if (rtcPeerConnection.signalingState == RTCSignalingState.have_remote_offer)
                        {
                            var answerSdp = rtcPeerConnection.createAnswer();
                            rtcPeerConnection.setLocalDescription(answerSdp);

                            Debug.Log($"Sending SDP answer");

                            Send("Offer", answerSdp.toJSON());
                        }
                    }
                }
                break;

            case "IceCandidate":
                if (RTCIceCandidateInit.TryParse(message.args, out RTCIceCandidateInit candidate))
                {
                    Debug.Log($"Got remote Ice Candidate, uri {candidate.candidate}");
                    rtcPeerConnection.addIceCandidate(candidate);
                }
                break;
            }
        }