示例#1
0
        public IEnumerator AddTrackThrowException(TestMode mode)
        {
            MockSignaling.Reset(mode == TestMode.PrivateMode);

            var dependencies = CreateDependencies();
            var target       = new RenderStreamingInternal(ref dependencies);

            bool isStarted = false;

            target.onStart += () => { isStarted = true; };
            yield return(new WaitUntil(() => isStarted));

            var connectionId = "12345";

            target.CreateConnection(connectionId);
            bool isCreatedConnection = false;

            target.onCreatedConnection += _ => { isCreatedConnection = true; };
            yield return(new WaitUntil(() => isCreatedConnection));

            Assert.That(() => target.AddTrack(null, null), Throws.TypeOf <ArgumentNullException>());
            Assert.That(() => target.AddTrack(connectionId, null), Throws.TypeOf <ArgumentNullException>());
            Assert.That(() => target.RemoveTrack(null, null), Throws.TypeOf <ArgumentNullException>());
            Assert.That(() => target.RemoveTrack(connectionId, null), Throws.TypeOf <InvalidOperationException>());
            target.DeleteConnection(connectionId);
            bool isDeletedConnection = false;

            target.onDeletedConnection += _ => { isDeletedConnection = true; };
            yield return(new WaitUntil(() => isDeletedConnection));

            target.Dispose();
        }
示例#2
0
        public IEnumerator AddTrackMultiple(TestMode mode)
        {
            MockSignaling.Reset(mode == TestMode.PrivateMode);

            var dependencies = CreateDependencies();
            var target       = new RenderStreamingInternal(ref dependencies);

            bool isStarted = false;

            target.onStart += () => { isStarted = true; };
            yield return(new WaitUntil(() => isStarted));

            Assert.That(isStarted, Is.True);

            var connectionId = "12345";

            target.CreateConnection(connectionId);
            bool isCreatedConnection = false;

            target.onCreatedConnection += _ => { isCreatedConnection = true; };
            yield return(new WaitUntil(() => isCreatedConnection));

            Assert.That(isCreatedConnection, Is.True);

            var camObj             = new GameObject("Camera");
            var camera             = camObj.AddComponent <Camera>();
            VideoStreamTrack track = camera.CaptureStreamTrack(1280, 720, 0);
            var transceiver1       = target.AddTrack(connectionId, track);

            Assert.That(transceiver1.Direction, Is.EqualTo(RTCRtpTransceiverDirection.SendOnly));

            var camObj2             = new GameObject("Camera2");
            var camera2             = camObj2.AddComponent <Camera>();
            VideoStreamTrack track2 = camera2.CaptureStreamTrack(1280, 720, 0);
            var transceiver2        = target.AddTrack(connectionId, track2);

            Assert.That(transceiver2.Direction, Is.EqualTo(RTCRtpTransceiverDirection.SendOnly));

            target.DeleteConnection(connectionId);
            bool isDeletedConnection = false;

            target.onDeletedConnection += _ => { isDeletedConnection = true; };
            yield return(new WaitUntil(() => isDeletedConnection));

            Assert.That(isDeletedConnection, Is.True);

            target.Dispose();
            track.Dispose();
            track2.Dispose();
            UnityEngine.Object.Destroy(camObj);
            UnityEngine.Object.Destroy(camObj2);
        }
示例#3
0
        public IEnumerator AddTrack(TestMode mode)
        {
            MockSignaling.Reset(mode == TestMode.PrivateMode);

            var dependencies = CreateDependencies();
            var target       = new RenderStreamingInternal(ref dependencies);

            bool isStarted = false;

            target.onStart += () => { isStarted = true; };
            yield return(new WaitUntil(() => isStarted));

            var  connectionId        = "12345";
            bool isCreatedConnection = false;

            target.onCreatedConnection += _ => { isCreatedConnection = true; };
            target.CreateConnection(connectionId);
            yield return(new WaitUntil(() => isCreatedConnection));

            var camObj             = new GameObject("Camera");
            var camera             = camObj.AddComponent <Camera>();
            VideoStreamTrack track = camera.CaptureStreamTrack(1280, 720, 0);

            target.AddTrack(connectionId, track);
            target.RemoveTrack(connectionId, track);

            bool isDeletedConnection = false;

            target.onDeletedConnection += _ => { isDeletedConnection = true; };
            target.DeleteConnection(connectionId);
            yield return(new WaitUntil(() => isDeletedConnection));

            target.Dispose();
            track.Dispose();
            UnityEngine.Object.Destroy(camObj);
        }
示例#4
0
        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);
        }
示例#5
0
        public IEnumerator OnAddReceiverPrivateMode()
        {
            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));

            Assert.That(isStarted1, Is.True);
            Assert.That(isStarted2, Is.True);

            bool isCreatedConnection1 = false;
            bool isCreatedConnection2 = false;

            target1.onCreatedConnection += _ => { isCreatedConnection1 = true; };
            target2.onFoundConnection   += _ => { isCreatedConnection2 = true; };

            var connectionId = "12345";

            // target1 is Receiver in private mode
            target1.CreateConnection(connectionId);
            yield return(new WaitUntil(() => isCreatedConnection1));

            Assert.That(isCreatedConnection1, Is.True);

            // target2 is sender in private mode
            target2.CreateConnection(connectionId);
            yield return(new WaitUntil(() => isCreatedConnection2));

            Assert.That(isCreatedConnection2, Is.True);

            bool isAddReceiver1 = false;
            bool isGotAnswer2   = false;

            target1.onAddReceiver += (_, receiver) => { isAddReceiver1 = true; };
            target1.onGotOffer    += (_, sdp) => { target1.SendAnswer(connectionId); };
            target2.onGotAnswer   += (_, sdp) => { isGotAnswer2 = true; };

            var camObj             = new GameObject("Camera");
            var camera             = camObj.AddComponent <Camera>();
            VideoStreamTrack track = camera.CaptureStreamTrack(1280, 720, 0);

            // send offer automatically after adding a Track
            var transceiver = target2.AddTrack(connectionId, track);

            Assert.That(transceiver, Is.Not.Null);

            yield return(new WaitUntil(() => isAddReceiver1 && isGotAnswer2));

            Assert.That(isAddReceiver1, Is.True);
            Assert.That(isGotAnswer2, Is.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);
            Assert.That(isDeletedConnection2, Is.True);

            target1.Dispose();
            target2.Dispose();
            track.Dispose();
            UnityEngine.Object.Destroy(camObj);
        }