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)); }
/// <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); } }
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(); }
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}."); } }
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}."); } }