Files
jellycon/resources/lib/websocket_client.py.rej
mani a71efe14c1
Some checks failed
Build JellyCon / build (py2) (push) Has been cancelled
Build JellyCon / build (py3) (push) Has been cancelled
CodeQL Analysis / analyze (python, 3.9) (push) Has been cancelled
Release Drafter / Update release draft (push) Has been cancelled
Test JellyCon / test (3.9) (push) Has been cancelled
Properly fix intermittent installation failures
Instead of setting addon variables to None (which causes issues),
fix the root cause by removing unnecessary module-level initialization:

- Remove module-level user_details loading in functions.py
- Load user_details locally in functions where actually needed
- Wrap remaining module-level addon access in try/except in:
  - service.py (log_timing_data)
  - default.py (log_timing_data)
  - kodi_utils.py (addon variable)
  - functions.py (__addon__ and related variables)

This prevents crashes during installation/update while avoiding
None-related issues during normal operation.
2026-01-06 01:12:59 +01:00

74 lines
2.8 KiB
Plaintext

@@ -46,7 +46,12 @@
result = json.loads(message)
message_type = result['MessageType']
- if message_type == 'Play':
+ if message_type == 'ForceKeepAlive':
+ timeout_seconds = result.get('Data', 60)
+ log.debug("Received ForceKeepAlive with timeout: {0}s".format(timeout_seconds))
+ self._send_keep_alive()
+
+ elif message_type == 'Play':
data = result['Data']
self._play(data)
@@ -237,6 +242,9 @@
def on_error(self, ws, error):
log.debug("Error: {0}".format(error))
+ def on_close(self, ws, close_status_code, close_msg):
+ log.debug("WebSocket closed. Code: {0}, Message: {1}".format(close_status_code, close_msg))
+
def run(self):
token = None
@@ -259,17 +267,23 @@
)
log.debug("websocket url: {0}".format(websocket_url))
- self._client = websocket.WebSocketApp(
- websocket_url,
- on_open=lambda ws: self.on_open(ws),
- on_message=lambda ws, message: self.on_message(ws, message),
- on_error=lambda ws, error: self.on_error(ws, error))
-
log.debug("Starting WebSocketClient")
while not self.monitor.abortRequested():
- self._client.run_forever(ping_interval=5, reconnect=13, ping_timeout=2)
+ # Create a new WebSocketApp for each connection attempt to avoid
+ # memory leaks from reusing a potentially dirty connection object
+ self._client = websocket.WebSocketApp(
+ websocket_url,
+ on_open=lambda ws: self.on_open(ws),
+ on_message=lambda ws, message: self.on_message(ws, message),
+ on_error=lambda ws, error: self.on_error(ws, error),
+ on_close=lambda ws, status, msg: self.on_close(ws, status, msg))
+
+ # Use ping_interval without ping_timeout to keep connection alive
+ # without forcing disconnection. The server's ForceKeepAlive/KeepAlive
+ # mechanism handles the actual keepalive logic.
+ self._client.run_forever(ping_interval=10)
if self._stop_websocket:
break
@@ -291,6 +305,17 @@
self._client.close()
log.debug("Stopping WebSocket (stop_client called)")
+ def _send_keep_alive(self):
+ """Send a KeepAlive message to the server to maintain the connection."""
+ try:
+ keep_alive_message = json.dumps({
+ 'MessageType': 'KeepAlive'
+ })
+ self._client.send(keep_alive_message)
+ log.debug("Sent KeepAlive message")
+ except Exception as error:
+ log.debug("Error sending KeepAlive: {0}".format(error))
+
def post_capabilities(self):
settings = xbmcaddon.Addon()