示例#1
0
    def test_connect_fail(self):
        gatherer_1 = RTCIceGatherer()
        transport_1 = RTCIceTransport(gatherer_1)

        gatherer_2 = RTCIceGatherer()
        transport_2 = RTCIceTransport(gatherer_2)

        # gather candidates
        run(asyncio.gather(gatherer_1.gather(), gatherer_2.gather()))
        for candidate in gatherer_2.getLocalCandidates():
            run(transport_1.addRemoteCandidate(candidate))
        for candidate in gatherer_1.getLocalCandidates():
            run(transport_2.addRemoteCandidate(candidate))
        self.assertEqual(transport_1.state, "new")
        self.assertEqual(transport_2.state, "new")

        # connect
        run(transport_2.stop())
        run(transport_1.start(gatherer_2.getLocalParameters()))
        self.assertEqual(transport_1.state, "failed")
        self.assertEqual(transport_2.state, "closed")

        # cleanup
        run(asyncio.gather(transport_1.stop(), transport_2.stop()))
        self.assertEqual(transport_1.state, "closed")
        self.assertEqual(transport_2.state, "closed")
    def test_connect(self):
        gatherer_1 = RTCIceGatherer()
        transport_1 = RTCIceTransport(gatherer_1)

        gatherer_2 = RTCIceGatherer()
        transport_2 = RTCIceTransport(gatherer_2)

        # gather candidates
        run(asyncio.gather(gatherer_1.gather(), gatherer_2.gather()))
        for candidate in gatherer_2.getLocalCandidates():
            transport_1.addRemoteCandidate(candidate)
        for candidate in gatherer_1.getLocalCandidates():
            transport_2.addRemoteCandidate(candidate)
        self.assertEqual(transport_1.state, 'new')
        self.assertEqual(transport_2.state, 'new')

        # connect
        run(
            asyncio.gather(transport_1.start(gatherer_2.getLocalParameters()),
                           transport_2.start(gatherer_1.getLocalParameters())))
        self.assertEqual(transport_1.state, 'completed')
        self.assertEqual(transport_2.state, 'completed')

        # cleanup
        run(asyncio.gather(transport_1.stop(), transport_2.stop()))
        self.assertEqual(transport_1.state, 'closed')
        self.assertEqual(transport_2.state, 'closed')
示例#3
0
    async def test_connect(self):
        gatherer_1 = RTCIceGatherer()
        transport_1 = RTCIceTransport(gatherer_1)

        gatherer_2 = RTCIceGatherer()
        transport_2 = RTCIceTransport(gatherer_2)

        # gather candidates
        await asyncio.gather(gatherer_1.gather(), gatherer_2.gather())
        for candidate in gatherer_2.getLocalCandidates():
            await transport_1.addRemoteCandidate(candidate)
        for candidate in gatherer_1.getLocalCandidates():
            await transport_2.addRemoteCandidate(candidate)
        self.assertEqual(transport_1.state, "new")
        self.assertEqual(transport_2.state, "new")

        # connect
        await asyncio.gather(
            transport_1.start(gatherer_2.getLocalParameters()),
            transport_2.start(gatherer_1.getLocalParameters()),
        )
        self.assertEqual(transport_1.state, "completed")
        self.assertEqual(transport_2.state, "completed")

        # cleanup
        await asyncio.gather(transport_1.stop(), transport_2.stop())
        self.assertEqual(transport_1.state, "closed")
        self.assertEqual(transport_2.state, "closed")
 def test_gather(self):
     gatherer = RTCIceGatherer()
     self.assertEqual(gatherer.state, "new")
     self.assertEqual(gatherer.getLocalCandidates(), [])
     run(gatherer.gather())
     self.assertEqual(gatherer.state, "completed")
     self.assertTrue(len(gatherer.getLocalCandidates()) > 0)
示例#5
0
    async def test_gather(self):
        gatherer = RTCIceGatherer()
        self.assertEqual(gatherer.state, "new")
        self.assertEqual(gatherer.getLocalCandidates(), [])
        await gatherer.gather()
        self.assertEqual(gatherer.state, "completed")
        self.assertTrue(len(gatherer.getLocalCandidates()) > 0)

        # close
        await gatherer._connection.close()
