File: Test_Web_API.html

package info (click to toggle)
qlcplus 4.14.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 58,644 kB
  • sloc: cpp: 182,867; javascript: 7,764; xml: 2,453; ansic: 2,120; sh: 1,716; python: 634; ruby: 606; makefile: 23
file content (570 lines) | stat: -rw-r--r-- 19,614 bytes parent folder | download | duplicates (2)
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
<!DOCTYPE html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>QLC+ Web API Test</title>
<script type="text/javascript">

// the WebSocket instance
var websocket;
var isConnected = false;
// the websocket host location
var wshost = "http://127.0.0.1:9999";

// helper function to send QLC+ API commands
function requestAPI(cmd)
{
  if (isConnected === true)
    websocket.send("QLC+API|" + cmd);
  else
    alert("You must connect to QLC+ WebSocket first!");
}

// helper function to send a QLC+ API with one parameter.
// The specified parameter is not a value, but a CSS object
// from which a value is retrieved (usually a <input> box)
function requestAPIWithParam(cmd, paramObjName)
{
  var obj = document.getElementById(paramObjName);
  if (obj)
  {
    if (isConnected === true)
      websocket.send("QLC+API|" + cmd + "|" + obj.value);
    else
      alert("You must connect to QLC+ WebSocket first!");
  }
}

function requestAPIWith2Params(cmd, paramObjName, param2ObjName)
{
  var obj1 = document.getElementById(paramObjName);
  var obj2 = document.getElementById(param2ObjName);
  if (obj1 && obj2)
  {
    if (isConnected === true)
      websocket.send("QLC+API|" + cmd + "|" + obj1.value + "|" + obj2.value);
    else
      alert("You must connect to QLC+ WebSocket first!");
  }
}

function requestChannelsRange(cmd, uniObjName, addressObjName, rangeObjName)
{
  var uniObj = document.getElementById(uniObjName);
  var addrObj = document.getElementById(addressObjName);
  var rangeObj = document.getElementById(rangeObjName);
  if (uniObj && addrObj && rangeObj)
  {
    if (isConnected === true)
      websocket.send("QLC+API|" + cmd + "|" + uniObj.value + "|" + addrObj.value + "|" + rangeObj.value);
    else
      alert("You must connect to QLC+ WebSocket first!");
  }
}

function setSimpleDeskChannel(addressObjName, channelValueObjName)
{
  var addrObj = document.getElementById(addressObjName);
  var valObj = document.getElementById(channelValueObjName);
  if (addrObj && valObj)
  {
    if (isConnected === true)
      websocket.send("CH|" + addrObj.value + "|" + valObj.value);
    else
      alert("You must connect to QLC+ WebSocket first!");
  }
}

function vcWidgetSetValue(wIDObjName, wValueObjName)
{
  var wObj = document.getElementById(wIDObjName);
  var valObj = document.getElementById(wValueObjName);
  if (wObj && valObj)
  {
    if (isConnected === true)
      websocket.send(wObj.value + "|" + valObj.value);
    else
      alert("You must connect to QLC+ WebSocket first!");
  }
}

function vcCueListControl(clIDObjName, clOpObjName, clStepObjName)
{
  var clObj = document.getElementById(clIDObjName);
  var opObj = document.getElementById(clOpObjName);
  var stepObj = document.getElementById(clStepObjName);
  if (clObj && opObj)
  {
    if (isConnected === true)
    {
      if (opObj.value === "STEP")
        websocket.send(clObj.value + "|" + opObj.value + "|" + stepObj.value);
      else
        websocket.send(clObj.value + "|" + opObj.value);
    }
    else
      alert("You must connect to QLC+ WebSocket first!");
  }
}

function vcFrameControl(frIDObjName, frOperation)
{
  var frObj = document.getElementById(frIDObjName);
  var opObj = document.getElementById(frOperation);

  if (frObj && opObj)
  {
    if (isConnected === true)
    {
        websocket.send(frObj.value + "|" + opObj.value);
    }
    else
      alert("You must connect to QLC+ WebSocket first!");
  }
}

function vcAnimationWidgetControl(animIDObjName, controlIDObjName)
{
  var animObj = document.getElementById(animIDObjName);
  var controlIDObj = document.getElementById(controlIDObjName);

  if (animObj && controlIDObj)
  {
    if (isConnected === true)
    {
        websocket.send(animObj.value + "|MATRIX_PUSHBUTTON|" + controlIDObj.value);
    }
    else
      alert("You must connect to QLC+ WebSocket first!");
  }
}

