2022-03-07 23:51:59 +09:00
|
|
|
# SPDX-FileCopyrightText: 2022 n9k [https://git.076.ne.jp/ninya9k]
|
|
|
|
# SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
|
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-20 13:23:32 +09:00
|
|
|
producer = websocket_outbound(queue, user)
|
2022-02-18 10:32:34 +09:00
|
|
|
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)
|