How to use the aiortc.RTCSessionDescription function in aiortc

To help you get started, we’ve selected a few aiortc examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github aiortc / aiortc / tests / test_rtcpeerconnection.py View on Github external
def strip_ice_candidates(description):
    return RTCSessionDescription(
        sdp=STRIP_CANDIDATES_RE.sub('', description.sdp),
        type=description.type)
github aiortc / aiortc / tests / test_rtcpeerconnection.py View on Github external
def test_setRemoteDescription_without_rtcp_mux(self):
        pc1 = RTCPeerConnection()
        pc2 = RTCPeerConnection()

        pc1.addTrack(AudioStreamTrack())
        offer = run(pc1.createOffer())
        run(pc1.setLocalDescription(offer))

        mangled = RTCSessionDescription(
            sdp=re.sub('^a=rtcp-mux\r\n', '', pc1.localDescription.sdp, flags=re.M),
            type=pc1.localDescription.type)
        with self.assertRaises(ValueError) as cm:
            run(pc2.setRemoteDescription(mangled))
        self.assertEqual(str(cm.exception), 'RTCP mux is not enabled')
github aiortc / aiortc / tests / test_rtcsessiondescription.py View on Github external
def test_bad_type(self):
        with self.assertRaises(ValueError) as cm:
            RTCSessionDescription(sdp="v=0\r\n", type="bogus")
        self.assertEqual(
            str(cm.exception),
            "'type' must be in ['offer', 'pranswer', 'answer', 'rollback'] (got 'bogus')",
        )
github aiortc / aiortc / tests / test_rtcpeerconnection.py View on Github external
def test_setRemoteDescription_unexpected_answer(self):
        pc = RTCPeerConnection()
        with self.assertRaises(InvalidStateError) as cm:
            run(pc.setRemoteDescription(RTCSessionDescription(sdp='', type='answer')))
        self.assertEqual(str(cm.exception), 'Cannot handle answer in signaling state "stable"')
github aiortc / aiortc / src / aiortc / contrib / signaling.py View on Github external
def object_from_string(message_str):
    message = json.loads(message_str)
    if message["type"] in ["answer", "offer"]:
        return RTCSessionDescription(**message)
    elif message["type"] == "candidate":
        candidate = candidate_from_sdp(message["candidate"].split(":", 1)[1])
        candidate.sdpMid = message["id"]
        candidate.sdpMLineIndex = message["label"]
        return candidate
github aiortc / aiortc / examples / apprtc / apprtc.py View on Github external
recorder.addTrack(track)

    # connect to websocket and join
    params = await signaling.connect()

    if params["is_initiator"] == "true":
        # send offer
        add_tracks()
        await pc.setLocalDescription(await pc.createOffer())
        await signaling.send(pc.localDescription)

    # consume signaling
    while True:
        obj = await signaling.receive()

        if isinstance(obj, RTCSessionDescription):
            await pc.setRemoteDescription(obj)
            await recorder.start()

            if obj.type == "offer":
                # send answer
                add_tracks()
                await pc.setLocalDescription(await pc.createAnswer())
                await signaling.send(pc.localDescription)
        elif isinstance(obj, RTCIceCandidate):
            pc.addIceCandidate(obj)
        elif obj is None:
            print("Exiting")
            break
github vudung45 / FaceRTC / backend / demo_backend.py View on Github external
async def offer(request):
    params = await request.json()
    print(params);
    offer = RTCSessionDescription(sdp=params["sdp"], type=params["type"])

    pc = RTCPeerConnection()
    client_id = client_manager.create_new_client(pc)
   # data = [True]
   #recog_worker_thread = threading.Thread(target=recog_worker,args=(client_manager.get_client(client_id),data,))
    #recog_worker_thread.start()


    @pc.on("iceconnectionstatechange")
    async def on_iceconnectionstatechange():
        print("ICE connection state is %s" % pc.iceConnectionState)
        if pc.iceConnectionState == "failed":
            await client_manager.remove_client(client_id) #this already handles pc closing

    faceregtrack = FacialRecognitionTrack(face_detect, client_manager.get_client(client_id));
github balena-io-projects / balena-cam / balena-cam / app / server.py View on Github external
async def offer(request):
    params = await request.json()
    offer = RTCSessionDescription(
        sdp=params['sdp'],
        type=params['type'])
    pc = pc_factory.create_peer_connection()
    pcs.add(pc)
    # Add local media
    local_video = RTCVideoStream(camera_device)
    pc.addTrack(local_video)
    @pc.on('iceconnectionstatechange')
    async def on_iceconnectionstatechange():
        if pc.iceConnectionState == 'failed':
            await pc.close()
            pcs.discard(pc)
    await pc.setRemoteDescription(offer)
    answer = await pc.createAnswer()
    await pc.setLocalDescription(answer)
    return web.Response(
github aiortc / aiortc / src / aiortc / contrib / signaling.py View on Github external
def object_to_string(obj):
    if isinstance(obj, RTCSessionDescription):
        message = {"sdp": obj.sdp, "type": obj.type}
    elif isinstance(obj, RTCIceCandidate):
        message = {
            "candidate": "candidate:" + candidate_to_sdp(obj),
            "id": obj.sdpMid,
            "label": obj.sdpMLineIndex,
            "type": "candidate",
        }
    else:
        message = {"type": "bye"}
    return json.dumps(message, sort_keys=True)