Revert "Fix WebSocket session flapping with ForceKeepAlive protocol"
This reverts commit d5920a381e.
This commit is contained in:
@@ -46,12 +46,7 @@ class WebSocketClient(threading.Thread):
|
||||
result = json.loads(message)
|
||||
message_type = result['MessageType']
|
||||
|
||||
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':
|
||||
if message_type == 'Play':
|
||||
data = result['Data']
|
||||
self._play(data)
|
||||
|
||||
@@ -242,9 +237,6 @@ class WebSocketClient(threading.Thread):
|
||||
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
|
||||
@@ -267,23 +259,17 @@ class WebSocketClient(threading.Thread):
|
||||
)
|
||||
log.debug("websocket url: {0}".format(websocket_url))
|
||||
|
||||
log.debug("Starting WebSocketClient")
|
||||
|
||||
while not self.monitor.abortRequested():
|
||||
|
||||
# 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))
|
||||
on_error=lambda ws, error: self.on_error(ws, error))
|
||||
|
||||
# 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)
|
||||
log.debug("Starting WebSocketClient")
|
||||
|
||||
while not self.monitor.abortRequested():
|
||||
|
||||
self._client.run_forever(ping_interval=5, reconnect=13, ping_timeout=2)
|
||||
|
||||
if self._stop_websocket:
|
||||
break
|
||||
@@ -305,17 +291,6 @@ class WebSocketClient(threading.Thread):
|
||||
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()
|
||||
|
||||
Reference in New Issue
Block a user