Use websocket ping/pong for remote access (re)connection
authorMarcel van der Veldt <m.vanderveldt@outlook.com>
Mon, 15 Dec 2025 18:23:46 +0000 (19:23 +0100)
committerMarcel van der Veldt <m.vanderveldt@outlook.com>
Mon, 15 Dec 2025 18:23:46 +0000 (19:23 +0100)
music_assistant/controllers/webserver/remote_access/gateway.py

index 574832483c1667cd99af045efd5ec5c448968879..da5ab52af5a86f58b56af63b4432d0d0c9b7b0ad 100644 (file)
@@ -222,7 +222,7 @@ class WebRTCGateway:
         try:
             self._signaling_ws = await self.http_session.ws_connect(
                 self.signaling_url,
-                heartbeat=None,
+                heartbeat=30.0,  # Send WebSocket ping every 30s to keep connection alive
             )
             self.logger.debug("WebSocket connection established, id=%s", id(self._signaling_ws))
             self.logger.debug("Sending registration")
@@ -315,10 +315,9 @@ class WebRTCGateway:
         """
         msg_type = message.get("type")
 
-        if msg_type == "ping":
-            if self._signaling_ws:
-                await self._signaling_ws.send_json({"type": "pong"})
-        elif msg_type == "pong":
+        if msg_type in ("ping", "pong"):
+            # Ignore JSON-level ping/pong messages - we use WebSocket protocol-level heartbeat
+            # The signaling server still sends these for backward compatibility with older clients
             pass
         elif msg_type == "registered":
             self._is_connected = True