Add plenty of log messages.
[toast/stream2beamer.git] / laplace_client.py
old mode 100644 (file)
new mode 100755 (executable)
index 63fb8b8..4180f30
@@ -1,3 +1,5 @@
+#!/usr/bin/python3
+
 import argparse
 import asyncio
 import json
@@ -17,7 +19,7 @@ gi.require_version('GstSdp', '1.0')
 from gi.repository import GstSdp
 
 
-log = logging.Logger(__name__)
+log = logging.getLogger(__name__)
 
 
 class WebRTCClient:
@@ -32,7 +34,7 @@ class WebRTCClient:
 
     def send_sdp_offer(self, offer):
         text = offer.sdp.as_text()
-        log.info('Sending offer:\n%s' % text)
+        log.info(f'send_sdp_offer with {text}')
         msg = json.dumps({
             'SessionID': self.session_id,
             'Type': "gotAnswer",
@@ -46,6 +48,7 @@ class WebRTCClient:
         loop.close()
 
     def on_offer_created(self, promise, _, __):
+        log.info('on_offer_created')
         promise.wait()
         reply = promise.get_reply()
         offer = reply['offer']
@@ -55,6 +58,7 @@ class WebRTCClient:
         self.send_sdp_offer(offer)
 
     def on_negotiation_needed(self, element):
+        log.info('on_negotiation_needed')
         promise = Gst.Promise.new_with_change_func(self.on_offer_created, element, None)
         element.emit('create-offer', None, promise)
 
@@ -68,11 +72,13 @@ class WebRTCClient:
                 "sdpMLineIndex": mlineindex,
                 })
             })
+        log.info(f'send_ice_candidate_message with {icemsg}')
         loop = asyncio.new_event_loop()
         loop.run_until_complete(self.websocket.send(icemsg))
         loop.close()
 
     def on_incoming_decodebin_stream(self, _, pad):
+        log.info('on_incoming_decodebin_stream')
         if not pad.has_current_caps():
             log.info(pad, 'has no caps, ignoring')
             return
@@ -103,6 +109,7 @@ class WebRTCClient:
             resample.link(sink)
 
     def on_incoming_stream(self, _, pad):
+        log.info('on_incoming_stream')
         if pad.direction != Gst.PadDirection.SRC:
             return
         decodebin = Gst.ElementFactory.make('decodebin')
@@ -130,6 +137,7 @@ class WebRTCClient:
         self.webrtc = None
     
     def handle_sdp(self, sdp):
+        log.info(f'handle_sdp: {sdp}')
         res, sdpmsg = GstSdp.SDPMessage.new()
         GstSdp.sdp_message_parse_buffer(bytes(sdp.encode()), sdpmsg)
         answer = GstWebRTC.WebRTCSessionDescription.new(GstWebRTC.WebRTCSDPType.ANSWER, sdpmsg)
@@ -138,6 +146,7 @@ class WebRTCClient:
         promise.interrupt()
 
     def handle_ice(self, ice):
+        log.info(f'handle_ice: {ice}')
         candidate = ice['candidate']
         sdpmlineindex = ice['sdpMLineIndex']
         self.webrtc.emit('add-ice-candidate', sdpmlineindex, candidate)