Fixed Sonarr v3 SignalR feed not connecting when mono is used to run Sonarr. #1985

pull/1991/head
morpheus65535 2 years ago
parent b8b916dc30
commit a26b86cb95

@ -11,6 +11,7 @@ from requests.exceptions import ConnectionError
from signalrcore.hub_connection_builder import HubConnectionBuilder from signalrcore.hub_connection_builder import HubConnectionBuilder
from collections import deque from collections import deque
from time import sleep from time import sleep
from websocket._exceptions import WebSocketBadStatusException
from constants import headers from constants import headers
from app.event_handler import event_stream from app.event_handler import event_stream
@ -66,11 +67,15 @@ class SonarrSignalrClientLegacy:
"permissions on that directory and restart Sonarr. Also, if you're a Docker image " "permissions on that directory and restart Sonarr. Also, if you're a Docker image "
"user, you should make sure you properly defined PUID/PGID environment variables. " "user, you should make sure you properly defined PUID/PGID environment variables. "
"Otherwise, please contact Sonarr support.") "Otherwise, please contact Sonarr support.")
except WebSocketBadStatusException:
logging.debug("BAZARR cannot connect to Sonarr SignalR feed using websocket. We'll fall back to "
"SSE.")
self.configure(force_sse=True)
self.restart()
else: else:
self.connected = True self.connected = True
event_stream(type='badges') event_stream(type='badges')
logging.info('BAZARR SignalR client for Sonarr is connected and waiting for events.') logging.info('BAZARR SignalR client for Sonarr is connected and waiting for events.')
finally:
if not args.dev: if not args.dev:
scheduler.add_job(update_series, kwargs={'send_event': True}, max_instances=1) scheduler.add_job(update_series, kwargs={'send_event': True}, max_instances=1)
scheduler.add_job(sync_episodes, kwargs={'send_event': True}, max_instances=1) scheduler.add_job(sync_episodes, kwargs={'send_event': True}, max_instances=1)
@ -97,9 +102,9 @@ class SonarrSignalrClientLegacy:
logging.error('BAZARR connection to Sonarr SignalR feed has been lost.') logging.error('BAZARR connection to Sonarr SignalR feed has been lost.')
self.restart() self.restart()
def configure(self): def configure(self, force_sse=False):
self.apikey_sonarr = settings.sonarr.apikey self.apikey_sonarr = settings.sonarr.apikey
self.connection = Connection(url_sonarr() + "/signalr", self.session) self.connection = Connection(url_sonarr() + "/signalr", self.session, force_sse=force_sse)
self.connection.qs = {'apikey': self.apikey_sonarr} self.connection.qs = {'apikey': self.apikey_sonarr}
sonarr_hub = self.connection.register_hub('') # Sonarr doesn't use named hub sonarr_hub = self.connection.register_hub('') # Sonarr doesn't use named hub

@ -4,12 +4,13 @@ from threading import Thread
from signalr.events import EventHook from signalr.events import EventHook
from signalr.hubs import Hub from signalr.hubs import Hub
from signalr.transports import AutoTransport from signalr.transports import AutoTransport
from signalr.transports._sse_transport import ServerSentEventsTransport
class Connection: class Connection:
protocol_version = '1.5' protocol_version = '1.5'
def __init__(self, url, session): def __init__(self, url, session, force_sse=False):
self.url = url self.url = url
self.__hubs = {} self.__hubs = {}
self.qs = {} self.qs = {}
@ -23,7 +24,7 @@ class Connection:
self.stopping = EventHook() self.stopping = EventHook()
self.exception = EventHook() self.exception = EventHook()
self.is_open = False self.is_open = False
self.__transport = AutoTransport(session, self) self.__transport = ServerSentEventsTransport(session, self) if force_sse else AutoTransport(session, self)
self.__listener_thread = None self.__listener_thread = None
self.started = False self.started = False

Loading…
Cancel
Save