示例#6
0
    def test_connect_when_closed(self):
        gatherer = RTCIceGatherer()
        transport = RTCIceTransport(gatherer)

        # stop transport
        run(transport.stop())
        self.assertEqual(transport.state, "closed")

        # try to start it
        with self.assertRaises(InvalidStateError) as cm:
            run(
                transport.start(
                    RTCIceParameters(usernameFragment="foo", password="******")))
        self.assertEqual(str(cm.exception), "RTCIceTransport is closed")
示例#7
0
    def test_send_connection_error(self):
        gatherer = RTCIceGatherer()
        transport = RTCIceTransport(gatherer)
        self.assertEqual(transport.state, "new")

        # fake connection
        gatherer._connection.connect = noop
        run(
            transport.start(
                RTCIceParameters(usernameFragment="foo", password="******")))
        self.assertEqual(transport.state, "completed")

        with self.assertRaises(ConnectionError):
            run(transport._send(b"foo"))
        self.assertEqual(transport.state, "failed")
    def test_send_connection_error(self):
        gatherer = RTCIceGatherer()
        transport = RTCIceTransport(gatherer)
        self.assertEqual(transport.state, 'new')

        # fake connection
        gatherer._connection.connect = noop
        run(
            transport.start(
                RTCIceParameters(usernameFragment='foo', password='******')))
        self.assertEqual(transport.state, 'completed')

        with self.assertRaises(ConnectionError):
            run(transport._send(b'foo'))
        self.assertEqual(transport.state, 'failed')
示例#9
0
    async def test_connection_closed(self):
        gatherer = RTCIceGatherer()

        # mock out methods
        gatherer._connection.connect = mock_connect
        gatherer._connection.get_event = mock_get_event

        transport = RTCIceTransport(gatherer)
        self.assertEqual(transport.state, "new")

        await transport.start(RTCIceParameters(usernameFragment="foo", password="******"))
        self.assertEqual(transport.state, "completed")

        await asyncio.sleep(1)
        self.assertEqual(transport.state, "failed")

        await transport.stop()
        self.assertEqual(transport.state, "closed")
示例#10
0
    def test_construct(self):
        gatherer = RTCIceGatherer()
        connection = RTCIceTransport(gatherer)
        self.assertEqual(connection.state, 'new')
        self.assertEqual(connection.getRemoteCandidates(), [])

        candidate = RTCIceCandidate(component=1,
                                    foundation='0',
                                    ip='192.168.99.7',
                                    port=33543,
                                    priority=2122252543,
                                    protocol='UDP',
                                    type='host')

        # add candidate
        connection.addRemoteCandidate(candidate)
        self.assertEqual(connection.getRemoteCandidates(), [candidate])

        # end-of-candidates
        connection.addRemoteCandidate(None)
        self.assertEqual(connection.getRemoteCandidates(), [candidate])
示例#11
0
    def test_construct(self):
        gatherer = RTCIceGatherer()
        connection = RTCIceTransport(gatherer)
        self.assertEqual(connection.state, "new")
        self.assertEqual(connection.getRemoteCandidates(), [])

        candidate = RTCIceCandidate(
            component=1,
            foundation="0",
            ip="192.168.99.7",
            port=33543,
            priority=2122252543,
            protocol="UDP",
            type="host",
        )

        # add candidate
        run(connection.addRemoteCandidate(candidate))
        self.assertEqual(connection.getRemoteCandidates(), [candidate])

        # end-of-candidates
        run(connection.addRemoteCandidate(None))
        self.assertEqual(connection.getRemoteCandidates(), [candidate])
示例#12
0
 def test_construct(self):
     gatherer = RTCIceGatherer()
     self.assertEqual(gatherer.state, 'new')
     self.assertEqual(gatherer.getLocalCandidates(), [])
     run(gatherer.gather())
     self.assertTrue(len(gatherer.getLocalCandidates()) > 0)