Yes, it's as pythonic as such an non-Python object can be.
[toast/stream2beamer.git] / laplace_client.py
index 3600fdc3a30462cd4dbd1ab97ff0412a343d6953..1b9c8f0eccd0acfc1179c486599e635b4fb74911 100755 (executable)
@@ -31,6 +31,7 @@ class WebRTCClient:
         self.ssl_context.verify_mode = ssl.CERT_NONE
         self.websocket = None
         self.session_id = None
+        self.userfragments = []
 
     def send_sdp_offer(self, offer):
         text = offer.sdp.as_text()
@@ -57,6 +58,9 @@ class WebRTCClient:
         promise.interrupt()
         self.send_sdp_offer(offer)
 
+        sdp = offer.sdp
+        self.userfragments = [sdp.get_media(i).get_attribute_val('ice-ufrag') for i in range(sdp.medias_len())]
+
     def on_negotiation_needed(self, element):
         log.info('on_negotiation_needed')
         promise = Gst.Promise.new_with_change_func(self.on_offer_created, element, None)
@@ -68,8 +72,9 @@ class WebRTCClient:
             'Type': 'addCalleeIceCandidate',
             'Value': json.dumps({
                 "candidate": candidate,
-                "sdpMid": "0",
+                "sdpMid": f"{mlineindex}",
                 "sdpMLineIndex": mlineindex,
+                "usernameFragment": self.userfragments[mlineindex],
                 })
             })
         log.info(f'send_ice_candidate_message with {icemsg}')
@@ -193,7 +198,7 @@ def main():
     if not check_plugins():
         sys.exit(1)
     parser = argparse.ArgumentParser()
-    parser.add_argument('--uri', default='wss://localhost:2222/ws_connect?id=cug',
+    parser.add_argument('--uri', default='wss://localhost:1234/ws_connect?id=cug',
         help='Signalling server URI')
     args = parser.parse_args()
     c = WebRTCClient(args.uri)