From 77436dea052af355b22f9eab62a3b36603a15e32 Mon Sep 17 00:00:00 2001 From: Marks Polakovs Date: Fri, 24 Apr 2020 12:22:37 +0200 Subject: [PATCH] Tell shittyserver about TURN as well Not sure it needs it but... --- shittyserver.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/shittyserver.py b/shittyserver.py index 15834da..373c0dc 100644 --- a/shittyserver.py +++ b/shittyserver.py @@ -13,7 +13,7 @@ import aiohttp import av # type: ignore import jack as Jack # type: ignore import websockets -from aiortc import MediaStreamTrack, RTCPeerConnection, RTCSessionDescription # type: ignore +from aiortc import MediaStreamTrack, RTCPeerConnection, RTCConfiguration, RTCSessionDescription # type: ignore from aiortc.mediastreams import MediaStreamError # type: ignore from raygun4py import raygunprovider # type: ignore @@ -161,6 +161,7 @@ class Session(object): running: bool ended: bool resampler: Optional[Any] + ice_servers: Optional[TurnCredentials] def __init__(self) -> None: self.websocket = None @@ -173,6 +174,7 @@ class Session(object): self.lock = asyncio.Lock() self.running = False self.connected_at = datetime.now(timezone.utc) + self.ice_servers = None def to_dict(self) -> Dict[str, str]: return { @@ -239,7 +241,10 @@ class Session(object): self.ended = True def create_peerconnection(self) -> None: - self.pc = RTCPeerConnection() + assert self.ice_servers is not None + rtc_config = RTCConfiguration() + rtc_config.iceServers = self.ice_servers + self.pc = RTCPeerConnection(rtc_config) assert self.pc is not None @self.pc.on("signalingstatechange") # type: ignore @@ -346,11 +351,11 @@ class Session(object): self.websocket = websocket self.connection_state = "HELLO" print(self.connection_id, "Connected") - ice_config = get_turn_credentials() + self.ice_servers = get_turn_credentials() print(self.connection_id, "Obtained ICE") # TODO Raygun user ID await websocket.send( - json.dumps({"kind": "HELLO", "connectionId": self.connection_id, "iceServers": ice_config}) + json.dumps({"kind": "HELLO", "connectionId": self.connection_id, "iceServers": self.ice_servers}) ) try: