anonstream/anonstream/routes/websocket.py

27 行
727 B
Python
Raw 通常表示 履歴

2022-06-16 10:12:37 +09:00
# SPDX-FileCopyrightText: 2022 n9k <https://git.076.ne.jp/ninya9k>
2022-03-07 23:51:59 +09:00
# SPDX-License-Identifier: AGPL-3.0-or-later
import asyncio
from math import inf
from quart import current_app, websocket
from anonstream.user import see
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):
queue = asyncio.Queue(maxsize=0)
user['websockets'][queue] = -inf
producer = websocket_outbound(queue, user)
2022-02-18 10:32:34 +09:00
consumer = websocket_inbound(queue, user)
try:
await asyncio.gather(producer, consumer)
finally:
see(user)
user['websockets'].pop(queue)