From: Marcel van der Veldt Date: Mon, 15 Dec 2025 18:23:46 +0000 (+0100) Subject: Use websocket ping/pong for remote access (re)connection X-Git-Url: https://git.kitaultman.com/?a=commitdiff_plain;h=c7adc276f2b44e6fdbec2d45a8e7e3c9c1a6b888;p=music-assistant-server.git Use websocket ping/pong for remote access (re)connection --- diff --git a/music_assistant/controllers/webserver/remote_access/gateway.py b/music_assistant/controllers/webserver/remote_access/gateway.py index 57483248..da5ab52a 100644 --- a/music_assistant/controllers/webserver/remote_access/gateway.py +++ b/music_assistant/controllers/webserver/remote_access/gateway.py @@ -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