mirror of
https://github.com/yulinfeng000/blive.git
synced 2025-03-25 16:50:53 +08:00
release 0.1
This commit is contained in:
parent
bc6b01b22d
commit
758108b346
@ -178,8 +178,6 @@ async def show():
|
||||
- example/with_fastapi.py
|
||||
与fastapi 配合使用的例子
|
||||
|
||||
- example/error_handler.py
|
||||
错误处理的例子
|
||||
|
||||
## TODO
|
||||
|
||||
|
@ -87,7 +87,7 @@ class BLiver(AsyncIOEventEmitter):
|
||||
self.scheduler.start()
|
||||
|
||||
# 开始监听
|
||||
while True:
|
||||
while self.running:
|
||||
try:
|
||||
msg = await self.ws.receive(timeout=60)
|
||||
if msg.type in (
|
||||
@ -95,8 +95,9 @@ class BLiver(AsyncIOEventEmitter):
|
||||
aiohttp.WSMsgType.CLOSED,
|
||||
aiohttp.WSMsgType.ERROR,
|
||||
):
|
||||
await self.connect() # reconnect
|
||||
continue
|
||||
if self.running:
|
||||
await self.connect() # reconnect
|
||||
continue
|
||||
if msg.type != aiohttp.WSMsgType.BINARY:
|
||||
continue
|
||||
mq = self.packman.unpack(msg.data)
|
||||
@ -112,10 +113,11 @@ class BLiver(AsyncIOEventEmitter):
|
||||
await self.connect()
|
||||
|
||||
async def graceful_close(self):
|
||||
self.scheduler.shutdown()
|
||||
await self._ws.close()
|
||||
await self.aio_session.close()
|
||||
self.running = False
|
||||
self.scheduler.shutdown()
|
||||
await self.aio_session.close()
|
||||
await self.ws.close()
|
||||
|
||||
|
||||
def run(self):
|
||||
loop = asyncio.get_event_loop()
|
||||
|
@ -1,3 +1,4 @@
|
||||
import uvicorn
|
||||
from fastapi import FastAPI
|
||||
from blive import BLiver, Events
|
||||
from blive.msg import DanMuMsg
|
||||
@ -41,3 +42,7 @@ async def rm_bliver(roomid: int):
|
||||
@app.get("/show")
|
||||
async def show():
|
||||
return list(BLIVER_POOL.keys())
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
uvicorn.run(app)
|
Loading…
Reference in New Issue
Block a user