function connectToWebSocket(host) {
  var url = 'ws://' + host + '/qlcplusWS';
  websocket = new WebSocket(url);
  // update the host information
  wshost = "http://" + host;

  websocket.onopen = function(ev) {
    //alert("QLC+ connection successful");
    document.getElementById('connStatus').innerHTML = "<font color=green>Connected</font>";
    isConnected = true;
  };

  websocket.onclose = function(ev) {
    alert("QLC+ connection lost!");
  };

  websocket.onerror = function(ev) {
    alert("QLC+ connection error!");
  };

  // WebSocket message handler. This is where async events
  // will be shown or processed as needed
  websocket.onmessage = function(ev) {
    // Uncomment the following line to display the received message
    //alert(ev.data);

    // Event data is formatted as follows: "QLC+API|API name|arguments"
    // Arguments vary depending on the API called

    var msgParams = ev.data.split('|');

    if (msgParams[0] === "QLC+API")
    {
      if (msgParams[1] === "getFunctionsNumber")
      {
        document.getElementById('getFunctionsNumberBox').innerHTML = msgParams[2];
      }
      // Arguments is an array formatted as follows:
      // Function ID|Function name|Function ID|Function name|...
      else if (msgParams[1] === "getFunctionsList")
      {
        var tableCode = "<table class='apiTable'><tr><th>ID</th><th>Name</th></tr>";
        for (i = 2; i < msgParams.length; i+=2)
        {
            tableCode = tableCode + "<tr><td>" + msgParams[i] + "</td><td>" + msgParams[i + 1] + "</td></tr>";
        }
        tableCode += "</table>";
        document.getElementById('getFunctionsListBox').innerHTML = tableCode;
      }
      else if (msgParams[1] === "getFunctionType")
      {
        document.getElementById('getFunctionTypeBox').innerHTML = msgParams[2];
      }
      else if (msgParams[1] === "getFunctionStatus")
      {
        document.getElementById('getFunctionStatusBox').innerHTML = msgParams[2];
      }
      else if (msgParams[1] === "getWidgetsNumber")
      {
        document.getElementById('getWidgetsNumberBox').innerHTML = msgParams[2];
      }
      else if (msgParams[1] === "getWidgetsList")
      {
        // Arguments is an array formatted as follows:
        // Widget ID|Widget name|Widget ID|Widget name|...
        var tableCode = "<table class='apiTable'><tr><th>ID</th><th>Name</th></tr>";
        for (i = 2; i < msgParams.length; i+=2)
        {
            tableCode = tableCode + "<tr><td>" + msgParams[i] + "</td><td>" + msgParams[i + 1] + "</td></tr>";
        }
        tableCode += "</table>";
        document.getElementById('getWidgetsListBox').innerHTML = tableCode;
      }
      else if (msgParams[1] === "getWidgetType")
      {
        document.getElementById('getWidgetTypeBox').innerHTML = msgParams[3];
      }
      else if (msgParams[1] === "getWidgetStatus")
      {
        var status = msgParams[3];
        if (msgParams[2] === "PLAY")
            status = msgParams[2] + "(Step: " + msgParams[3] + ")";
        document.getElementById('getWidgetStatusBox').innerHTML = status;
      }
      else if (msgParams[1] === "getWidgetSubIdList")
      {
        // Arguments is an array formatted as follows:
        // Widget ID|Preset ID|Preset Type|Preset ID|Preset Type|...
        var tableCode = "<table class='apiTable'><tr><th>ID</th><th>Type</th></tr>";
        for (i = 2; i < msgParams.length; i+=2)
        {
            tableCode = tableCode + "<tr><td>" + msgParams[i] + "</td><td>" + msgParams[i + 1] + "</td></tr>";
        }
        tableCode += "</table>";
        document.getElementById('getWidgetSubIdBox').innerHTML = tableCode;
      }
      else if (msgParams[1] === "getChannelsValues")
      {
        var tableCode = "<table class='apiTable'><tr><th>Index</th><th>Value</th><th>Type</th></tr>";
        for (i = 2; i < msgParams.length; i+=3)
        {
            tableCode = tableCode + "<tr><td>" + msgParams[i] + "</td><td>" + msgParams[i + 1] + "</td><td>" + msgParams[i + 2] + "</td></tr>";
        }
        tableCode += "</table>";
        document.getElementById('requestChannelsRangeBox').innerHTML = tableCode;
      }
    }
  };
};

