From 5a8c7eef82f14334ebcd4a9a2a308fe2cec23154 Mon Sep 17 00:00:00 2001 From: Matthew Clark Date: Thu, 8 Nov 2018 20:18:41 +0000 Subject: [PATCH] webrtc better handling of a closed connection --- brave/outputs/webrtc.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/brave/outputs/webrtc.py b/brave/outputs/webrtc.py index 7d2d3e5..e7f50ec 100644 --- a/brave/outputs/webrtc.py +++ b/brave/outputs/webrtc.py @@ -4,6 +4,7 @@ import json import asyncio import gi +import websockets gi.require_version('GstWebRTC', '1.0') from gi.repository import GstWebRTC gi.require_version('GstSdp', '1.0') @@ -110,8 +111,7 @@ def on_message(bus, message): t = message.type if t == Gst.MessageType.ELEMENT: if message.get_structure().get_name() == 'level': - s = message.get_structure() - channels = len(s['peak']) + channels = len(message.get_structure().get_value('peak')) data = [] for i in range(0, channels): @@ -122,7 +122,14 @@ def on_message(bus, message): })) jsonData = json.dumps({'msg_type': 'volume', 'channels': channels, 'data': data}) - loop.create_task(ws.send(jsonData)) + + async def _send_data(): + try: + await ws.send(jsonData) + except websockets.ConnectionClosed: + pass + + loop.create_task(_send_data()) self.pipeline.get_bus().add_signal_watch() self.pipeline.get_bus().connect('message::element', on_message)