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,9 +76,10 @@ async def download(req, ws):
@bp.websocket("control") @bp.websocket("control")
@websocket_wrapper @websocket_wrapper
async def control(req, ws): async def control(req, ws):
cmd = msgspec.json.decode(await ws.recv(), type=ControlTypes) while True:
await asyncio.to_thread(cmd) cmd = msgspec.json.decode(await ws.recv(), type=ControlTypes)
await asend(ws, StatusMsg(status="ack", req=cmd)) await asyncio.to_thread(cmd)
await asend(ws, StatusMsg(status="ack", req=cmd))
@bp.websocket("watch") @bp.websocket("watch")

View File

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