aboutsummaryrefslogtreecommitdiffstats
path: root/htdocs
diff options
context:
space:
mode:
authorFulup Ar Foll <fulup@iot.bzh>2017-07-25 17:33:52 +0200
committerFulup Ar Foll <fulup@iot.bzh>2017-07-25 17:33:52 +0200
commita3cecd20f812c3fc71141a487443568c861c160a (patch)
treef7b1c23fd5af0385985ae3a2e3abf558ec5bc0f6 /htdocs
parentd00d127abd72f632b36db1619f6282a8e5c61798 (diff)
Update HTML test page to new template. Added Config file selection from UI.
Diffstat (limited to 'htdocs')
-rw-r--r--htdocs/AFB-websock.js7
-rw-r--r--htdocs/AudioBinding.js72
-rw-r--r--htdocs/UNICENS.html25
-rw-r--r--htdocs/Ucs2Binding.css7
-rw-r--r--htdocs/Ucs2Binding.js162
5 files changed, 189 insertions, 84 deletions
diff --git a/htdocs/AFB-websock.js b/htdocs/AFB-websock.js
index 08a7ffe..99ab3b8 100644
--- a/htdocs/AFB-websock.js
+++ b/htdocs/AFB-websock.js
@@ -1,7 +1,10 @@
+var urlws;
+var urlhttp;
+
AFB = function(base, initialtoken){
-var urlws = "ws://"+window.location.host+"/"+base;
-var urlhttp = "http://"+window.location.host+"/"+base;
+urlws = "ws://"+window.location.host+"/"+base;
+urlhttp = "http://"+window.location.host+"/"+base;
/*********************************************/
/**** ****/
diff --git a/htdocs/AudioBinding.js b/htdocs/AudioBinding.js
deleted file mode 100644
index 5f9ea24..0000000
--- a/htdocs/AudioBinding.js
+++ /dev/null
@@ -1,72 +0,0 @@
- var afb = new AFB("api", "mysecret");
- var ws;
- var evtidx=0;
-
- function getParameterByName(name, url) {
- if (!url) {
- url = window.location.href;
- }
- name = name.replace(/[\[\]]/g, "\\$&");
- var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
- results = regex.exec(url);
- if (!results) return null;
- if (!results[2]) return '';
- return decodeURIComponent(results[2].replace(/\+/g, " "));
- }
-
- // default soundcard is "PCH"
- var devid=getParameterByName("devid");
- if (!devid) devid="hw:0";
-
- var sndname=getParameterByName("sndname");
- if (!sndname) sndname="PCH";
-
- var quiet=getParameterByName("quiet");
- if (!quiet) quiet="99";
-
- function init() {
- ws = new afb.ws(onopen, onabort);
- }
-
- function onopen() {
- document.getElementById("main").style.visibility = "visible";
- document.getElementById("connected").innerHTML = "Binder WS Active";
- document.getElementById("connected").style.background = "lightgreen";
- ws.onevent("*", gotevent);
- }
-
- function onabort() {
- document.getElementById("main").style.visibility = "hidden";
- document.getElementById("connected").innerHTML = "Connected Closed";
- document.getElementById("connected").style.background = "red";
-
- }
-
- function replyok(obj) {
- console.log("replyok:" + JSON.stringify(obj));
- document.getElementById("output").innerHTML = "OK: "+JSON.stringify(obj);
- }
-
- function replyerr(obj) {
- console.log("replyerr:" + JSON.stringify(obj));
- document.getElementById("output").innerHTML = "ERROR: "+JSON.stringify(obj);
- }
-
- function gotevent(obj) {
- console.log("gotevent:" + JSON.stringify(obj));
- document.getElementById("outevt").innerHTML = (evtidx++) +": "+JSON.stringify(obj);
- }
-
- function send(message) {
- var api = document.getElementById("api").value;
- var verb = document.getElementById("verb").value;
- document.getElementById("question").innerHTML = "subscribe: "+api+"/"+verb + " (" + JSON.stringify(message) +")";
- ws.call(api+"/"+verb, {data:message}).then(replyok, replyerr);
- }
-
-
- function callbinder(api, verb, query) {
- console.log ("subscribe api="+api+" verb="+verb+" query=" +query);
- document.getElementById("question").innerHTML = "apicall: " + api+"/"+verb +" ("+ JSON.stringify(query)+")";
- ws.call(api+"/"+verb, query).then(replyok, replyerr);
- }
diff --git a/htdocs/UNICENS.html b/htdocs/UNICENS.html
index 73c1b66..11746c6 100644
--- a/htdocs/UNICENS.html
+++ b/htdocs/UNICENS.html
@@ -1,17 +1,22 @@
<html>
<head>
- <title>Hello world test</title>
+ <title>Unicens Simple Test</title>
+ <link rel="stylesheet" href="Ucs2Binding.css">
<script type="text/javascript" src="AFB-websock.js"></script>
- <script type="text/javascript" src="AudioBinding.js"></script>
+ <script type="text/javascript" src="Ucs2Binding.js"></script>
-
-<body onload="init();">
- <h1>Hello world test</h1>
- <button id="connected" onclick="init()">Binder WS Fail</button></li>
+<body onload="init('ucs2_config','unicens', 'listconfig');">
+ <h1>Unicens Simple Test</h1>
+
+ <button id="connected" onclick="init('ucs2_config','unicens', 'listconfig')">Binder WS Fail</button>
+ <br><br>
+ <b>Selected HAL </b>
+ <select id='ucs2_config'></select>
<br>
+
<ol>
- <li><button onclick="callbinder('UNICENS','initialise', {filename:'data/config_multichannel_audio_kit.xml'})">Parse XML and Start UNICENS</button></li>
+ <li><button onclick="callbinder('UNICENS','initialise', {filename:ucs2_config})">Parse XML and Start UNICENS</button></li>
<li><button onclick="callbinder('UNICENS','setvol', {channel:'master', volume: 255})">Set Master Volume to 255</button></li>
<li><button onclick="callbinder('unicens','setvol', {channel:'master', volume: 230})">Set Master Volume to 230</button></li>
<li><button onclick="callbinder('unicens','setvol', {channel:'master', volume: 215})">Set Master Volume to 215</button></li>
@@ -26,8 +31,8 @@
<br>
<div id="main" style="visibility:hidden">
<ol>
- <li>Question <div id="question"></div>
- <li>Response <div id="output"></div>
- <li>Events: <div id="outevt"></div>
+ <li>Question <pre id="question"></pre>
+ <li>Response <pre id="output"></pre>
+ <li>Events: <pre id="outevt"></pre>
</ol>
</div>
diff --git a/htdocs/Ucs2Binding.css b/htdocs/Ucs2Binding.css
new file mode 100644
index 0000000..1052aa7
--- /dev/null
+++ b/htdocs/Ucs2Binding.css
@@ -0,0 +1,7 @@
+pre {outline: 1px solid #ccc; padding: 5px; margin: 5px; }
+.string { color: green; }
+.number { color: darkorange; }
+.boolean { color: blue; }
+.null { color: magenta; }
+.key { color: red; }
+
diff --git a/htdocs/Ucs2Binding.js b/htdocs/Ucs2Binding.js
new file mode 100644
index 0000000..11b8a1a
--- /dev/null
+++ b/htdocs/Ucs2Binding.js
@@ -0,0 +1,162 @@
+ var afb = new AFB("api", "mysecret");
+ var ws;
+ var ucs2_config="ConfigNotSelected";
+ var evtidx=0;
+ var numid=0;
+
+ function syntaxHighlight(json) {
+ if (typeof json !== 'string') {
+ json = JSON.stringify(json, undefined, 2);
+ }
+ json = json.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
+ return json.replace(/("(\\u[a-zA-Z0-9]{4}|\\[^u]|[^\\"])*"(\s*:)?|\b(true|false|null)\b|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?)/g, function (match) {
+ var cls = 'number';
+ if (/^"/.test(match)) {
+ if (/:$/.test(match)) {
+ cls = 'key';
+ } else {
+ cls = 'string';
+ }
+ } else if (/true|false/.test(match)) {
+ cls = 'boolean';
+ } else if (/null/.test(match)) {
+ cls = 'null';
+ }
+ return '<span class="' + cls + '">' + match + '</span>';
+ });
+ }
+
+ function basename(path) {
+ return path.split('/').reverse()[0];
+ }
+
+ function getParameterByName(name, url) {
+ if (!url) {
+ url = window.location.href;
+ }
+ name = name.replace(/[\[\]]/g, "\\$&");
+ var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
+ results = regex.exec(url);
+ if (!results) return null;
+ if (!results[2]) return '';
+ return decodeURIComponent(results[2].replace(/\+/g, " "));
+ }
+
+ // default soundcard is "PCH"
+ var devid=getParameterByName("devid");
+ if (!devid) devid="hw:1";
+
+ var haldev=getParameterByName("haldev");
+ if (!haldev) haldev="scarlett-usb";
+
+ var sndname=getParameterByName("sndname");
+ if (!sndname) sndname="PCH";
+
+ var mode=getParameterByName("mode");
+ if (!mode) mode="0";
+
+
+
+
+ function replyok(obj) {
+ console.log("replyok:" + JSON.stringify(obj));
+ document.getElementById("output").innerHTML = "OK: "+ syntaxHighlight(obj);
+ }
+
+ function replyerr(obj) {
+ console.log("replyerr:" + JSON.stringify(obj));
+ document.getElementById("output").innerHTML = "ERROR: "+ syntaxHighlight(obj);
+ }
+
+ function gotevent(obj) {
+ console.log("gotevent:" + JSON.stringify(obj));
+ document.getElementById("outevt").innerHTML = (evtidx++) +": "+JSON.stringify(obj);
+ }
+
+ function send(message) {
+ var api = document.getElementById("api").value;
+ var verb = document.getElementById("verb").value;
+ document.getElementById("question").innerHTML = "subscribe: "+api+"/"+verb + " (" + JSON.stringify(message) +")";
+ ws.call(api+"/"+verb, {data:message}).then(replyok, replyerr);
+ }
+
+
+ // On button click from HTML page
+ function callbinder(api, verb, query) {
+ console.log ("subscribe api="+api+" verb="+verb+" query=" +query);
+ var question = urlws +"/" +api +"/" +verb + "?query=" + JSON.stringify(query);
+ document.getElementById("question").innerHTML = syntaxHighlight(question);
+ ws.call(api+"/"+verb, query).then(replyok, replyerr);
+ }
+
+
+ // Retreive Select value and Text from the binder
+ // Note: selection of value/text for a given context is huggly!!!
+ function querySelectList (elemid, api, verb, query) {
+
+ console.log("querySelectList elemid=%s api=%s verb=%s query=%s", elemid, api, verb, query);
+
+ var selectobj = document.getElementById(elemid);
+ if (!selectobj) {
+ console.log ("****** elemid=%s does not exit in HTML page ****", elemid);
+ return;
+ }
+
+ // onlick update selected HAL api
+ selectobj.onclick=function(){
+ ucs2_config= this.value;
+ console.log ("Default Selection=" + ucs2_config);
+ };
+
+ function gotit (result) {
+
+ // display response as for normal onclick action
+ replyok(result);
+ var response=result.response;
+
+ // fulfill select with avaliable active HAL
+ for (idx=0; idx<response.length; idx++) {
+ var opt = document.createElement('option');
+ var basename = response[idx].basename;
+ var dirpath = response[idx].dirpath;
+ var ext= basename.split('.').pop();
+
+ // Only propose XML files
+ if (ext.toLowerCase() === "xml") {
+ opt.text = basename;
+ opt.value = dirpath + "/" + basename;
+ selectobj.appendChild(opt);
+ }
+ }
+
+ ucs2_config= selectobj.value;
+ }
+
+ var question = urlws +"/"+api +"/" +verb + "?query=" + JSON.stringify(query);
+ document.getElementById("question").innerHTML = syntaxHighlight(question);
+
+ // request lowlevel ALSA to get API list
+ ws.call(api+"/"+verb, query).then(gotit, replyerr);
+ }
+
+
+ function init(elemid, api, verb, query) {
+
+ function onopen() {
+ // check for active HALs
+ querySelectList (elemid, api, verb, query);
+
+ document.getElementById("main").style.visibility = "visible";
+ document.getElementById("connected").innerHTML = "Binder WS Active";
+ document.getElementById("connected").style.background = "lightgreen";
+ ws.onevent("*", gotevent);
+ }
+
+ function onabort() {
+ document.getElementById("main").style.visibility = "hidden";
+ document.getElementById("connected").innerHTML = "Connected Closed";
+ document.getElementById("connected").style.background = "red";
+
+ }
+ ws = new afb.ws(onopen, onabort);
+ }