From a66632043620a84141e52d756eeff6af54093f7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20CHOMAZ?= Date: Mon, 23 Dec 2024 21:59:40 +0100 Subject: [PATCH] =?UTF-8?q?Cr=C3=A9ation=20du=20service=20d'interface=20en?= =?UTF-8?q?tre=20QLC+=20et=20BrainBlast?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- services/light-manager-DMX.js | 69 +++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 services/light-manager-DMX.js diff --git a/services/light-manager-DMX.js b/services/light-manager-DMX.js new file mode 100644 index 0000000..d99ebd3 --- /dev/null +++ b/services/light-manager-DMX.js @@ -0,0 +1,69 @@ +// websocket.js +let websocket; + +export function connectWebSocket(url) { + websocket = new WebSocket(url); + + websocket.onopen = () => { + console.log("WebSocket connection established"); + }; + + websocket.onclose = () => { + console.log("QLC+ connection is closed. Reconnect will be attempted in 1 second."); + setTimeout(() => { + connectWebSocket(url); + }, 1000); + }; + + websocket.onerror = (err) => { + console.error("QLC+ connection encountered error. Closing socket", err); + websocket.close(); + }; + + websocket.onmessage = (ev) => { + const message = ev.data.toString(); + const msgParams = message.split("|"); + + if (msgParams[1] === "BUTTON") { + //wsSetButtonState(msgParams[0], msgParams[2]); + } else if (msgParams[1] === "SLIDER") { + wsSetSliderValue(msgParams[0], msgParams[2], msgParams[3]); + } else if (msgParams[1] === "AUDIOTRIGGERS") { + wsSetAudioTriggersEnabled(msgParams[0], msgParams[2]); + } else if (msgParams[1] === "CUE") { + wsSetCueIndex(msgParams[0], msgParams[2]); + } else if (msgParams[1] === "CLOCK") { + wsUpdateClockTime(msgParams[0], msgParams[2]); + } else if (msgParams[1] === "FRAME") { + setFramePage(msgParams[0], msgParams[2]); + } else if (msgParams[1] === "getWidgetsList") { + console.log(msgParams) + } + }; + +} + +export function sendButtonPress(id, state) { + if (state == 1){ + websocket.send(id + "|255"); + // Quand un bouton est pressé, envoyez un message au serveur + console.log(`Button ${id} pressed and sent to server`); + } + if (state == 0){ + websocket.send(id + "|0"); + // Quand un bouton est pressé, envoyez un message au serveur + console.log(`Button ${id} released and sent to server`); + } +} + +export function sendCMD(cmd) { + websocket.send("QLC+CMD|" + cmd); +} + +export function requestAPI(cmd) +{ + if (isConnected === true) + websocket.send("QLC+API|" + cmd); + else + alert("You must connect to QLC+ WebSocket first!"); +}