Allow multiple commands on control socket without disconnecting.

This commit is contained in:
Leo Vasanko 2023-11-01 14:57:54 +00:00
parent a435a30c88
commit ba36eaec1b
2 changed files with 6 additions and 4 deletions

View File

@ -76,6 +76,7 @@ async def download(req, ws):
@bp.websocket("control")
@websocket_wrapper
async def control(req, ws):
while True:
cmd = msgspec.json.decode(await ws.recv(), type=ControlTypes)
await asyncio.to_thread(cmd)
await asend(ws, StatusMsg(status="ack", req=cmd))

View File

@ -9,7 +9,6 @@ from sanic.exceptions import Forbidden, NotFound
from cista import auth, config, session, watching
from cista.api import bp
from cista.util import filename
from cista.util.apphelpers import handle_sanic_exception
app = Sanic("cista", strict_slashes=True)
@ -90,12 +89,14 @@ def load_wwwroot(app):
wwwnew[name] = data, br, mime
www = wwwnew
@app.add_task
async def refresh_wwwroot():
while app.debug:
await asyncio.sleep(0.5)
load_wwwroot(app)
@app.get("/<path:path>", static=True)
async def wwwroot(req, path=""):
"""Frontend files only"""