Skip to content

Commit

Permalink
Merge pull request #9 from bbc/webrtc_audio_channels_on_connection_cl…
Browse files Browse the repository at this point in the history
…osed

webrtc to not error if the user closes their browser window
  • Loading branch information
matthew1000 authored Nov 15, 2018
2 parents cf28f0e + 5a8c7ee commit 47a5198
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion 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 @@ -121,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 47a5198

Please sign in to comment.