Attempt to reestablished websocket communication if the connection fails

This commit is contained in:
Matt 2021-11-14 13:37:23 -05:00
parent 76d2bc2c38
commit 2427f566fa
2 changed files with 24 additions and 22 deletions

View file

@ -5,6 +5,7 @@ from __future__ import division, absolute_import, print_function, unicode_litera
import json
import threading
import time
from kodi_six import xbmc
@ -54,17 +55,22 @@ class WSClient(threading.Thread):
LOG.info("Websocket url: %s", 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_error=lambda ws, error: self.on_error(ws, error))
self.wsc.on_open = self.on_open
retry_count = 0
while not self.stop:
time.sleep(retry_count * 5)
self.wsc.run_forever(ping_interval=10)
if not self.stop and monitor.waitForAbort(5):
break
if retry_count < 12:
retry_count += 1
LOG.info("---<[ websocket ]")
def on_error(self, ws, error):
@ -72,6 +78,21 @@ class WSClient(threading.Thread):
def on_open(self, ws):
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):

View file

@ -160,7 +160,8 @@ class Monitor(xbmc.Monitor):
def server_instance(self, server_id=None):
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:
self.servers.append(server_id)
@ -177,26 +178,6 @@ class Monitor(xbmc.Monitor):
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):