From a7a6ae4be87ee9178905ab784d84a4c0a8303f9b Mon Sep 17 00:00:00 2001 From: fulup Date: Sun, 23 Jul 2017 01:23:37 +0200 Subject: Added TLV->DBscale into HAL control 1st Working version of HAL ctl-get with TLV Cleanup HTML5 test pages WIP Only --- htdocs/AudioBinding.js | 74 ++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 54 insertions(+), 20 deletions(-) (limited to 'htdocs/AudioBinding.js') diff --git a/htdocs/AudioBinding.js b/htdocs/AudioBinding.js index 7105b20..e000a70 100644 --- a/htdocs/AudioBinding.js +++ b/htdocs/AudioBinding.js @@ -1,8 +1,30 @@ var afb = new AFB("api", "mysecret"); var ws; - var halapi="HALNotSelected"; + var sndcard="HALNotSelected"; var evtidx=0; + function syntaxHighlight(json) { + if (typeof json !== 'string') { + json = JSON.stringify(json, undefined, 2); + } + json = json.replace(/&/g, '&').replace(//g, '>'); + 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 '' + match + ''; + }); + } + function getParameterByName(name, url) { if (!url) { url = window.location.href; @@ -25,8 +47,8 @@ var sndname=getParameterByName("sndname"); if (!sndname) sndname="PCH"; - var quiet=getParameterByName("quiet"); - if (!quiet) quiet="99"; + var mode=getParameterByName("mode"); + if (!mode) mode="99"; @@ -54,12 +76,12 @@ function replyok(obj) { console.log("replyok:" + JSON.stringify(obj)); - document.getElementById("output").innerHTML = "OK: "+JSON.stringify(obj); + document.getElementById("output").innerHTML = "OK: "+ syntaxHighlight(obj); } function replyerr(obj) { console.log("replyerr:" + JSON.stringify(obj)); - document.getElementById("output").innerHTML = "ERROR: "+JSON.stringify(obj); + document.getElementById("output").innerHTML = "ERROR: "+ syntaxHighlight(obj); } function gotevent(obj) { @@ -78,7 +100,8 @@ // On button click from HTML page function callbinder(api, verb, query) { console.log ("subscribe api="+api+" verb="+verb+" query=" +query); - document.getElementById("question").innerHTML = "apicall: " + api+"/"+verb +" ("+ JSON.stringify(query)+")"; + var question = urlws +"/" +api +"/" +verb + "?query=" + JSON.stringify(query); + document.getElementById("question").innerHTML = syntaxHighlight(question); ws.call(api+"/"+verb, query).then(replyok, replyerr); } @@ -89,27 +112,38 @@ // onlick update selected HAL api selectobj.onclick=function(){ - halapi= this.value; - console.log ("New Default HAL=" + halapi); + sndcard= this.value; + console.log ("Default Selection=" + sndcard); }; function gotit (result) { - // display response as for normal onclick action - replyok(result); - var response=result.response; + // display response as for normal onclick action + replyok(result); + var response=result.response; - // fulfill select with avaliable active HAL - for (idx=0; idx