Skip to content

Commit

Permalink
webrtc better handling of a closed connection
Browse files Browse the repository at this point in the history
  • Loading branch information
matthew1000 committed Nov 8, 2018
1 parent 7b24c80 commit 5a8c7ee
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions brave/outputs/webrtc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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):
Expand All @@ -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)
Expand Down

0 comments on commit 5a8c7ee

Please sign in to comment.