0
1
mirror of https://github.com/radio95-rnt/RadioPlayer.git synced 2026-02-26 21:53:54 +01:00

imc stuff

This commit is contained in:
2025-12-14 10:59:13 +01:00
parent 6c3a96cf63
commit decb38ce91
2 changed files with 13 additions and 20 deletions

View File

@@ -111,7 +111,6 @@
</div> </div>
<script> <script>
const WS_URL = `ws://192.168.1.93:3001`;
let ws = null; let ws = null;
let reconnectDelay = 1000; let reconnectDelay = 1000;
@@ -127,7 +126,7 @@
function connectWs(){ function connectWs(){
document.getElementById("server-status").textContent = "connecting..."; document.getElementById("server-status").textContent = "connecting...";
ws = new WebSocket(WS_URL); ws = new WebSocket("ws://192.168.1.93:3001");
ws.addEventListener("open", () => { ws.addEventListener("open", () => {
document.getElementById("server-status").textContent = "connected"; document.getElementById("server-status").textContent = "connected";
@@ -195,7 +194,7 @@
const elapsed = Number(payload.elapsed || 0); const elapsed = Number(payload.elapsed || 0);
const total = Number(payload.total || payload.real_total || 1) || 1; const total = Number(payload.total || payload.real_total || 1) || 1;
const realtotal = Number(payload.real_total || payload.total || 1) || 1; const realtotal = Number(payload.real_total || payload.total || 1) || 1;
const percent = Math.max(0, Math.min(100, (elapsed/total)*100)); const percent = Math.max(0, Math.min(100, (elapsed/realtotal)*100));
document.getElementById("prog-fill").style.width = percent + "%"; document.getElementById("prog-fill").style.width = percent + "%";
document.getElementById("time-label").textContent = formatTime(elapsed) + " / " + formatTime(total) + ` (${formatTime(realtotal)})`; document.getElementById("time-label").textContent = formatTime(elapsed) + " / " + formatTime(total) + ` (${formatTime(realtotal)})`;
currentTrackIndex = payload.index; currentTrackIndex = payload.index;
@@ -346,11 +345,8 @@
} }
document.getElementById("skip-btn").addEventListener("click", () => { document.getElementById("skip-btn").addEventListener("click", () => {
if(ws && ws.readyState === WebSocket.OPEN){ if(ws && ws.readyState === WebSocket.OPEN) ws.send(JSON.stringify({action:"skip"}));
ws.send(JSON.stringify({action:"skip"})); else console.error("WebSocket not connected.");
} else {
console.error("WebSocket not connected.");
}
}); });
document.getElementById("readd-btn").addEventListener("click", () => { document.getElementById("readd-btn").addEventListener("click", () => {
@@ -361,7 +357,7 @@
const selected = playlist[selectedPlaylistIndex]; const selected = playlist[selectedPlaylistIndex];
if(!selected) { alert("Invalid selection"); return; } if(!selected) { alert("Invalid selection"); return; }
const path = (selected.official ? "" : "!") + selected.path; const path = (selected.official ? "" : "!") + selected.path;
sendAddToToplay([path]); ws.send(JSON.stringify({action:"add_to_toplay", songs: [path]}))
Array.from(document.getElementById("playlist-box").children).forEach(c => c.classList.remove("selected")); Array.from(document.getElementById("playlist-box").children).forEach(c => c.classList.remove("selected"));
}); });
@@ -389,17 +385,10 @@
} }
} }
if (fullPath) { if (fullPath) ws.send(JSON.stringify({action:"add_to_toplay", songs: [fullPath]}))
sendAddToToplay([fullPath]); else alert("Please select a file to add.");
} else {
alert("Please select a file to add.");
}
}); });
function sendAddToToplay(songs){
if(ws && ws.readyState === WebSocket.OPEN) ws.send(JSON.stringify({action:"add_to_toplay", songs: songs}))
}
connectWs(); connectWs();
</script> </script>
</body> </body>

View File

@@ -6,7 +6,7 @@ import asyncio
import websockets import websockets
from websockets import ServerConnection, Request, Response, Headers from websockets import ServerConnection, Request, Response, Headers
from . import Track, PlayerModule, Path from . import Track, PlayerModule, Path, BaseIMCModule
MAIN_PATH_DIR = Path("/home/user/mixes") MAIN_PATH_DIR = Path("/home/user/mixes")
@@ -32,7 +32,7 @@ async def ws_handler(websocket: ServerConnection, shared_data: dict, imc_q: mult
imc_q.put({"name": name, "data": data, "key": key}) imc_q.put({"name": name, "data": data, "key": key})
start = time.monotonic() start = time.monotonic()
result = None result = None
while time.monotonic() - start < 2: while time.monotonic() - start < 1.5:
if key in shared_data: if key in shared_data:
result = shared_data.pop(key) result = shared_data.pop(key)
break break
@@ -216,6 +216,10 @@ class Module(PlayerModule):
self.data["progress"] = json.dumps(payload) self.data["progress"] = json.dumps(payload)
try: self.ws_q.put({"event": "progress", "data": payload}) try: self.ws_q.put({"event": "progress", "data": payload})
except Exception: pass except Exception: pass
def imc_data(self, source: BaseIMCModule, source_name: str | None, data: object, broadcast: bool) -> object:
try: self.ws_q.put({"event": "imc", "data": {"name": source_name, "data": data, "broadcast": broadcast}})
except Exception: pass
def shutdown(self): def shutdown(self):
self.ipc_thread_running = False self.ipc_thread_running = False