diff --git a/modules/jingle.py b/modules/jingle.py index 0c24b3b..bd79dc5 100644 --- a/modules/jingle.py +++ b/modules/jingle.py @@ -43,11 +43,11 @@ class Module2(PlayerModule): def imc(self, imc: InterModuleCommunication) -> None: super().imc(imc) self._imc.register(self, "jingle") - def imc_data(self, source: BaseIMCModule, source_name: str | None, data: object, broadcast: bool) -> object: + def imc_data(self, source: BaseIMCModule, source_name: str | None, data: bool, broadcast: bool) -> object: if broadcast: return jingle = self.primary if self.secondary and (random.randint(1,3) == 1): jingle = random.choice(self.secondary) - return self._imc.send(self, "activemod", {"action": "add_to_toplay", "songs": [f"!{jingle}"]}) + return self._imc.send(self, "activemod", {"action": "add_to_toplay", "songs": [f"!{jingle}"], "top": bool(data)}) options = Path("/home/user/Jingiel.mp3"), [Path("/home/user/jing2.opus"), Path("Jing3.opus")] module = Module2(*options) diff --git a/modules/web.html b/modules/web.html index 6658ae9..0fe2127 100644 --- a/modules/web.html +++ b/modules/web.html @@ -81,6 +81,7 @@ + @@ -417,6 +418,10 @@ if(ws && ws.readyState === WebSocket.OPEN) ws.send(JSON.stringify({action:"jingle"})); else console.error("WebSocket not connected."); }); + document.getElementById("jingle2-btn").addEventListener("click", () => { + if(ws && ws.readyState === WebSocket.OPEN) ws.send(JSON.stringify({action:"jingle", top: true})); + else console.error("WebSocket not connected."); + }); document.getElementById("clear-btn").addEventListener("click", () => {ws.send(JSON.stringify({action:"clear_toplay"}))}); @@ -470,12 +475,12 @@ if (e.target.tagName === "INPUT") return; if (e.key === "Enter") { - const added = addSelectedFileToQueue(false); + const added = addSelectedFileToQueue(e.shiftKey); if (added) e.preventDefault(); } if (e.key === "s") ws.send(JSON.stringify({action:"skip"})); if (e.key === "n") ws.send(JSON.stringify({action:"skip_next"})); - if (e.key === "j") ws.send(JSON.stringify({action:"jingle"})); + if (e.key === "j") ws.send(JSON.stringify({action:"jingle", top: e.shiftKey})); }); setTimeout(connectWs, 100) diff --git a/modules/web.py b/modules/web.py index a94157b..7687a8e 100644 --- a/modules/web.py +++ b/modules/web.py @@ -69,7 +69,7 @@ async def ws_handler(websocket: ServerConnection, shared_data: dict, imc_q: mult if result is None: await websocket.send(json.dumps({"error": "timeout", "code": 504})) else: await websocket.send(json.dumps({"data": result, "event": "skip_next"})) elif action == "jingle": - result = await get_imc("jingle", None) + result = await get_imc("jingle", msg.get("top", False)) if result is None: await websocket.send(json.dumps({"error": "timeout", "code": 504})) else: await websocket.send(json.dumps(result))