function loadProject () {
  var formAction = wshost + "/loadProject";
  document.getElementById('lpForm').action = formAction;
}

</script>

<style type="text/css">

body {
  background-color: #45484d;
  color: white;
  font:normal 18px/1.2em sans-serif;
}

iframe {
  position: absolute;
  display: block;

  height: 100%;
  width: 100%;
}

#prjBox {
  position: absolute;
  width: 50%;
  height: 70%;
  margin-top: 0px;
  margin-left: 47%;
}

.apiTable {
  border-collapse: collapse;
}

.apiTable th {
  font-size: 20px;
  color: white;
  background-color: #3da1ff;
  border: solid 1px grey;
  padding: 10px 0 10px 0 !important;
}

.apiTable tr {
  font-size: 14px;
  border: solid 1px grey;
}

.apiTable td {
  border: solid 1px grey;
  padding: 5px 5px 5px 5px;
  margin: 0 5px 0 5px;
}

.apiHeader {
  font-size: 18px;
  background-color: #3bc247;
  padding: 10px 0 10px 0 !important;
}

.apiButton {
  display: table-cell;
  vertical-align: middle;
  text-align: center;
  font-weight: bold;
  color: black;
  cursor:pointer;
  height: 30px;
  padding: 0 10px 0 10px;
  background: #7497b6;
}

.apiButton:hover {
  background: #87b1d5;
}

.resultBox {
  display: table-cell;
  vertical-align: middle;
  text-align: center;
  color: #000;
  width: 150px;
  height: 30px;
  background-color: #aaaaaa;
  border-radius: 6px;
}

</style>

<body>

<h2>Q Light Controller+ Web API test page</h2>

<!-- ############## Project box to display what QLC+ is doing ####################### -->
<div id="prjBox"><iframe name="projectFrame" src="" id="projectFrame"></iframe></div>

<!-- ############## Websocket connection code ####################### -->
QLC+ IP:
<input type="text" id="qlcplusIP" value="127.0.0.1:9999"/>
<input type="button" value="Connect" onclick="javascript:connectToWebSocket(document.getElementById('qlcplusIP').value);">
<div id="connStatus" style="display: inline-block;"><font color=red>Not connected</font></div>
<br><br>

<!-- ############## Project load code ####################### -->
<form id="lpForm" onsubmit="loadProject()" method="POST" enctype="multipart/form-data" target="projectFrame">
Load a project:
<input id="loadTrigger" type="file" onchange="document.getElementById('submitTrigger').click();" name="qlcprj">
<input id="submitTrigger" type="submit">
</form>
<br><br>

<!-- ############## Individual API tests ####################### -->

<table class="apiTable" width=45%>
 <tr>
  <th width=30%><b>API Function</b></th>
  <th width=30%><b>Description</b></th>
  <th width=40%><b>Result</b></th>
 </tr>

<!-- ############## Channels API tests ####################### -->

 <tr>
  <td colspan="3" align="center" class="apiHeader"><b>Channels APIs</b></td>
 </tr>

 <tr>
  <td>
    <div class="apiButton" onclick="javascript:requestChannelsRange('getChannelsValues', 'chUniIdx', 'chDMXaddr', 'chRange');">getChannelsValues</div><br>
    Universe index: <input id="chUniIdx" type="text" value="1" size="6"><br>
    DMX start address: <input id="chDMXaddr" type="text" value="1" size="6"><br>
    Channels count: <input id="chRange" type="text" value="16" size="6">
  </td>
  <td>Retrieve the specified number of DMX values for the given universe, starting at the given address.
      Note that indices start from 1 and not from 0.</td>
  <td><div id="requestChannelsRangeBox" style="height: 150px; overflow-y: scroll;"></div></td>
 </tr>

