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)