def set_up_components(): global cam, conn cam = cameras.MicroCamera( type="remote_usb") # !!! CHANGE FOR CUSTOM CAMERA OBJ conn = RTCConnection() conn.video.putSubscription(cam) conn.subscribe(onMessage)
async def test_basic(self): """ Creates a connection, and ensures that multiple messages go through in both directions. """ testmsg1 = "Testy mc test-test" testmsg2 = "Hai wrld" c1 = RTCConnection() c2 = RTCConnection() q1 = c1.subscribe() q2 = c2.subscribe() offer = await c1.getLocalDescription() response = await c2.getLocalDescription(offer) await c1.setRemoteDescription(response) c1.put_nowait(testmsg1) c2.put_nowait(testmsg2) c1.send("OMG") # Just to check c2.put_nowait("OMG2") msg1 = await asyncio.wait_for(q1.get(), 5) msg2 = await asyncio.wait_for(q2.get(), 5) self.assertEqual(msg1, testmsg2) self.assertEqual(msg2, testmsg1) msg1 = await asyncio.wait_for(q1.get(), 5) msg2 = await asyncio.wait_for(q2.get(), 5) self.assertEqual(msg1, "OMG2") self.assertEqual(msg2, "OMG") await c1.close() await c2.close()
async def registerOnServerAndAwaitRtcConnections(): print("sending /registerRobot") ws = Websocket(REMOTE_WEB_SERVER + '/registerRobot') while True: remoteDescription = await ws.get() print("{:%Y-%m-%d %H:%M:%S}: new web user requested connect".format(datetime.datetime.now())) connection = RTCConnection() connection.video.putSubscription(videoFrameSubscription) connection.subscribe(onMessage) connection.putSubscription(cv2ColorSubscription) connection.put_nowait({ "action": "hsv", "hsv": hsv }) @connection.onClose def close(): print("{:%Y-%m-%d %H:%M:%S}: Connection Closed".format(datetime.datetime.now())) connections.remove(connection) connections.append(connection) robotDescription = await connection.getLocalDescription(remoteDescription) ws.put_nowait(robotDescription)