public IEnumerator OnAddReceiverPublicMode() { MockSignaling.Reset(false); var dependencies1 = CreateDependencies(); var dependencies2 = CreateDependencies(); var target1 = new RenderStreamingInternal(ref dependencies1); var target2 = new RenderStreamingInternal(ref dependencies2); bool isStarted1 = false; bool isStarted2 = false; target1.onStart += () => { isStarted1 = true; }; target2.onStart += () => { isStarted2 = true; }; yield return(new WaitUntil(() => isStarted1 && isStarted2)); Assert.That(isStarted1, Is.True); Assert.That(isStarted2, Is.True); bool isCreatedConnection1 = false; bool isOnGotOffer2 = false; target1.onCreatedConnection += _ => { isCreatedConnection1 = true; }; target2.onGotOffer += (_, sdp) => { isOnGotOffer2 = true; }; var connectionId = "12345"; // target1 is Receiver in public mode target1.CreateConnection(connectionId); yield return(new WaitUntil(() => isCreatedConnection1)); Assert.That(isCreatedConnection1, Is.True); target1.AddTransceiver(connectionId, TrackKind.Video, RTCRtpTransceiverDirection.RecvOnly); // target2 is sender in private mode yield return(new WaitUntil(() => isOnGotOffer2)); Assert.That(isOnGotOffer2, Is.True); bool isAddReceiver1 = false; bool isGotAnswer1 = false; target1.onAddReceiver += (_, receiver) => { isAddReceiver1 = true; }; target1.onGotAnswer += (_, sdp) => { isGotAnswer1 = true; }; var camObj = new GameObject("Camera"); var camera = camObj.AddComponent <Camera>(); VideoStreamTrack track = camera.CaptureStreamTrack(1280, 720, 0); var transceiver2 = target2.AddTrack(connectionId, track); Assert.That(transceiver2.Direction, Is.EqualTo(RTCRtpTransceiverDirection.SendOnly)); target2.SendAnswer(connectionId); yield return(new WaitUntil(() => isAddReceiver1 & isGotAnswer1)); target1.DeleteConnection(connectionId); target2.DeleteConnection(connectionId); bool isDeletedConnection1 = false; bool isDeletedConnection2 = false; target1.onDeletedConnection += _ => { isDeletedConnection1 = true; }; target2.onDeletedConnection += _ => { isDeletedConnection2 = true; }; yield return(new WaitUntil(() => isDeletedConnection1 && isDeletedConnection2)); Assert.That(isDeletedConnection1, Is.True); Assert.That(isDeletedConnection2, Is.True); target1.Dispose(); target2.Dispose(); track.Dispose(); UnityEngine.Object.DestroyImmediate(camObj); }
public IEnumerator SwapTransceiverPrivateMode() { MockSignaling.Reset(true); var dependencies1 = CreateDependencies(); var dependencies2 = CreateDependencies(); var target1 = new RenderStreamingInternal(ref dependencies1); var target2 = new RenderStreamingInternal(ref dependencies2); bool isStarted1 = false; bool isStarted2 = false; target1.onStart += () => { isStarted1 = true; }; target2.onStart += () => { isStarted2 = true; }; yield return(new WaitUntil(() => isStarted1 && isStarted2)); bool isCreatedConnection1 = false; bool isCreatedConnection2 = false; target1.onCreatedConnection += _ => { isCreatedConnection1 = true; }; target2.onCreatedConnection += _ => { isCreatedConnection2 = true; }; var connectionId = "12345"; // target1 has impolite peer (request first) target1.CreateConnection(connectionId); yield return(new WaitUntil(() => isCreatedConnection1)); // target2 has polite peer (request second) target2.CreateConnection(connectionId); yield return(new WaitUntil(() => isCreatedConnection2)); bool isGotOffer1 = false; bool isGotOffer2 = false; bool isGotAnswer1 = false; target1.onGotOffer += (_, sdp) => { isGotOffer1 = true; }; target2.onGotOffer += (_, sdp) => { isGotOffer2 = true; }; target1.onGotAnswer += (_, sdp) => { isGotAnswer1 = true; }; target1.AddTransceiver(connectionId, TrackKind.Audio, RTCRtpTransceiverDirection.SendRecv); target2.AddTransceiver(connectionId, TrackKind.Audio, RTCRtpTransceiverDirection.SendRecv); // check each target invoke onGotOffer yield return(new WaitForSeconds(ResendOfferInterval * 5)); // ignore offer because impolite peer Assert.That(isGotOffer1, Is.False, $"{nameof(isGotOffer1)} is not False."); // accept offer because polite peer Assert.That(isGotOffer2, Is.True, $"{nameof(isGotOffer2)} is not True."); target2.SendAnswer(connectionId); yield return(new WaitUntil(() => isGotAnswer1)); Assert.That(isGotAnswer1, Is.True, $"{nameof(isGotAnswer1)} is not True."); target1.DeleteConnection(connectionId); target2.DeleteConnection(connectionId); bool isDeletedConnection1 = false; bool isDeletedConnection2 = false; target1.onDeletedConnection += _ => { isDeletedConnection1 = true; }; target2.onDeletedConnection += _ => { isDeletedConnection2 = true; }; yield return(new WaitUntil(() => isDeletedConnection1 && isDeletedConnection2)); Assert.That(isDeletedConnection1, Is.True, $"{nameof(isDeletedConnection1)} is not True."); Assert.That(isDeletedConnection2, Is.True, $"{nameof(isDeletedConnection1)} is not True."); target1.Dispose(); target2.Dispose(); }
public IEnumerator ReNegotiationAfterReceivingFirstOffer() { MockSignaling.Reset(true); var dependencies1 = CreateDependencies(); var dependencies2 = CreateDependencies(); var target1 = new RenderStreamingInternal(ref dependencies1); var target2 = new RenderStreamingInternal(ref dependencies2); bool isStarted1 = false; bool isStarted2 = false; target1.onStart += () => { isStarted1 = true; }; target2.onStart += () => { isStarted2 = true; }; yield return(new WaitUntil(() => isStarted1 && isStarted2)); bool isCreatedConnection1 = false; bool isCreatedConnection2 = false; target1.onCreatedConnection += _ => { isCreatedConnection1 = true; }; target2.onCreatedConnection += _ => { isCreatedConnection2 = true; }; var connectionId = "12345"; // target1 has impolite peer (request first) target1.CreateConnection(connectionId); yield return(new WaitUntil(() => isCreatedConnection1)); // target2 has polite peer (request second) target2.CreateConnection(connectionId); yield return(new WaitUntil(() => isCreatedConnection2)); bool isGotOffer1 = false; bool isGotOffer2 = false; bool isGotAnswer1 = false; bool isGotAnswer2 = false; target1.onGotOffer += (_, sdp) => { isGotOffer1 = true; }; target2.onGotOffer += (_, sdp) => { isGotOffer2 = true; }; target1.onGotAnswer += (_, sdp) => { isGotAnswer1 = true; }; target2.onGotAnswer += (_, sdp) => { isGotAnswer2 = true; }; target1.AddTransceiver(connectionId, TrackKind.Video, RTCRtpTransceiverDirection.SendOnly); target1.AddTransceiver(connectionId, TrackKind.Video, RTCRtpTransceiverDirection.RecvOnly); target2.AddTransceiver(connectionId, TrackKind.Video, RTCRtpTransceiverDirection.SendOnly); target2.AddTransceiver(connectionId, TrackKind.Video, RTCRtpTransceiverDirection.RecvOnly); yield return(new WaitUntil(() => isGotOffer2)); Assert.That(isGotOffer2, Is.True, $"{nameof(isGotOffer2)} is not True."); target2.SendAnswer(connectionId); yield return(new WaitUntil(() => isGotAnswer1)); Assert.That(isGotAnswer1, Is.True, $"{nameof(isGotAnswer1)} is not True."); yield return(new WaitUntil(() => isGotOffer1)); Assert.That(isGotOffer1, Is.True, $"{nameof(isGotOffer1)} is not True."); target1.SendAnswer(connectionId); yield return(new WaitUntil(() => isGotAnswer2)); Assert.That(isGotAnswer2, Is.True, $"{nameof(isGotAnswer2)} is not True."); target1.DeleteConnection(connectionId); target2.DeleteConnection(connectionId); bool isDeletedConnection1 = false; bool isDeletedConnection2 = false; target1.onDeletedConnection += _ => { isDeletedConnection1 = true; }; target2.onDeletedConnection += _ => { isDeletedConnection2 = true; }; yield return(new WaitUntil(() => isDeletedConnection1 && isDeletedConnection2)); Assert.That(isDeletedConnection1, Is.True, $"{nameof(isDeletedConnection1)} is not True."); Assert.That(isDeletedConnection2, Is.True, $"{nameof(isDeletedConnection1)} is not True."); target1.Dispose(); target2.Dispose(); }