Don't fail if message is received before websocket start (#9634)

This commit is contained in:
Nicolas Mowen 2024-02-05 16:53:16 -07:00 committed by GitHub
parent a33f2f117e
commit 00804a0f81
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -38,6 +38,7 @@ class WebSocketClient(Communicator): # type: ignore[misc]
def __init__(self, config: FrigateConfig) -> None: def __init__(self, config: FrigateConfig) -> None:
self.config = config self.config = config
self.websocket_server = None
def subscribe(self, receiver: Callable) -> None: def subscribe(self, receiver: Callable) -> None:
self._dispatcher = receiver self._dispatcher = receiver
@ -98,6 +99,10 @@ class WebSocketClient(Communicator): # type: ignore[misc]
logger.debug(f"payload for {topic} wasn't text. Skipping...") logger.debug(f"payload for {topic} wasn't text. Skipping...")
return return
if self.websocket_server is None:
logger.debug("Skipping message, websocket not connected yet")
return
try: try:
self.websocket_server.manager.broadcast(ws_message) self.websocket_server.manager.broadcast(ws_message)
except ConnectionResetError: except ConnectionResetError: