mirror of
https://github.com/radio95-rnt/RadioPlayer.git
synced 2026-07-30 15:59:16 +02:00
skipc
This commit is contained in:
@@ -255,6 +255,7 @@
|
|||||||
document.getElementById("server-status").textContent = "connected";
|
document.getElementById("server-status").textContent = "connected";
|
||||||
reconnectDelay = 1000;
|
reconnectDelay = 1000;
|
||||||
ws.send(JSON.stringify({action:"get_toplay"}));
|
ws.send(JSON.stringify({action:"get_toplay"}));
|
||||||
|
ws.send(JSON.stringify({action:"skipc"}));
|
||||||
});
|
});
|
||||||
|
|
||||||
ws.addEventListener("close", () => {
|
ws.addEventListener("close", () => {
|
||||||
@@ -289,6 +290,7 @@
|
|||||||
} else if(msg.event === "new_track"){
|
} else if(msg.event === "new_track"){
|
||||||
applyTrackState(msg.data);
|
applyTrackState(msg.data);
|
||||||
ws.send(JSON.stringify({action:"get_toplay"}));
|
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 === "progress") applyProgressState(msg.data);
|
||||||
else if(msg.event === "toplay") {
|
else if(msg.event === "toplay") {
|
||||||
Queue = msg.data.data || [];
|
Queue = msg.data.data || [];
|
||||||
|
|||||||
+1
-12
@@ -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"}))
|
else: await websocket.send(json.dumps({"error": "unknown action"}))
|
||||||
|
|
||||||
async def broadcast_worker(ws_q: multiprocessing.Queue, clients: set):
|
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()
|
loop = asyncio.get_event_loop()
|
||||||
while True:
|
while True:
|
||||||
msg = await loop.run_in_executor(None, ws_q.get)
|
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)
|
payload = json.dumps(msg)
|
||||||
if clients:
|
if clients:
|
||||||
coros = []
|
coros = []
|
||||||
for ws in list(clients):
|
for ws in list(clients): coros.append(_safe_send(ws, payload, clients))
|
||||||
coros.append(_safe_send(ws, payload, clients))
|
|
||||||
await asyncio.gather(*coros)
|
await asyncio.gather(*coros)
|
||||||
|
|
||||||
|
|
||||||
async def _safe_send(ws, payload: str, clients: set):
|
async def _safe_send(ws, payload: str, clients: set):
|
||||||
try: await ws.send(payload)
|
try: await ws.send(payload)
|
||||||
except Exception:
|
except Exception:
|
||||||
@@ -132,15 +126,10 @@ async def _safe_send(ws, payload: str, clients: set):
|
|||||||
except Exception: pass
|
except Exception: pass
|
||||||
|
|
||||||
def websocket_server_process(shared_data: dict, imc_q: multiprocessing.Queue, ws_q: multiprocessing.Queue):
|
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():
|
async def runner():
|
||||||
clients = set()
|
clients = set()
|
||||||
|
|
||||||
async def handler_wrapper(websocket: ServerConnection):
|
async def handler_wrapper(websocket: ServerConnection):
|
||||||
# register client
|
|
||||||
clients.add(websocket)
|
clients.add(websocket)
|
||||||
try: await ws_handler(websocket, shared_data, imc_q, ws_q)
|
try: await ws_handler(websocket, shared_data, imc_q, ws_q)
|
||||||
finally:
|
finally:
|
||||||
|
|||||||
Reference in New Issue
Block a user