mirror of
https://github.com/xfgryujk/blivedm.git
synced 2024-12-25 20:30:08 +08:00
添加重连次数太多的保险措施
This commit is contained in:
parent
356837c136
commit
b1d066b59f
@ -260,6 +260,16 @@ class OpenLiveClient(ws_base.WebSocketClientBase):
|
||||
return False
|
||||
return True
|
||||
|
||||
async def _on_before_ws_connect(self, retry_count):
|
||||
"""
|
||||
在每次建立连接之前调用,可以用来初始化房间
|
||||
"""
|
||||
# 重连次数太多则重新init_room,保险
|
||||
reinit_period = max(3, len(self._host_server_url_list or ()))
|
||||
if retry_count > 0 and retry_count % reinit_period == 0:
|
||||
self._need_init_room = True
|
||||
await super()._on_before_ws_connect(retry_count)
|
||||
|
||||
def _get_ws_url(self, retry_count) -> str:
|
||||
"""
|
||||
返回WebSocket连接的URL,可以在这里做故障转移和负载均衡
|
||||
|
@ -232,6 +232,16 @@ class BLiveClient(ws_base.WebSocketClientBase):
|
||||
return False
|
||||
return True
|
||||
|
||||
async def _on_before_ws_connect(self, retry_count):
|
||||
"""
|
||||
在每次建立连接之前调用,可以用来初始化房间
|
||||
"""
|
||||
# 重连次数太多则重新init_room,保险
|
||||
reinit_period = max(3, len(self._host_server_list or ()))
|
||||
if retry_count > 0 and retry_count % reinit_period == 0:
|
||||
self._need_init_room = True
|
||||
await super()._on_before_ws_connect(retry_count)
|
||||
|
||||
def _get_ws_url(self, retry_count) -> str:
|
||||
"""
|
||||
返回WebSocket连接的URL,可以在这里做故障转移和负载均衡
|
||||
|
@ -248,7 +248,7 @@ class WebSocketClientBase:
|
||||
retry_count = 0
|
||||
while True:
|
||||
try:
|
||||
await self._on_before_ws_connect()
|
||||
await self._on_before_ws_connect(retry_count)
|
||||
|
||||
# 连接
|
||||
async with self._session.ws_connect(
|
||||
@ -282,7 +282,7 @@ class WebSocketClientBase:
|
||||
logger.warning('room=%d is reconnecting, retry_count=%d', self.room_id, retry_count)
|
||||
await asyncio.sleep(1)
|
||||
|
||||
async def _on_before_ws_connect(self):
|
||||
async def _on_before_ws_connect(self, retry_count):
|
||||
"""
|
||||
在每次建立连接之前调用,可以用来初始化房间
|
||||
"""
|
||||
|
Loading…
Reference in New Issue
Block a user