补充开放平台接口的结束及心跳调用

This commit is contained in:
kinori 2023-09-02 19:36:04 +08:00
parent 20867a2135
commit 0bdec42f50
3 changed files with 15 additions and 5 deletions

View File

@ -233,6 +233,10 @@ class BLiveClient:
"""
便利函数停止本客户端并释放本客户端的资源调用后本客户端将不可用
"""
if self._open_live_client:
await self._open_live_client.end()
if self.is_running:
self.stop()
await self.join()
@ -522,6 +526,13 @@ class BLiveClient:
except Exception: # noqa
logger.exception('room=%d _send_heartbeat() failed:', self.room_id)
try:
await self._open_live_client.heartbeat()
except (ConnectionResetError, aiohttp.ClientConnectionError) as e:
logger.warning('room=%d _send_heartbeat() failed: %r', self.room_id, e)
except Exception: # noqa
logger.exception('room=%d _send_heartbeat() failed:', self.room_id)
async def _on_ws_message(self, message: aiohttp.WSMessage):
"""
收到WebSocket消息

View File

@ -149,7 +149,7 @@ class OpenLiveClient:
return False
try:
params = f'{{"app_id":{self.app_id},"game_id":{self._game_id}}}'
params = f'{{"game_id":"{self._game_id}", "app_id":{self.app_id}}}'
headers = self._sign_request_header(params)
async with self._session.post(
OPEN_LIVE_END_URL, headers=headers, data=params, ssl=self._ssl
@ -175,8 +175,7 @@ class OpenLiveClient:
return False
try:
params = f'{{"game_id":{self._game_id}}}'
print(params)
params = f'{{"game_id":"{self._game_id}"}}'
headers = self._sign_request_header(params)
async with self._session.post(
OPEN_LIVE_HEARTBEAT_URL, headers=headers, data=params, ssl=self._ssl

View File

@ -25,8 +25,8 @@ async def run_start():
client.start()
try:
# 演示60秒后停止
await asyncio.sleep(600)
# 演示20秒后停止
await asyncio.sleep(60)
client.stop()
await client.join()