public void SortChecklistUnitTest() { logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name); logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name); var rtpIceChannel = new RtpIceChannel(null, RTCIceComponent.rtp, null); rtpIceChannel.StartGathering(); Assert.NotNull(rtpIceChannel); Assert.NotEmpty(rtpIceChannel.Candidates); foreach (var hostCandidate in rtpIceChannel.Candidates) { logger.LogDebug(hostCandidate.ToString()); } var remoteCandidate = RTCIceCandidate.Parse("candidate:408132416 1 udp 2113937151 192.168.11.50 51268 typ host generation 0 ufrag CI7o network-cost 999"); rtpIceChannel.AddRemoteCandidate(remoteCandidate); var remoteCandidate2 = RTCIceCandidate.Parse("candidate:408132417 1 udp 2113937150 192.168.11.51 51268 typ host generation 0 ufrag CI7o network-cost 999"); rtpIceChannel.AddRemoteCandidate(remoteCandidate2); foreach (var entry in rtpIceChannel._checklist) { logger.LogDebug($"checklist entry priority {entry.Priority}."); } }
public void NonEquivalentCandidateFoundationUnitTest() { logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name); logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name); RTCIceCandidateInit initA = new RTCIceCandidateInit { usernameFragment = "abcd" }; var candidateA = new RTCIceCandidate(initA); candidateA.SetAddressProperties(RTCIceProtocol.udp, IPAddress.Loopback, 1024, RTCIceCandidateType.host, null, 0); RTCIceCandidateInit initB = new RTCIceCandidateInit { usernameFragment = "efgh" }; var candidateB = new RTCIceCandidate(initB); candidateB.SetAddressProperties(RTCIceProtocol.udp, IPAddress.IPv6Loopback, 1024, RTCIceCandidateType.host, null, 0); Assert.NotNull(candidateA); Assert.NotNull(candidateB); Assert.NotEqual(candidateA.foundation, candidateB.foundation); logger.LogDebug(candidateA.ToString()); logger.LogDebug(candidateB.ToString()); }
public async void ChecklistProcessingToFailStateUnitTest() { logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name); logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name); var rtpIceChannel = new RtpIceChannel(null, RTCIceComponent.rtp, null); rtpIceChannel.StartGathering(); Assert.NotNull(rtpIceChannel); Assert.NotEmpty(rtpIceChannel.Candidates); foreach (var hostCandidate in rtpIceChannel.Candidates) { logger.LogDebug($"host candidate: {hostCandidate}"); } var remoteCandidate = RTCIceCandidate.Parse("candidate:408132416 1 udp 2113937151 192.168.11.50 51268 typ host generation 0 ufrag CI7o network-cost 999"); rtpIceChannel.AddRemoteCandidate(remoteCandidate); rtpIceChannel.SetRemoteCredentials("CI7o", "xxxxxxxxxxxx"); logger.LogDebug($"ICE session retry interval {rtpIceChannel.RTO}ms."); await Task.Delay(1000); rtpIceChannel._checklist.Single().FirstCheckSentAt = DateTime.Now.Subtract(TimeSpan.FromSeconds(RtpIceChannel.FAILED_TIMEOUT_PERIOD)); await Task.Delay(1000); Assert.Equal(ChecklistEntryState.Failed, rtpIceChannel._checklist.Single().State); Assert.Equal(ChecklistState.Failed, rtpIceChannel._checklistState); Assert.Equal(RTCIceConnectionState.failed, rtpIceChannel.IceConnectionState); }
public async void ChecklistProcessingUnitTest() { logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name); logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name); var rtpIceChannel = new RtpIceChannel(null, RTCIceComponent.rtp, null); rtpIceChannel.StartGathering(); Assert.NotNull(rtpIceChannel); Assert.NotEmpty(rtpIceChannel.Candidates); foreach (var hostCandidate in rtpIceChannel.Candidates) { logger.LogDebug($"host candidate: {hostCandidate}"); } var remoteCandidate = RTCIceCandidate.Parse("candidate:408132416 1 udp 2113937151 192.168.11.50 51268 typ host generation 0 ufrag CI7o network-cost 999"); rtpIceChannel.AddRemoteCandidate(remoteCandidate); rtpIceChannel.SetRemoteCredentials("CI7o", "xxxxxxxxxxxx"); rtpIceChannel.StartGathering(); await Task.Delay(2000); var checklistEntry = rtpIceChannel._checklist.Single(); logger.LogDebug($"Checklist entry state {checklistEntry.State}, last check sent at {checklistEntry.LastCheckSentAt}."); Assert.Equal(ChecklistEntryState.InProgress, checklistEntry.State); }
public async void ChecklistConstructionUnitTest() { logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name); logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name); var rtpIceChannel = new RtpIceChannel(null, RTCIceComponent.rtp, null); rtpIceChannel.StartGathering(); Assert.NotNull(rtpIceChannel); Assert.NotEmpty(rtpIceChannel.Candidates); foreach (var hostCandidate in rtpIceChannel.Candidates) { logger.LogDebug($"host candidate: {hostCandidate}"); } var remoteCandidate = RTCIceCandidate.Parse("candidate:408132416 1 udp 2113937151 192.168.11.50 51268 typ host generation 0 ufrag CI7o network-cost 999"); rtpIceChannel.AddRemoteCandidate(remoteCandidate); var remoteCandidate2 = RTCIceCandidate.Parse("candidate:408132417 1 udp 2113937150 192.168.11.50 51268 typ host generation 0 ufrag CI7o network-cost 999"); rtpIceChannel.AddRemoteCandidate(remoteCandidate2); await Task.Delay(500); foreach (var entry in rtpIceChannel._checklist) { logger.LogDebug($"checklist entry: {entry.LocalCandidate.ToShortString()}->{entry.RemoteCandidate.ToShortString()}"); } Assert.Single(rtpIceChannel._checklist); }
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); }
public async void ChecklistProcessingToFailStateUnitTest() { logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name); logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name); var rtpIceChannel = new RtpIceChannel(null, RTCIceComponent.rtp, null); rtpIceChannel.StartGathering(); Assert.NotNull(rtpIceChannel); Assert.NotEmpty(rtpIceChannel.Candidates); foreach (var hostCandidate in rtpIceChannel.Candidates) { logger.LogDebug($"host candidate: {hostCandidate}"); } var remoteCandidate = RTCIceCandidate.Parse("candidate:408132416 1 udp 2113937151 192.168.11.50 51268 typ host generation 0 ufrag CI7o network-cost 999"); rtpIceChannel.AddRemoteCandidate(remoteCandidate); rtpIceChannel.SetRemoteCredentials("CI7o", "xxxxxxxxxxxx"); logger.LogDebug($"ICE session retry interval {rtpIceChannel.RTO}ms."); // The defaults are 5 STUN requests and for a checklist with one entry they will be 500ms apart. await Task.Delay(4000); Assert.Equal(ChecklistEntryState.Failed, rtpIceChannel._checklist.Single().State); Assert.Equal(ChecklistState.Failed, rtpIceChannel._checklistState); Assert.Equal(RTCIceConnectionState.failed, rtpIceChannel.IceConnectionState); }
public void ChecklistConstructionUnitTest() { logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name); logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name); RTPChannel rtpChannel = new RTPChannel(false, null); var iceSession = new IceSession(rtpChannel, RTCIceComponent.rtp); Assert.NotNull(iceSession); Assert.NotEmpty(iceSession.Candidates); foreach (var hostCandidate in iceSession.Candidates) { logger.LogDebug($"host candidate: {hostCandidate}"); } var remoteCandidate = RTCIceCandidate.Parse("candidate:408132416 1 udp 2113937151 192.168.11.50 51268 typ host generation 0 ufrag CI7o network-cost 999"); iceSession.AddRemoteCandidate(remoteCandidate); var remoteCandidate2 = RTCIceCandidate.Parse("candidate:408132417 1 udp 2113937150 192.168.11.50 51268 typ host generation 0 ufrag CI7o network-cost 999"); iceSession.AddRemoteCandidate(remoteCandidate2); foreach (var entry in iceSession._checklist) { logger.LogDebug($"checklist entry: {entry.LocalCandidate} -> {entry.RemoteCandidate}"); } Assert.Single(iceSession._checklist); }
public async void ChecklistProcessingUnitTest() { logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name); logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name); RTPChannel rtpChannel = new RTPChannel(false, null); var iceSession = new IceSession(rtpChannel, RTCIceComponent.rtp); Assert.NotNull(iceSession); Assert.NotEmpty(iceSession.Candidates); foreach (var hostCandidate in iceSession.Candidates) { logger.LogDebug($"host candidate: {hostCandidate}"); } var remoteCandidate = RTCIceCandidate.Parse("candidate:408132416 1 udp 2113937151 192.168.11.50 51268 typ host generation 0 ufrag CI7o network-cost 999"); iceSession.AddRemoteCandidate(remoteCandidate); iceSession.SetRemoteCredentials("CI7o", "xxxxxxxxxxxx"); iceSession.StartGathering(); await Task.Delay(1000); Assert.Equal(IceSession.ChecklistEntryState.InProgress, iceSession._checklist.Single().State); }
public void SortChecklistUnitTest() { logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name); logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name); RTPSession rtpSession = new RTPSession(true, true, true); MediaStreamTrack dummyTrack = new MediaStreamTrack(null, SDPMediaTypesEnum.audio, false, new List<SDPMediaFormat> { new SDPMediaFormat(SDPMediaFormatsEnum.PCMU) }); rtpSession.addTrack(dummyTrack); var iceSession = new IceSession(rtpSession.GetRtpChannel(SDPMediaTypesEnum.audio), RTCIceComponent.rtp); Assert.NotNull(iceSession); Assert.NotEmpty(iceSession.Candidates); foreach (var hostCandidate in iceSession.Candidates) { logger.LogDebug(hostCandidate.ToString()); } var remoteCandidate = RTCIceCandidate.Parse("candidate:408132416 1 udp 2113937151 192.168.11.50 51268 typ host generation 0 ufrag CI7o network-cost 999"); iceSession.AddRemoteCandidate(remoteCandidate); var remoteCandidate2 = RTCIceCandidate.Parse("candidate:408132417 1 udp 2113937150 192.168.11.51 51268 typ host generation 0 ufrag CI7o network-cost 999"); iceSession.AddRemoteCandidate(remoteCandidate2); foreach (var entry in iceSession._checklist) { logger.LogDebug($"checklist entry priority {entry.Priority}."); } }
public static async Task <string> SendIceCandidateAndGetResonse(RTCIceCandidate iceCandidate, string address) { var objectJson = JsonConvert.SerializeObject(iceCandidate); var serverAnswer = await SendMessageAndGetResponseAsync(objectJson, Protocol.MessageType.IceCandidate, Protocol.MessageType.IceAnswer, address); return(serverAnswer); }
public void ConstructWithOption() { var option = new RTCIceCandidateInit { sdpMid = "0", sdpMLineIndex = 0, candidate = "candidate:102362043 1 udp 2122262783 240b:10:2fe0:4900:3cbd:7306:63c4:a8e1 50241 typ host generation 0 ufrag DEIG network-id 5" }; var candidate = new RTCIceCandidate(option); Assert.IsNotEmpty(candidate.Candidate); Assert.AreEqual(candidate.Candidate, option.candidate); Assert.AreEqual(candidate.SdpMLineIndex, option.sdpMLineIndex); Assert.AreEqual(candidate.SdpMid, option.sdpMid); Assert.AreEqual(RTCIceComponent.Rtp, candidate.Component); Assert.IsNotEmpty(candidate.Foundation); Assert.NotNull(candidate.Port); Assert.NotNull(candidate.Priority); Assert.IsNotEmpty(candidate.Address); Assert.NotNull(candidate.Protocol); Assert.IsNotEmpty(candidate.RelatedAddress); Assert.NotNull(candidate.RelatedPort); Assert.IsNotEmpty(candidate.SdpMid); Assert.NotNull(candidate.SdpMLineIndex); Assert.NotNull(candidate.Type); Assert.Null(candidate.TcpType); Assert.IsNotEmpty(candidate.UserNameFragment); }
private void OnIceCandidate(RTCPeerConnection pc, RTCIceCandidate candidate) { switch ((ProtocolOption)dropDownProtocol.value) { case ProtocolOption.Default: break; case ProtocolOption.UDP: if (candidate.Protocol != RTCIceProtocol.Udp) { return; } break; case ProtocolOption.TCP: if (candidate.Protocol != RTCIceProtocol.Tcp) { return; } break; } GetOtherPc(pc).AddIceCandidate(candidate); Debug.Log($"{GetName(pc)} ICE candidate:\n {candidate.Candidate}"); }
public IEnumerator UnitySetUp() { WebRTC.WebRTC.Initialize(); RTCConfiguration config = default; RTCIceCandidate candidate_ = null; config.iceServers = new[] { new RTCIceServer { urls = new[] { "stun:stun.l.google.com:19302" } } }; var peer1 = new RTCPeerConnection(ref config); var peer2 = new RTCPeerConnection(ref config); peer1.OnIceCandidate = candidate => { candidate_ = candidate; }; MediaStream stream = WebRTC.Audio.CaptureStream(); peer1.AddTrack(stream.GetTracks().First()); RTCOfferOptions offerOptions = new RTCOfferOptions(); var op1 = peer1.CreateOffer(ref offerOptions); yield return(op1); m_DescOffer = op1.Desc; var op2 = peer1.SetLocalDescription(ref m_DescOffer); yield return(op2); var op3 = peer2.SetRemoteDescription(ref m_DescOffer); yield return(op3); RTCAnswerOptions answerOptions = new RTCAnswerOptions(); var op4 = peer2.CreateAnswer(ref answerOptions); yield return(op4); m_DescAnswer = op4.Desc; var op5 = peer2.SetLocalDescription(ref m_DescAnswer); yield return(op5); var op6 = peer1.SetRemoteDescription(ref m_DescAnswer); yield return(op6); yield return(new WaitUntil(() => candidate_ != null)); m_candidate = candidate_; stream.Dispose(); peer1.Close(); peer2.Close(); m_Context = SynchronizationContext.Current; signaling1 = CreateSignaling(m_SignalingType, m_Context); signaling2 = CreateSignaling(m_SignalingType, m_Context); }
public void DidGenerateIceCandidate(RTCPeerConnection peerConnection, RTCIceCandidate candidate) { DispatchForPeerConnectionAsync(() => { var message = new ARDICECandidateMessage(candidate); SendSignalingMessage(message); }); }
private void onIceCandidate(string clientId, string candidate, string sdpMid, int sdpMLineIndex) { var cand = new RTCIceCandidate { candidate = candidate, sdpMid = sdpMid, sdpMLineIndex = sdpMLineIndex }; pc.AddIceCandidate(ref cand); }
public static RTCIceCandidate IceCandidateFromJsonMessage(JsonObject jsonObject) { var candidate = new RTCIceCandidate( jsonObject.GetNamedString(kCandidateSdpName), jsonObject.GetNamedString(kCandidateSdpMidName), (ushort)jsonObject.GetNamedNumber(kCandidateSdpMlineIndexName)); return(candidate); }
public void EnqueueLocalIceCandidate(IPeerConnection peerConnection, RTCIceCandidate candidate) { if (peerConnection is null) { throw new ArgumentNullException(nameof(peerConnection)); } ThrowWhenInvalidIceCandidate(candidate); _negotiationQueue.Enqueue(new IceCandidateMessage(peerConnection, candidate, false)); }
public static DtoIceCandidate ToDto(this RTCIceCandidate obj) { return(new DtoIceCandidate { Candidate = obj.Candidate, SdpMid = obj.SdpMid, SdpMLineIndex = obj.SdpMLineIndex }); }
public async Task SignalIceCandidate(RTCIceCandidate ice, Guid peerId, string toName, Guid roomId) { if (toName == null) { return; } var clientId = _roomService.GetRoomMember(roomId, toName).ConnectionId; await Clients.Client(clientId).SendAsync("NewIce", ice, peerId); }
public static string toJSON(this RTCIceCandidate candidate) { return("{" + $" \"sdpMid\": \"{candidate.sdpMid ?? candidate.sdpMLineIndex.ToString()}\"," + $" \"sdpMLineIndex\": {candidate.sdpMLineIndex}," + $" \"usernameFragment\": \"\"," + $" \"candidate\": \"{candidate.candidate}\"" + "}"); }
public static bool TryParseIceCandidate(string json, out RTCIceCandidate candidate) { candidate = new RTCIceCandidate(); candidate.sdpMid = Regex.Match(json, @"""sdpMid"":\s*""(?<sdpMid>.*?)""", RegexOptions.IgnoreCase).Result("${sdpMid}"); candidate.sdpMLineIndex = Convert.ToInt32(Regex.Match(json, @"""sdpMLineIndex"":\s*(?<sdpMLineIndex>\d+)", RegexOptions.IgnoreCase).Result("${sdpMLineIndex}")); candidate.candidate = Regex.Match(json, @"""candidate"":\s*""(?<candidate>.*?)""", RegexOptions.IgnoreCase).Result("${candidate}"); return(candidate.candidate != null); }
public void SendCandidate(string receiverEmail, RTCIceCandidate candidate) { var receiverUser = Users.Where(x => x.Email == receiverEmail).FirstOrDefault(); if (receiverUser != null) { var context = GlobalHost.ConnectionManager.GetHubContext <UserActivityHub>(); context.Clients.Client(receiverUser.ClientId).incommingCandidate(candidate); } }
static void ThrowWhenInvalidIceCandidate(RTCIceCandidate candidate) { if (string.IsNullOrWhiteSpace(candidate.Candidate)) { throw new ArgumentException($"{nameof(candidate.Candidate)} cannot be null or empty"); } if (string.IsNullOrWhiteSpace(candidate.SdpMid)) { throw new ArgumentException($"{nameof(candidate.SdpMid)} cannot be null or empty"); } }
private void Signaling_OnIceCandidate(AntMediaSignalingMessage msg) { var candidate = new RTCIceCandidate(new RTCIceCandidateInit { candidate = msg.candidate, sdpMLineIndex = msg.label, sdpMid = msg.id }); peer.AddIceCandidate(candidate); }
public static string AsJSON(this RTCIceCandidate rtcICEcandidate) { return(JsonConvert.SerializeObject( new { type = "candidate", id = rtcICEcandidate.SdpMid, label = rtcICEcandidate.SdpMLineIndex, candidate = rtcICEcandidate.Sdp }, Formatting.Indented)); }
private void OnIceCandidate(RTCIceCandidate​ rtcCandidate) { // GetOtherPc(pc).AddIceCandidate(ref candidate); Debug.Log($"Local ICE candidate:\n {rtcCandidate.candidate}"); SendWsMessage("candidate", new JsonMessageData { room = roomName, label = rtcCandidate.sdpMLineIndex, id = rtcCandidate.sdpMid, candidate = rtcCandidate.candidate }); }
public void SendCandidate(string connectionId, RTCIceCandidate candidate) { CandidateData data = new CandidateData(); data.connectionId = connectionId; data.candidate = candidate.Candidate; data.sdpMLineIndex = candidate.SdpMLineIndex.GetValueOrDefault(0); data.sdpMid = candidate.SdpMid; HTTPPost("signaling/candidate", data); }
IEnumerator OnIceCandidate(string connectionId, RTCIceCandidate candidate) { var opCandidate = signaling.PostCandidate(sessionId, connectionId, candidate.candidate, candidate.sdpMid, candidate.sdpMLineIndex); yield return(opCandidate); if (opCandidate.webRequest.isNetworkError) { Debug.LogError($"Network Error: {opCandidate.webRequest.error}"); yield break; } }
public RTCIceCandidate toCand() { var candidateInfo = new RTCIceCandidateInit { candidate = candidate, sdpMid = sdpMid, sdpMLineIndex = sdpMLineIndex }; var cand = new RTCIceCandidate(candidateInfo); return(cand); }
private async Task QueueIceCandidate(RTCIceCandidate candidate) { await _iceBufferSemaphore.WaitAsync(); _bufferedIceCandidates.Add(candidate); if (_iceCandidateBufferTimer == null) { // Flush the ice candidates in 100ms. _iceCandidateBufferTimer = new Timer(FlushBufferedIceCandidates, null, 100, Timeout.Infinite); } _iceBufferSemaphore.Release(); }
public virtual async Task SendLocalIceCandidates(RTCIceCandidate[] candidates) { }
public override async Task SendLocalIceCandidates(RTCIceCandidate[] candidates) { Context.SendToPeer(RelayMessageTags.IceCandidate, JsonConvert.Serialize(candidates.ToDto())); }