swap rtp, and also update user count on disconnect

This commit is contained in:
2026-05-08 17:05:49 +02:00
parent dc05db7e28
commit 4747e55c30
2 changed files with 24 additions and 12 deletions
+18 -9
View File
@@ -86,16 +86,25 @@ def update_rds(track_name: str):
artist = artist.encode("radiodatasystem", "replace")
rtp = []
rtp.append(1) # type 2
rtp.append(prt.find(title)) # start 2
rtp.append(len(title) - 1) # len 2
rtp.append(4) # type 1
rtp.append(prt.find(artist)) # start 1
rtp.append(len(artist) - 1) # len 1
def do_title():
rtp.append(1) # type 2
rtp.append(prt.find(title)) # start 2
rtp.append(len(title) - 1) # len 2
def do_artist():
rtp.append(4) # type 1
rtp.append(prt.find(artist)) # start 1
rtp.append(len(artist) - 1) # len 1
if len(artist) > len(title):
do_artist()
do_title()
else:
#len(artist) < len(title)
do_title()
do_artist()
rtp = [j_size if i_rt > j_size else i_rt for i_rt,j_size in zip(rtp, [255,0x3f,0x3f,255,0x3f,0x1f])]
rtp = ','.join(list(map(str, rtp)))
rtp_str = ','.join(list(map(str, rtp)))
prt = prt[:64]
@@ -104,14 +113,14 @@ def update_rds(track_name: str):
f.settimeout(1.0)
uecp_frame = uecp.frame.UECPFrame()
uecp_frame.add_command(RT_Set(prt))
uecp_frame.add_command(ASCII(f"RTP={rtp}".encode()))
uecp_frame.add_command(ASCII(f"RTP={rtp_str}".encode()))
data = uecp_frame.encode()
f.sendto(data, udp_host)
logger.debug("Sending", str(data))
except Exception as e: logger.error(f"Error updating RDS: {e}")
return prt.decode("radiodatasystem", "ignore"), rtp
return prt.decode("radiodatasystem", "ignore"), rtp_str
class Module(PlayerModule):
def on_new_track(self, index: int, track: Track, next_track: Track | None):
+6 -3
View File
@@ -134,13 +134,15 @@ 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, ws_q))
await asyncio.gather(*coros)
async def _safe_send(ws, payload: str, clients: set):
async def _safe_send(ws, payload: str, clients: set, ws_q: multiprocessing.Queue):
try: await ws.send(payload)
except Exception:
try: clients.discard(ws)
try:
clients.discard(ws)
await asyncio.get_event_loop().run_in_executor(None, ws_q.put, {"event": "users", "data": len(clients)})
except Exception: pass
def websocket_server_process(shared_data: dict, imc_q: multiprocessing.Queue, ws_q: multiprocessing.Queue):
@@ -154,6 +156,7 @@ def websocket_server_process(shared_data: dict, imc_q: multiprocessing.Queue, ws
finally:
await websocket.close(1001, "")
clients.discard(websocket)
await asyncio.get_event_loop().run_in_executor(None, ws_q.put, {"event": "users", "data": len(clients)})
async def process_request(websocket: ServerConnection, request: Request):
if request.path == "/ws":
if not "upgrade" in request.headers.get("Connection", "").lower():