diff --git a/blivedm/clients/ws_base.py b/blivedm/clients/ws_base.py index da21755..3387bdb 100644 --- a/blivedm/clients/ws_base.py +++ b/blivedm/clients/ws_base.py @@ -232,8 +232,8 @@ class WebSocketClientBase: logger.debug('room=%s _network_coroutine() finished', self.room_id) self._network_future = None - if exc is not None and self._handler is not None: - self._handler.on_stopped_by_exception(self, exc) + if self._handler is not None: + self._handler.on_client_stopped(self, exc) async def _network_coroutine(self): """ @@ -454,6 +454,8 @@ class WebSocketClientBase: :param command: 业务消息 """ + if self._handler is None: + return try: # 为什么不做成异步的: # 1. 为了保持处理消息的顺序,这里不使用call_soon、create_task等方法延迟处理 diff --git a/blivedm/handlers.py b/blivedm/handlers.py index c53cea6..9d33b70 100644 --- a/blivedm/handlers.py +++ b/blivedm/handlers.py @@ -48,9 +48,9 @@ class HandlerInterface: def handle(self, client: ws_base.WebSocketClientBase, command: dict): raise NotImplementedError - def on_stopped_by_exception(self, client: ws_base.WebSocketClientBase, exception: Exception): + def on_client_stopped(self, client: ws_base.WebSocketClientBase, exception: Optional[Exception]): """ - 当客户端被异常停止时调用。可以在这里close或者重新start + 当客户端停止时调用。可以在这里close或者重新start """