Add wrapper that listens to the availability of the room.
[toast/stream2beamer.git] / laplace_client.py
index 1b9c8f0eccd0acfc1179c486599e635b4fb74911..7378c62d8037b083e80ce0c07a25a9ff93dd143d 100755 (executable)
@@ -160,27 +160,31 @@ class WebRTCClient:
         self.webrtc.emit('add-ice-candidate', sdpmlineindex, candidate)
 
     async def run(self):
-        async with websockets.connect(self.uri, ssl=self.ssl_context) as websocket:
-            self.websocket = websocket
-            self.start_pipeline()
-            async for msg in websocket:
-                msg_json = json.loads(msg)
-                msg_type = msg_json['Type']
-                msg_value = msg_json['Value']
-                session_id = msg_json['SessionID']
-                log.info(f"receive for session {session_id} type {msg_type}")
-                if msg_type == 'newSession':
-                    self.session_id = session_id
-                elif msg_type == 'gotOffer':
-                    value_json = json.loads(msg_value)
-                    sdp = value_json['sdp']
-                    self.handle_sdp(sdp)
-                elif msg_type == 'addCallerIceCandidate':
-                    value_json = json.loads(msg_value)
-                    self.handle_ice(value_json)
-        self.close_pipeline()
-        self.websocket = None
-        self.session_id = None
+        try:
+            async with websockets.connect(self.uri, ssl=self.ssl_context) as websocket:
+                self.websocket = websocket
+                self.start_pipeline()
+                async for msg in websocket:
+                    msg_json = json.loads(msg)
+                    msg_type = msg_json['Type']
+                    msg_value = msg_json['Value']
+                    session_id = msg_json['SessionID']
+                    log.info(f"receive for session {session_id} type {msg_type}")
+                    if msg_type == 'newSession':
+                        self.session_id = session_id
+                    elif msg_type == 'gotOffer':
+                        value_json = json.loads(msg_value)
+                        sdp = value_json['sdp']
+                        self.handle_sdp(sdp)
+                    elif msg_type == 'addCallerIceCandidate':
+                        value_json = json.loads(msg_value)
+                        self.handle_ice(value_json)
+            self.close_pipeline()
+            self.websocket = None
+            self.session_id = None
+        except:
+            log.error(f'Connection to "{self.uri}" failed')
+            sys.exit(1)
 
 
 def check_plugins():