This commit is contained in:
2026-04-11 15:01:09 +02:00
parent 48a4617560
commit 48c955b527
2 changed files with 3 additions and 12 deletions
+2
View File
@@ -255,6 +255,7 @@
document.getElementById("server-status").textContent = "connected";
reconnectDelay = 1000;
ws.send(JSON.stringify({action:"get_toplay"}));
ws.send(JSON.stringify({action:"skipc"}));
});
ws.addEventListener("close", () => {
@@ -289,6 +290,7 @@
} else if(msg.event === "new_track"){
applyTrackState(msg.data);
ws.send(JSON.stringify({action:"get_toplay"}));
ws.send(JSON.stringify({action:"skipc"}));
} else if(msg.event === "progress") applyProgressState(msg.data);
else if(msg.event === "toplay") {
Queue = msg.data.data || [];
+1 -12
View File
@@ -109,10 +109,6 @@ async def ws_handler(websocket: ServerConnection, shared_data: dict, imc_q: mult
else: await websocket.send(json.dumps({"error": "unknown action"}))
async def broadcast_worker(ws_q: multiprocessing.Queue, clients: set):
"""
Reads messages from ws_q (a blocking multiprocessing.Queue) using run_in_executor
and broadcasts them to all connected clients.
"""
loop = asyncio.get_event_loop()
while True:
msg = await loop.run_in_executor(None, ws_q.get)
@@ -120,11 +116,9 @@ async def broadcast_worker(ws_q: multiprocessing.Queue, clients: set):
payload = json.dumps(msg)
if clients:
coros = []
for ws in list(clients):
coros.append(_safe_send(ws, payload, clients))
for ws in list(clients): coros.append(_safe_send(ws, payload, clients))
await asyncio.gather(*coros)
async def _safe_send(ws, payload: str, clients: set):
try: await ws.send(payload)
except Exception:
@@ -132,15 +126,10 @@ async def _safe_send(ws, payload: str, clients: set):
except Exception: pass
def websocket_server_process(shared_data: dict, imc_q: multiprocessing.Queue, ws_q: multiprocessing.Queue):
"""
Entrypoint for the separate process that runs the asyncio-based websocket server.
"""
# create the asyncio loop and run server
async def runner():
clients = set()
async def handler_wrapper(websocket: ServerConnection):
# register client
clients.add(websocket)
try: await ws_handler(websocket, shared_data, imc_q, ws_q)
finally: