-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQLC.lbe
125 lines (120 loc) · 4.57 KB
/
QLC.lbe
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
[extension_name]
QLC Plus (Deprecated)
[insert_external]
<div>
<span id="toqlcclient" class="disconnected">Not connected.</span>
<button onclick="refreshFunctions()" type="button">Refresh Functions</button>
<div id="function-list">Functions:</div>
</div>
[insert_command]
lioranboardclient.send('{"type":"MESSAGE","topic":"ExtensionCommand","name":"QLC+ Set Function","boxcount":3,"boxname1":"FunctionId","boxtype1":"integer", "boxname2":"Visible|1|0|toogle|","boxtype2":"string","boxname3":"ForceOthersToStop","boxtype3":"boolean"}');
lioranboardclient.send('{"type":"MESSAGE","topic":"ExtensionCommand","name":"QLC+ Get Function Status","boxcount":2,"boxname1":"FunctionId","boxtype1":"integer","boxname2":"Variable","boxtype2":"string",}');
//lioranboardclient.send('{"type":"MESSAGE","topic":"ExtensionCommand","name":"QLC+ Get Functions"}');
[insert_hook]
case "QLC+SetFunction": {
QLCSetFunction(LioranBoardJSON.FunctionId, LioranBoardJSON.Visible, LioranBoardJSON.ForceOthersToStop)
} break
case "QLC+GetFunctionStatus": {
variableForStatus = LioranBoardJSON.variable;
qlcclient.send("QLC+API|getFunctionStatus|" + LioranBoardJSON.FunctionId);
} break
// case "QLC+GetFunctions": {
// qlcclient.send("QLC+API|getFunctionsList");
// } break
[insert_script]
//main connection to Q Light Controller +
var lastFunctionId;
var variableForStatus;
var isAskingForFunctionStatus = false;
let functions = [];
connecttoqlc()
function connecttoqlc() {
var urlQlc = "ws://127.0.0.1:9999/qlcplusWS";
qlcclient = (new WebSocket(urlQlc));
qlcclient.binaryType = "arraybuffer";
//reconnect on disconnect
qlcclient.onclose = function (event) {
ConnectionStatus("toqlcclient", "disconnected", "Disconnected from QLC+.")
lioranboardclient.send(JSON.stringify({ "type": "MESSAGE", "topic": "AlertMessage", "message": "Disconnected from QLC+, attempting to reconnect in 10 seconds." }));
setTimeout(function () { connecttoqlc(); }, 10000);
};
//notice that connection is established
qlcclient.onopen = function (event) {
ConnectionStatus("toqlcclient", "connected", "Connected to QLC+.")
lioranboardclient.send(JSON.stringify({ "type": "MESSAGE", "topic": "AlertMessage", "message": "Connected to QLC+." }));
refreshFunctions();
};
qlcclient.onmessage = function (ev) {
var msgParams = ev.data.split("|");
console.log("QLC Message: " + ev.data);
if (msgParams[0] === "QLC+API") {
if (isAskingForFunctionStatus && msgParams[1] == "getFunctionStatus") {
switch (msgParams[2]) {
case "Stopped":
qlcclient.send("QLC+API|setFunctionStatus|" + lastFunctionId + "|1");
break;
case "Running":
qlcclient.send("QLC+API|setFunctionStatus|" + lastFunctionId + "|0");
break;
case "Undefined":
lioranboardclient.send(JSON.stringify({ "type": "MESSAGE", "topic": "AlertMessage", "message": "Asked QLC+ for not existing function status." }));
break;
}
isAskingForFunctionStatus = false;
lastFunctionId = undefined;
}
else if (msgParams[1] == "getFunctionStatus") {
lioranboardclient.send(JSON.stringify({ "type": "MESSAGE", "topic": "SetVariable", "variable": variableForStatus, "value": msgParams[2] }));
variableForStatus = undefined;
}
else if (msgParams[1] == "getFunctionsList") {
for (var i = 2; i < msgParams.length; i = i + 2) {
functions.push({ "Id": msgParams[i], "Name": msgParams[i + 1] });
}
//lioranboardclient.send(JSON.stringify({ "type": "MESSAGE", "topic": "PopupMessage", "message": JSON.stringify(strings) }));
var listDiv = document.getElementById('function-list');
var ul = document.createElement('ul');
for (var i = 0; i < functions.length; ++i)
{
var li = document.createElement('li');
li.innerHTML = functions[i].Id + " - " + functions[i].Name;
ul.appendChild(li);
}
listDiv.appendChild(ul);
}
}
};
};
function QLCSetFunction(functionId, Visible, ForceOthersToStop) {
if(ForceOthersToStop)
{
QLCDisableFunctions();
}
switch (Visible) {
case "toogle":
isAskingForFunctionStatus = true;
lastFunctionId = functionId;
qlcclient.send("QLC+API|getFunctionStatus|" + functionId);
break;
default:
qlcclient.send("QLC+API|setFunctionStatus|" + functionId + "|"+ Visible);
break;
}
}
function QLCDisableFunctions() {
if(functions.length > 0){
functions.forEach((elem,index) =>
{
qlcclient.send("QLC+API|setFunctionStatus|"+elem.Id+"|0");
})
}
}
function refreshFunctions(){
var listDiv = document.getElementById('function-list');
listDiv.innerHTML = '';
functions = [];
qlcclient.send("QLC+API|getFunctionsList");
}
[insert_over]
[force]
transmitter = "1"