1 var afb = new AFB("api", "mysecret");
5 function getParameterByName(name, url) {
7 url = window.location.href;
9 name = name.replace(/[\[\]]/g, "\\$&");
10 var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
11 results = regex.exec(url);
12 if (!results) return null;
13 if (!results[2]) return '';
14 return decodeURIComponent(results[2].replace(/\+/g, " "));
17 // default soundcard is "PCH"
18 var devid=getParameterByName("devid");
19 if (!devid) devid="hw:0";
21 var sndname=getParameterByName("sndname");
22 if (!sndname) sndname="PCH";
24 var quiet=getParameterByName("quiet");
25 if (!quiet) quiet="99";
28 ws = new afb.ws(onopen, onabort);
32 document.getElementById("main").style.visibility = "visible";
33 document.getElementById("connected").innerHTML = "Binder WS Active";
34 document.getElementById("connected").style.background = "lightgreen";
35 ws.onevent("*", gotevent);
39 document.getElementById("main").style.visibility = "hidden";
40 document.getElementById("connected").innerHTML = "Connected Closed";
41 document.getElementById("connected").style.background = "red";
45 function replyok(obj) {
46 console.log("replyok:" + JSON.stringify(obj));
47 document.getElementById("output").innerHTML = "OK: "+JSON.stringify(obj);
50 function replyerr(obj) {
51 console.log("replyerr:" + JSON.stringify(obj));
52 document.getElementById("output").innerHTML = "ERROR: "+JSON.stringify(obj);
55 function gotevent(obj) {
56 console.log("gotevent:" + JSON.stringify(obj));
57 document.getElementById("outevt").innerHTML = (evtidx++) +": "+JSON.stringify(obj);
60 function send(message) {
61 var api = document.getElementById("api").value;
62 var verb = document.getElementById("verb").value;
63 document.getElementById("question").innerHTML = "subscribe: "+api+"/"+verb + " (" + JSON.stringify(message) +")";
64 ws.call(api+"/"+verb, {data:message}).then(replyok, replyerr);
68 function callbinder(api, verb, query) {
69 console.log ("subscribe api="+api+" verb="+verb+" query=" +query);
70 document.getElementById("question").innerHTML = "apicall: " + api+"/"+verb +" ("+ JSON.stringify(query)+")";
71 ws.call(api+"/"+verb, query).then(replyok, replyerr);