mirror of
https://github.com/jellyfin/jellyfin-kodi.git
synced 2024-12-26 02:36:10 +00:00
Move retry to class, more accurately target schema replace
This commit is contained in:
parent
2427f566fa
commit
eae01cfec9
1 changed files with 8 additions and 5 deletions
|
@ -35,6 +35,7 @@ class WSClient(threading.Thread):
|
||||||
|
|
||||||
self.client = client
|
self.client = client
|
||||||
threading.Thread.__init__(self)
|
threading.Thread.__init__(self)
|
||||||
|
self.retry_count = 0
|
||||||
|
|
||||||
def send(self, message, data=""):
|
def send(self, message, data=""):
|
||||||
|
|
||||||
|
@ -49,7 +50,7 @@ class WSClient(threading.Thread):
|
||||||
token = self.client.config.data['auth.token']
|
token = self.client.config.data['auth.token']
|
||||||
device_id = self.client.config.data['app.device_id']
|
device_id = self.client.config.data['app.device_id']
|
||||||
server = self.client.config.data['auth.server']
|
server = self.client.config.data['auth.server']
|
||||||
server = server.replace('https', "wss") if server.startswith('https') else server.replace('http', "ws")
|
server = server.replace('https://', 'wss://') if server.startswith('https') else server.replace('http://', 'ws://')
|
||||||
wsc_url = "%s/socket?api_key=%s&device_id=%s" % (server, token, device_id)
|
wsc_url = "%s/socket?api_key=%s&device_id=%s" % (server, token, device_id)
|
||||||
|
|
||||||
LOG.info("Websocket url: %s", wsc_url)
|
LOG.info("Websocket url: %s", wsc_url)
|
||||||
|
@ -59,17 +60,17 @@ class WSClient(threading.Thread):
|
||||||
on_message=lambda ws, message: self.on_message(ws, message),
|
on_message=lambda ws, message: self.on_message(ws, message),
|
||||||
on_error=lambda ws, error: self.on_error(ws, error))
|
on_error=lambda ws, error: self.on_error(ws, error))
|
||||||
|
|
||||||
retry_count = 0
|
|
||||||
while not self.stop:
|
while not self.stop:
|
||||||
|
|
||||||
time.sleep(retry_count * 5)
|
time.sleep(self.retry_count * 5)
|
||||||
self.wsc.run_forever(ping_interval=10)
|
self.wsc.run_forever(ping_interval=10)
|
||||||
|
|
||||||
if not self.stop and monitor.waitForAbort(5):
|
if not self.stop and monitor.waitForAbort(5):
|
||||||
break
|
break
|
||||||
|
|
||||||
if retry_count < 12:
|
# Wait a maximum of 60 seconds before retrying connection
|
||||||
retry_count += 1
|
if self.retry_count < 12:
|
||||||
|
self.retry_count += 1
|
||||||
|
|
||||||
LOG.info("---<[ websocket ]")
|
LOG.info("---<[ websocket ]")
|
||||||
|
|
||||||
|
@ -93,6 +94,8 @@ class WSClient(threading.Thread):
|
||||||
"Play,Playstate,PlayNext,PlayMediaSource"
|
"Play,Playstate,PlayNext,PlayMediaSource"
|
||||||
),
|
),
|
||||||
})
|
})
|
||||||
|
# Reinitialize the retry counter after successful connection
|
||||||
|
self.retry_count = 0
|
||||||
|
|
||||||
def on_message(self, ws, message):
|
def on_message(self, ws, message):
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue