예제 #1
0
파일: WebRtcSession.cs 프로젝트: spFly/sip
        private async Task GetIceCandidatesAsync()
        {
            var localIPAddresses = _offerAddresses ?? NetServices.GetAllLocalIPAddresses();

            IceNegotiationStartedAt = DateTime.Now;
            LocalIceCandidates      = new List <IceCandidate>();

            foreach (var address in localIPAddresses.Where(x => x.AddressFamily == _rtpChannel.RTPLocalEndPoint.AddressFamily))
            {
                var iceCandidate = new IceCandidate(address, _rtpChannel.RTPPort);

                if (_turnServerEndPoint != null)
                {
                    iceCandidate.TurnServer = new TurnServer()
                    {
                        ServerEndPoint = _turnServerEndPoint
                    };
                    iceCandidate.InitialStunBindingCheck = SendTurnServerBindingRequest(iceCandidate);
                }

                LocalIceCandidates.Add(iceCandidate);
            }

            await Task.WhenAll(LocalIceCandidates.Where(x => x.InitialStunBindingCheck != null).Select(x => x.InitialStunBindingCheck));
        }
예제 #2
0
        /// <summary>
        /// Attempts to get a list of local ICE candidates.
        /// </summary>
        private async Task GetIceCandidatesAsync()
        {
            // The media is being multiplexed so the audio and video RTP channel is the same.
            var rtpChannel = GetRtpChannel(SDPMediaTypesEnum.audio);

            if (rtpChannel == null)
            {
                throw new ApplicationException("Cannot start gathering ICE candidates without an RTP channel.");
            }
            else
            {
                var localIPAddresses = _offerAddresses ?? NetServices.GetAllLocalIPAddresses();
                IceNegotiationStartedAt = DateTime.Now;
                LocalIceCandidates      = new List <IceCandidate>();

                foreach (var address in localIPAddresses.Where(x => x.AddressFamily == rtpChannel.RTPLocalEndPoint.AddressFamily))
                {
                    var iceCandidate = new IceCandidate(address, rtpChannel.RTPPort);

                    if (_turnServerEndPoint != null)
                    {
                        iceCandidate.TurnServer = new TurnServer()
                        {
                            ServerEndPoint = _turnServerEndPoint
                        };
                        iceCandidate.InitialStunBindingCheck = SendTurnServerBindingRequest(iceCandidate);
                    }

                    LocalIceCandidates.Add(iceCandidate);
                }

                await Task.WhenAll(LocalIceCandidates.Where(x => x.InitialStunBindingCheck != null).Select(x => x.InitialStunBindingCheck)).ConfigureAwait(false);
            }
        }
예제 #3
0
        static SIPChannel()
        {
            LocalIPAddresses = NetServices.GetAllLocalIPAddresses();

            // When using IPAddress.Any a default end point is still needed for placing in SIP headers and payloads.
            // Using 0.0.0.0 in SIP headers causes issues for some SIP software stacks.
            InternetDefaultAddress = NetServices.GetLocalAddressForInternet();
        }
예제 #4
0
        public void GetAllLocalIPAddressesUnitTest()
        {
            Console.WriteLine(System.Reflection.MethodBase.GetCurrentMethod().Name);

            var localAddresses = NetServices.GetAllLocalIPAddresses();

            Assert.NotNull(localAddresses);

            foreach (var localAddress in localAddresses)
            {
                Console.WriteLine($"Local address {localAddress}.");
            }
        }
예제 #5
0
        public void GetAllLocalIPAddressesUnitTest()
        {
            logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name);
            logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name);

            var localAddresses = NetServices.GetAllLocalIPAddresses();

            Assert.NotNull(localAddresses);

            foreach (var localAddress in localAddresses)
            {
                logger.LogDebug($"Local address {localAddress}.");
            }
        }