2022-02-16 18:55:30 +09:00
|
|
|
import asyncio
|
|
|
|
|
|
|
|
from quart import current_app, websocket
|
|
|
|
|
|
|
|
from anonstream.websocket import websocket_outbound, websocket_inbound
|
|
|
|
from anonstream.routes.wrappers import with_user_from
|
|
|
|
|
|
|
|
@current_app.websocket('/live')
|
|
|
|
@with_user_from(websocket)
|
|
|
|
async def live(user):
|
2022-02-19 12:14:37 +09:00
|
|
|
queue = asyncio.Queue(maxsize=0)
|
2022-02-18 10:32:34 +09:00
|
|
|
user['websockets'].add(queue)
|
2022-02-16 18:55:30 +09:00
|
|
|
|
2022-02-18 10:32:34 +09:00
|
|
|
producer = websocket_outbound(queue)
|
|
|
|
consumer = websocket_inbound(queue, user)
|
2022-02-16 18:55:30 +09:00
|
|
|
try:
|
|
|
|
await asyncio.gather(producer, consumer)
|
|
|
|
finally:
|
2022-02-18 10:32:34 +09:00
|
|
|
user['websockets'].remove(queue)
|