mirror of
https://github.com/jellyfin/jellyfin-kodi.git
synced 2024-11-13 21:56:11 +00:00
Merge pull request #812 from smcmnz/ws-reconnect
Fix websocket automatic reconnection
This commit is contained in:
commit
b880f47585
3 changed files with 6 additions and 14 deletions
|
@ -35,7 +35,6 @@ 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=""):
|
||||||
|
|
||||||
|
@ -62,23 +61,18 @@ class WSClient(threading.Thread):
|
||||||
|
|
||||||
while not self.stop:
|
while not self.stop:
|
||||||
|
|
||||||
time.sleep(self.retry_count * 5)
|
self.wsc.run_forever(ping_interval=10, reconnect=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
|
||||||
|
|
||||||
# Wait a maximum of 60 seconds before retrying connection
|
|
||||||
if self.retry_count < 12:
|
|
||||||
self.retry_count += 1
|
|
||||||
|
|
||||||
LOG.info("---<[ websocket ]")
|
|
||||||
|
|
||||||
def on_error(self, ws, error):
|
def on_error(self, ws, error):
|
||||||
LOG.error(error)
|
LOG.error(error)
|
||||||
|
|
||||||
def on_open(self, ws):
|
def on_open(self, ws):
|
||||||
LOG.info("--->[ websocket ]")
|
LOG.info("--->[ websocket opened ]")
|
||||||
|
# Avoid a timing issue where the capabilities are not correctly registered
|
||||||
|
time.sleep(5)
|
||||||
if settings('remoteControl.bool'):
|
if settings('remoteControl.bool'):
|
||||||
self.client.jellyfin.post_capabilities({
|
self.client.jellyfin.post_capabilities({
|
||||||
'PlayableMediaTypes': "Audio,Video",
|
'PlayableMediaTypes': "Audio,Video",
|
||||||
|
@ -99,8 +93,6 @@ class WSClient(threading.Thread):
|
||||||
"PlayableMediaTypes": "Audio, Video",
|
"PlayableMediaTypes": "Audio, Video",
|
||||||
"SupportsMediaControl": False
|
"SupportsMediaControl": False
|
||||||
})
|
})
|
||||||
# Reinitialize the retry counter after successful connection
|
|
||||||
self.retry_count = 0
|
|
||||||
|
|
||||||
def on_message(self, ws, message):
|
def on_message(self, ws, message):
|
||||||
|
|
||||||
|
|
|
@ -34,4 +34,4 @@ dependencies:
|
||||||
- addon: 'script.module.addon.signals'
|
- addon: 'script.module.addon.signals'
|
||||||
version: '0.0.5+matrix.1'
|
version: '0.0.5+matrix.1'
|
||||||
- addon: 'script.module.websocket'
|
- addon: 'script.module.websocket'
|
||||||
version: '0.58.0+matrix.1'
|
version: '1.6.4'
|
||||||
|
|
|
@ -16,7 +16,7 @@ pytest >= 4.6.11
|
||||||
coverage >= 5.2
|
coverage >= 5.2
|
||||||
flake8 >= 3.8
|
flake8 >= 3.8
|
||||||
flake8-import-order >= 0.18
|
flake8-import-order >= 0.18
|
||||||
websocket-client >= 0.57.0
|
websocket-client >= 1.6.4
|
||||||
|
|
||||||
types-requests >= 2.31
|
types-requests >= 2.31
|
||||||
types-PyYAML >= 6.0
|
types-PyYAML >= 6.0
|
||||||
|
|
Loading…
Reference in a new issue