public IEnumerator OnOffer() { bool startRaised1 = false; bool startRaised2 = false; bool offerRaised = false; bool raiseOnDestroy1 = false; bool raiseOnDestroy2 = false; string connectionId1 = null; string connectionId2 = null; const string _connectionId = "12345"; signaling1.OnStart += s => { startRaised1 = true; }; signaling2.OnStart += s => { startRaised2 = true; }; signaling1.Start(); signaling2.Start(); yield return(new WaitUntil(() => startRaised1 && startRaised2)); signaling1.OnCreateConnection += (s, connectionId, polite) => { connectionId1 = connectionId; }; signaling1.OnDestroyConnection += (signaling, id) => { raiseOnDestroy1 = id == connectionId1; }; signaling1.OpenConnection(_connectionId); signaling2.OnCreateConnection += (s, connectionId, polite) => { connectionId2 = connectionId; }; signaling1.OnDestroyConnection += (signaling, id) => { raiseOnDestroy2 = id == connectionId2; }; signaling2.OpenConnection(_connectionId); yield return(new WaitUntil(() => !string.IsNullOrEmpty(connectionId1) && !string.IsNullOrEmpty(connectionId2))); Assert.That(connectionId1, Is.EqualTo(_connectionId)); Assert.That(connectionId2, Is.EqualTo(_connectionId)); signaling2.OnOffer += (s, e) => { offerRaised = true; }; signaling1.SendOffer(connectionId1, m_DescOffer); yield return(new WaitUntil(() => offerRaised)); signaling1.CloseConnection(connectionId1); yield return(new WaitUntil(() => raiseOnDestroy1 && raiseOnDestroy2)); Assert.That(raiseOnDestroy1, Is.True); Assert.That(raiseOnDestroy2, Is.True); }
IEnumerator SendOfferCoroutine(string connectionId, RTCPeerConnection pc) { RTCOfferOptions option = new RTCOfferOptions { offerToReceiveAudio = true, offerToReceiveVideo = true }; var offerOp = pc.CreateOffer(ref option); yield return(offerOp); if (offerOp.IsError) { Debug.LogError($"Network Error: {offerOp.Error.message}"); yield break; } if (pc.SignalingState != RTCSignalingState.Stable) { Debug.LogError($"peerConnection's signaling state is not stable. {pc.SignalingState}"); yield break; } var desc = offerOp.Desc; var setLocalSdp = pc.SetLocalDescription(ref desc); yield return(setLocalSdp); if (setLocalSdp.IsError) { Debug.LogError($"Network Error: {setLocalSdp.Error.message}"); yield break; } _signaling.SendOffer(connectionId, desc); }
/// <summary> /// /// </summary> /// <param name="connectionId"></param> public void SendOffer(string connectionId) { var pc = _mapConnectionIdAndPeer[connectionId]; if (!IsStable(connectionId)) { if (!pc.waitingAnswer) { throw new InvalidOperationException( $"{pc} sendoffer needs in stable state, current state is {pc.peer.SignalingState}"); } _signaling.SendOffer(connectionId, pc.peer.LocalDescription); return; } _startCoroutine(SendOfferCoroutine(connectionId, pc)); }
public IEnumerator OnOffer() { bool startRaised1 = false; bool startRaised2 = false; bool offerRaised2 = false; const string connectionId = "12345"; string connectionId1 = null; string connectionId2 = null; signaling1.OnStart += s => { startRaised1 = true; }; signaling2.OnStart += s => { startRaised2 = true; }; signaling1.Start(); signaling2.Start(); yield return(new WaitUntil(() => startRaised1 && startRaised2)); signaling1.OnCreateConnection += (s, id, peerExists) => { connectionId1 = id; }; signaling1.OpenConnection(connectionId); yield return(new WaitUntil(() => !string.IsNullOrEmpty(connectionId1))); signaling2.OnOffer += (s, e) => { offerRaised2 = true; }; LogAssert.Expect(LogType.Error, new Regex(".")); signaling1.SendOffer(connectionId, m_DescOffer); yield return(new WaitForSeconds(5)); // Do not receive offer other signaling if not connected same sendoffer connectionId in private mode Assert.IsFalse(offerRaised2); signaling2.OnCreateConnection += (s, id, peerExists) => { connectionId2 = id; }; signaling2.OpenConnection(connectionId); yield return(new WaitUntil(() => !string.IsNullOrEmpty(connectionId2))); Assert.That(connectionId1, Is.EqualTo(connectionId)); Assert.That(connectionId2, Is.EqualTo(connectionId)); signaling1.SendOffer(connectionId, m_DescOffer); yield return(new WaitUntil(() => offerRaised2)); signaling1.CloseConnection(connectionId1); signaling2.CloseConnection(connectionId2); signaling1.Stop(); signaling2.Stop(); yield return(new WaitForSeconds(1)); }
public IEnumerator OnOffer() { bool startRaised1 = false; bool startRaised2 = false; bool offerRaised = false; string connectionId1 = null; signaling1.OnStart += s => { startRaised1 = true; }; signaling2.OnStart += s => { startRaised2 = true; }; signaling1.Start(); signaling2.Start(); yield return(new WaitUntil(() => startRaised1 && startRaised2)); signaling1.OnCreateConnection += (s, connectionId) => { connectionId1 = connectionId; }; signaling1.CreateConnection(); yield return(new WaitUntil(() => !string.IsNullOrEmpty(connectionId1))); signaling2.OnOffer += (s, e) => { offerRaised = true; }; signaling1.SendOffer(connectionId1, m_DescOffer); yield return(new WaitUntil(() => offerRaised)); }
public void OnOffer() { bool startRaised1 = false; bool startRaised2 = false; bool offerRaised = false; string connectionId1 = null; signaling1.Start(); signaling2.Start(); signaling1.OnStart += s => { startRaised1 = true; }; signaling2.OnStart += s => { startRaised2 = true; }; Assert.True(Wait(() => startRaised1 && startRaised2)); signaling1.OnCreateConnection += (s, connectionId) => { connectionId1 = connectionId; }; signaling1.CreateConnection(); Assert.True(Wait(() => !string.IsNullOrEmpty(connectionId1))); signaling2.OnOffer += (s, e) => { offerRaised = true; }; signaling1.SendOffer(connectionId1, m_DescOffer); Assert.True(Wait(() => offerRaised)); }
public IEnumerator OnOffer() { bool startRaised1 = false; bool startRaised2 = false; bool offerRaised = false; bool peerExists1 = false; bool peerExists2 = false; string connectionId1 = null; string connectionId2 = null; const string _connectionId = "12345"; signaling1.OnStart += s => { startRaised1 = true; }; signaling2.OnStart += s => { startRaised2 = true; }; signaling1.Start(); signaling2.Start(); yield return(new WaitUntil(() => startRaised1 && startRaised2)); signaling1.OnCreateConnection += (s, connectionId, peerExists) => { connectionId1 = connectionId; peerExists1 = peerExists; }; signaling1.OpenConnection(_connectionId); signaling2.OnCreateConnection += (s, connectionId, peerExists) => { connectionId2 = connectionId; peerExists2 = peerExists; }; signaling2.OpenConnection(_connectionId); yield return(new WaitUntil(() => !string.IsNullOrEmpty(connectionId1) && !string.IsNullOrEmpty(connectionId2))); Assert.That(connectionId1, Is.EqualTo(_connectionId)); Assert.That(connectionId2, Is.EqualTo(_connectionId)); Assert.That(peerExists1, Is.False); Assert.That(peerExists2, Is.False); signaling2.OnOffer += (s, e) => { offerRaised = true; }; signaling1.SendOffer(connectionId1, m_DescOffer); yield return(new WaitUntil(() => offerRaised)); }
IEnumerator OnNegotiationNeeded(ISignaling signaling, string connectionId, bool isOffer) { if (!isOffer) { yield break; } if (!m_mapConnectionIdAndPeer.TryGetValue(connectionId, out var pc)) { Debug.LogError($"connectionId: {connectionId}, did not created peerConnection"); yield break; } RTCOfferOptions option = new RTCOfferOptions { offerToReceiveAudio = true, offerToReceiveVideo = true }; var offerOp = pc.CreateOffer(ref option); yield return(offerOp); if (offerOp.IsError) { Debug.LogError($"Network Error: {offerOp.Error.message}"); yield break; } if (pc.SignalingState != RTCSignalingState.Stable) { Debug.LogError($"peerConnection's signaling state is not stable."); yield break; } var desc = offerOp.Desc; var setLocalSdp = pc.SetLocalDescription(ref desc); yield return(setLocalSdp); if (setLocalSdp.IsError) { Debug.LogError($"Network Error: {setLocalSdp.Error.message}"); yield break; } signaling.SendOffer(connectionId, desc); }
public IEnumerator OnOffer() { bool startRaised1 = false; bool startRaised2 = false; bool offerRaised2 = false; const string connectionId = "12345"; bool raiseOnDestroy1 = false; bool raiseOnDestroy2 = false; string connectionId1 = null; string connectionId2 = null; signaling1.OnStart += s => { startRaised1 = true; }; signaling2.OnStart += s => { startRaised2 = true; }; signaling1.Start(); signaling2.Start(); yield return(new WaitUntil(() => startRaised1 && startRaised2)); signaling1.OnCreateConnection += (s, id, polite) => { connectionId1 = id; }; signaling1.OnDestroyConnection += (signaling, id) => { raiseOnDestroy1 = id == connectionId1; }; signaling1.OpenConnection(connectionId); yield return(new WaitUntil(() => !string.IsNullOrEmpty(connectionId1))); signaling2.OnOffer += (s, e) => { offerRaised2 = true; }; signaling1.SendOffer(connectionId, m_DescOffer); yield return(new WaitForSeconds(3)); // Do not receive offer other signaling if not connected same sendoffer connectionId in private mode Assert.IsFalse(offerRaised2); signaling2.OnCreateConnection += (s, id, polite) => { connectionId2 = id; }; signaling2.OnDestroyConnection += (signaling, id) => { raiseOnDestroy2 = id == connectionId2; }; signaling2.OpenConnection(connectionId); yield return(new WaitUntil(() => !string.IsNullOrEmpty(connectionId2))); Assert.That(connectionId1, Is.EqualTo(connectionId)); Assert.That(connectionId2, Is.EqualTo(connectionId)); signaling1.SendOffer(connectionId, m_DescOffer); yield return(new WaitUntil(() => offerRaised2)); signaling1.CloseConnection(connectionId1); yield return(new WaitUntil(() => raiseOnDestroy1 && raiseOnDestroy2)); Assert.That(raiseOnDestroy1, Is.True); Assert.That(raiseOnDestroy2, Is.True); signaling2.CloseConnection(connectionId2); signaling1.Stop(); signaling2.Stop(); yield return(new WaitForSeconds(1)); }