Skip to content

Commit

Permalink
[NOT WORKING] Copy and fix lines of code procesing an offer from aior…
Browse files Browse the repository at this point in the history
…tc/aiortc/examples/server.py to __init__.py (and set up a logger)
  • Loading branch information
whitphx committed Jan 24, 2021
1 parent 7b7dd2d commit 92416e6
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions tiny_streamlit_webrtc/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import logging
import os
import streamlit.components.v1 as components
from aiortc import RTCPeerConnection, RTCSessionDescription

logger = logging.getLogger(__name__)

_RELEASE = False

Expand All @@ -23,6 +27,29 @@ def tiny_streamlit_webrtc(key=None):
# Debug
st.write(offer_json)

offer = RTCSessionDescription(sdp=offer_json["sdp"], type=offer_json["type"])

pc = RTCPeerConnection()

@pc.on("track")
def on_track(track):
logger.info("Track %s received", track.kind)
pc.addTrack(track) # Passthrough. TODO: Implement video transformation

# TODO: `await` does not work in a function. It must be used inside a coroutine.
# handle offer
await pc.setRemoteDescription(offer)

# send answer
answer = await pc.createAnswer()
await pc.setLocalDescription(answer)

# TODO: How to send back the answer to frontend?
# answer_json = json.dumps(
# {"sdp": pc.localDescription.sdp, "type": pc.localDescription.type}
# )


return component_value


Expand Down

0 comments on commit 92416e6

Please sign in to comment.