The back-end websocket server for wowlet.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

69 lines
1.9 KiB

# SPDX-License-Identifier: BSD-3-Clause
# Copyright (c) 2020, The Monero Project.
# Copyright (c) 2020,
import asyncio
import json
from quart import websocket, jsonify
from wowlet_backend.factory import app
from wowlet_backend.wsparse import WebsocketParse
from wowlet_backend.utils import collect_websocket, feather_data
async def root():
data = await feather_data()
return jsonify(data)
async def ws(queue):
data = await feather_data()
# blast available data on connect
for task_key, task_value in data.items():
if not task_value:
await websocket.send(json.dumps({"cmd": task_key, "data": task_value}).encode())
async def rx():
while True:
buffer = await websocket.receive()
blob = json.loads(buffer)
if "cmd" not in blob:
cmd = blob.get('cmd')
_data = blob.get('data')
result = await WebsocketParse.parser(cmd, _data)
if result:
rtn = json.dumps({"cmd": cmd, "data": result}).encode()
await websocket.send(rtn)
except Exception as ex:
async def tx():
while True:
data = await queue.get()
payload = json.dumps(data).encode()
await websocket.send(payload)
# bidirectional async rx and tx loops
consumer_task = asyncio.ensure_future(rx())
producer_task = asyncio.ensure_future(tx())
await asyncio.gather(consumer_task, producer_task)
def page_not_found(e):
return ":)", 500