<!-- ############## Functions API tests ####################### -->

 <tr>
  <td colspan="3" align="center" class="apiHeader"><b>Function APIs</b></td>
 </tr>

 <tr>
  <td><div class="apiButton" onclick="javascript:requestAPI('getFunctionsNumber');">getFunctionsNumber</div></td>
  <td>Retrieve the number of functions loaded</td>
  <td><div id="getFunctionsNumberBox" class="resultBox"></div></td>
 </tr>

 <tr>
  <td><div class="apiButton" onclick="javascript:requestAPI('getFunctionsList');">getFunctionsList</div></td>
  <td>Retrieve the list of functions with their ID and name</td>
  <td><div id="getFunctionsListBox" style="height: 150px; overflow-y: scroll;"></div></td>
 </tr>

 <tr>
  <td>
    <div class="apiButton" onclick="javascript:requestAPIWithParam('getFunctionType', 'fTypeID');">getFunctionType</div><br>
    Function ID: <input id="fTypeID" type="text" value="0" size="6">
  </td>
  <td>Retrieve the type of a function with the given ID</td>
  <td><div id="getFunctionTypeBox" class="resultBox"></div></td>
 </tr>

 <tr>
  <td>
    <div class="apiButton" onclick="javascript:requestAPIWithParam('getFunctionStatus', 'gfFuncID');">getFunctionStatus</div><br>
    Function ID: <input id="gfFuncID" type="text" value="0" size="6">
  </td>
  <td>Retrieve the running status of a function with the given ID. Possible values are "Running", "Stopped" and "Undefined"</td>
  <td><div id="getFunctionStatusBox" class="resultBox"></div></td>
 </tr>

 <tr>
  <td>
    <div class="apiButton" onclick="javascript:requestAPIWith2Params('setFunctionStatus', 'sfFuncID', 'sfStatus');">setFunctionStatus</div><br>
    Function ID: <input id="sfFuncID" type="text" value="0" size="6"><br>
    Status: <input id="sfStatus" type="text" value="0" size="6">
  </td>
  <td>Set the running status of a function with the given ID. Possible values are: 0 (stop) or 1 (run)</td>
  <td></td>
 </tr>

<!-- ############## Widgets API tests ####################### -->

 <tr>
  <td colspan="3" align="center" class="apiHeader"><b>Virtual Console Widget APIs</b></td>
 </tr>

 <tr>
  <td><div class="apiButton" onclick="javascript:requestAPI('getWidgetsNumber');">getWidgetsNumber</div></td>
  <td>Retrieve the number of widgets loaded</td>
  <td><div id="getWidgetsNumberBox" class="resultBox"></div></td>
 </tr>
 <tr>
  <td><div class="apiButton" onclick="javascript:requestAPI('getWidgetsList');">getWidgetsList</div></td>
  <td>Retrieve the list of Virtual Console Widgets with their ID and name</td>
  <td><div id="getWidgetsListBox" style="height: 150px; overflow-y: scroll;"></div></td>
 </tr>

 <tr>
  <td>
    <div class="apiButton" onclick="javascript:requestAPIWithParam('getWidgetType', 'wTypeID');">getWidgetType</div><br>
    Widget ID: <input id="wTypeID" type="text" value="0" size="6">
  </td>
  <td>Retrieve the type of a Virtual Console Widget with the given ID</td>
  <td><div id="getWidgetTypeBox" class="resultBox"></div></td>
 </tr>

 <tr>
  <td>
    <div class="apiButton" onclick="javascript:requestAPIWithParam('getWidgetStatus', 'wStatusID');">getWidgetStatus</div><br>
    Widget ID: <input id="wStatusID" type="text" value="0" size="6">
  </td>
  <td>Retrieve the status of a Virtual Console Widget with the given ID</td>
  <td><div id="getWidgetStatusBox" class="resultBox"></div></td>
 </tr>

 <tr>
  <td>
    <div class="apiButton" onclick="javascript:requestAPIWithParam('getWidgetSubIdList', 'wSubListID');">getWidgetSubIdList</div><br>
    Widget ID: <input id="wSubListID" type="text" value="0" size="6">
  </td>
  <td>Retrieve information about sub-widgets (aka presets) of a Virtual Console Widget with the given ID</td>
  <td><div id="getWidgetSubIdBox" style="height: 150px; overflow-y: scroll;"></div></td>
 </tr>

 <tr>
  <td>
   <div class="apiButton" onclick="javascript:vcAnimationWidgetControl('animWidgetID', 'animControlID');">Animation widget control</div><br>
   Animation widget ID: <input id="animWidgetID" type="text" value="0" size="6"><br>
   Control ID: <input id="animControlID" type="text" value="0" size="6">
  </td>
  <td colspan="2">
    This API demonstrates how to control Virtual Console Animation widget.
    The parameters to be used are:<br>
    <b>Animation widget ID</b>: The Animation widget ID as retrieved with the 'getWidgetsList' API<br>
    <b>Control ID</b>: The Animation control ID of preset buttons.
  </td>
 </tr>

