mirror of
https://github.com/jellyfin/jellyfin-kodi.git
synced 2024-11-10 04:06:11 +00:00
Attempt to reestablished websocket communication if the connection fails
This commit is contained in:
parent
76d2bc2c38
commit
2427f566fa
2 changed files with 24 additions and 22 deletions
|
@ -5,6 +5,7 @@ from __future__ import division, absolute_import, print_function, unicode_litera
|
||||||
|
|
||||||
import json
|
import json
|
||||||
import threading
|
import threading
|
||||||
|
import time
|
||||||
|
|
||||||
from kodi_six import xbmc
|
from kodi_six import xbmc
|
||||||
|
|
||||||
|
@ -54,17 +55,22 @@ class WSClient(threading.Thread):
|
||||||
LOG.info("Websocket url: %s", wsc_url)
|
LOG.info("Websocket url: %s", wsc_url)
|
||||||
|
|
||||||
self.wsc = websocket.WebSocketApp(wsc_url,
|
self.wsc = websocket.WebSocketApp(wsc_url,
|
||||||
|
on_open=lambda ws: self.on_open(ws),
|
||||||
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))
|
||||||
self.wsc.on_open = self.on_open
|
|
||||||
|
|
||||||
|
retry_count = 0
|
||||||
while not self.stop:
|
while not self.stop:
|
||||||
|
|
||||||
|
time.sleep(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:
|
||||||
|
retry_count += 1
|
||||||
|
|
||||||
LOG.info("---<[ websocket ]")
|
LOG.info("---<[ websocket ]")
|
||||||
|
|
||||||
def on_error(self, ws, error):
|
def on_error(self, ws, error):
|
||||||
|
@ -72,6 +78,21 @@ class WSClient(threading.Thread):
|
||||||
|
|
||||||
def on_open(self, ws):
|
def on_open(self, ws):
|
||||||
LOG.info("--->[ websocket ]")
|
LOG.info("--->[ websocket ]")
|
||||||
|
self.client.jellyfin.post_capabilities({
|
||||||
|
'PlayableMediaTypes': "Audio,Video",
|
||||||
|
'SupportsMediaControl': True,
|
||||||
|
'SupportedCommands': (
|
||||||
|
"MoveUp,MoveDown,MoveLeft,MoveRight,Select,"
|
||||||
|
"Back,ToggleContextMenu,ToggleFullscreen,ToggleOsdMenu,"
|
||||||
|
"GoHome,PageUp,NextLetter,GoToSearch,"
|
||||||
|
"GoToSettings,PageDown,PreviousLetter,TakeScreenshot,"
|
||||||
|
"VolumeUp,VolumeDown,ToggleMute,SendString,DisplayMessage,"
|
||||||
|
"SetAudioStreamIndex,SetSubtitleStreamIndex,"
|
||||||
|
"SetRepeatMode,"
|
||||||
|
"Mute,Unmute,SetVolume,"
|
||||||
|
"Play,Playstate,PlayNext,PlayMediaSource"
|
||||||
|
),
|
||||||
|
})
|
||||||
|
|
||||||
def on_message(self, ws, message):
|
def on_message(self, ws, message):
|
||||||
|
|
||||||
|
|
|
@ -160,7 +160,8 @@ class Monitor(xbmc.Monitor):
|
||||||
def server_instance(self, server_id=None):
|
def server_instance(self, server_id=None):
|
||||||
|
|
||||||
server = Jellyfin(server_id).get_client()
|
server = Jellyfin(server_id).get_client()
|
||||||
self.post_capabilities(server)
|
session = server.jellyfin.get_device(self.device_id)
|
||||||
|
server.config.data['app.session'] = session[0]['Id']
|
||||||
|
|
||||||
if server_id is not None:
|
if server_id is not None:
|
||||||
self.servers.append(server_id)
|
self.servers.append(server_id)
|
||||||
|
@ -177,26 +178,6 @@ class Monitor(xbmc.Monitor):
|
||||||
|
|
||||||
self.additional_users(server)
|
self.additional_users(server)
|
||||||
|
|
||||||
def post_capabilities(self, server):
|
|
||||||
LOG.info("--[ post capabilities/%s ]", server.auth.server_id)
|
|
||||||
|
|
||||||
server.jellyfin.post_capabilities({
|
|
||||||
'PlayableMediaTypes': "Audio,Video",
|
|
||||||
'SupportsMediaControl': True,
|
|
||||||
'SupportedCommands': (
|
|
||||||
"MoveUp,MoveDown,MoveLeft,MoveRight,Select,"
|
|
||||||
"Back,ToggleContextMenu,ToggleFullscreen,ToggleOsdMenu,"
|
|
||||||
"GoHome,PageUp,NextLetter,GoToSearch,"
|
|
||||||
"GoToSettings,PageDown,PreviousLetter,TakeScreenshot,"
|
|
||||||
"VolumeUp,VolumeDown,ToggleMute,SendString,DisplayMessage,"
|
|
||||||
"SetAudioStreamIndex,SetSubtitleStreamIndex,"
|
|
||||||
"SetRepeatMode,"
|
|
||||||
"Mute,Unmute,SetVolume,"
|
|
||||||
"Play,Playstate,PlayNext,PlayMediaSource"
|
|
||||||
),
|
|
||||||
})
|
|
||||||
session = server.jellyfin.get_device(self.device_id)
|
|
||||||
server.config.data['app.session'] = session[0]['Id']
|
|
||||||
|
|
||||||
def additional_users(self, server):
|
def additional_users(self, server):
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue