mirror of
https://github.com/xfgryujk/blivedm.git
synced 2024-12-25 20:30:08 +08:00
补充开放平台接口的结束及心跳调用
This commit is contained in:
parent
20867a2135
commit
0bdec42f50
@ -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消息
|
||||
|
@ -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
|
||||
|
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user