<!-- ############## High rate API tests ####################### -->

 <tr>
  <td colspan="3" align="center" class="apiHeader"><b>High rate APIs</b></td>
 </tr>
 <tr>
  <td colspan="3">Due to the nature of some type of transmissions (for example a slider changing rapidly),
                  there are a few WebSocket operations stripped down to avoid useless overhead of data.<br>
                  So, instead of transmitting every time the "QLC+API|API name" information, direct calls
                  are here used to accomplish fast operations.
  </td>
 </tr>

 <tr>
  <td>
   <div class="apiButton" onclick="javascript:setSimpleDeskChannel('sdDMXAddress', 'sdDMXValue');">Simple Desk channel set</div><br>
   Absolute DMX address: <input id="sdDMXAddress" type="text" value="1" size="6"><br>
   Value: <input id="sdDMXValue" type="text" value="100" size="6">
  </td>
  <td colspan="2">
   This API sets the value of a single channel of the QLC+ Simple Desk. The parameters to send are:<br>
   <b>Absolute DMX address</b>: this is the address of the DMX channel you want to set. It is absolute in the sense
   that the universe information is implicit in the address itself. So for example addresses on the first
   universe will range from 1 to 512, while addresses on the second universe will range from 513 to 1024,
   and so on.<br>
   <b>Value</b>: the value of the DMX channel to set in a range from 0 to 255.
  </td>
 </tr>

 <tr>
  <td>
   <div class="apiButton" onclick="javascript:vcWidgetSetValue('basicWidgetID', 'basicWidgetValue');">Basic widget value set</div><br>
   Widget ID: <input id="basicWidgetID" type="text" value="0" size="6"><br>
   Value: <input id="basicWidgetValue" type="text" value="255" size="6">
  </td>
  <td colspan="2">
    This API is the direct way to set a Virtual Console widget value. It can be used for Buttons, Sliders and
    Audio Triggers. The value to set depends on the widget type itself. Buttons will only support values 255
    (= button is pressed) and 0 (= button is released), Audio triggers will support values 0 (= off) and 255 (= on)
    and Sliders will accept all the values in the 0-255 range.
  </td>
 </tr>

 <tr>
  <td>
   <div class="apiButton" onclick="javascript:vcCueListControl('clWidgetID', 'clOperation', 'clStep');">Cue list control</div><br>
   Cue List ID: <input id="clWidgetID" type="text" value="0" size="6"><br>
   Operation: <input id="clOperation" type="text" value="PLAY" size="6"><br>
   Step (optional): <input id="clStep" type="text" value="1" size="6">
  </td>
  <td colspan="2">
    This API demonstrates how to control a Virtual Console Cue List widget. The parameters to be used are:<br>
    <b>Cue List ID</b>: The Cue List widget ID as retrieved with the 'getWidgetsList' API<br>
    <b>Operation</b>: The Cue List operation to perform. Possible values are 'PLAY', 'NEXT', 'PREV' and 'STEP'.
    Only the 'STEP' operation requires a third parameter. The 'PLAY' operation will stop the Cue List if called
    twice.<br>
    <b>Step</b>: The Cue List step index to play. Index starts from 0.
  </td>
 </tr>

 <tr>
  <td>
   <div class="apiButton" onclick="javascript:vcFrameControl('frWidgetID', 'frOperation');">Multipage frame control</div><br>
   Frame ID: <input id="frWidgetID" type="text" value="0" size="6"><br>
   Operation: <input id="frOperation" type="text" value="NEXT_PG" size="6">
  </td>
  <td colspan="2">
    This API demonstrates how to change page of a Virtual Console Frame widget in multipage mode.
    The parameters to be used are:<br>
    <b>Frame ID</b>: The Frame widget ID as retrieved with the 'getWidgetsList' API<br>
    <b>Operation</b>: The Frame operation to perform. Accepted values are 'NEXT_PG' and 'PREV_PG'.
  </td>
 </tr>

</table>

</body>
</html>