From 3ec6b9b25ce98363f87c54fd25249aa0a6984e0b Mon Sep 17 00:00:00 2001 From: Marks Polakovs Date: Mon, 13 Apr 2020 00:51:12 +0200 Subject: [PATCH] slightly better drop handling on the serverside --- server.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/server.py b/server.py index dcca699..8ca7c08 100644 --- a/server.py +++ b/server.py @@ -5,6 +5,7 @@ import uuid import av # type: ignore import struct from aiortc import MediaStreamTrack, RTCPeerConnection, RTCSessionDescription # type: ignore +from aiortc.mediastreams import MediaStreamError # type: ignore from aiortc.contrib.media import MediaBlackhole, MediaPlayer # type: ignore import jack as Jack # type: ignore import os @@ -226,12 +227,15 @@ class Session(object): @track.on("ended") # type: ignore async def on_ended() -> None: print(self.connection_id, "Track {} ended".format(track.kind)) - # TODO: this doesn't exactly handle reconnecting gracefully await self.end() write_ob_status(True) while True: - frame = await track.recv() + try: + frame = await track.recv() + except MediaStreamError as e: + print(self.connection_id, e) + await self.end() if self.running: # Right, depending on the format, we may need to do some fuckery. # Jack expects all audio to be 32 bit floating point