hello3: Add verb 'after'
[src/app-framework-binder.git] / test / AFB.html
1 <html>
2 <head>
3     <title>Test of AFB Echo</title>
4     <script type="text/javascript" src="AFB.js"></script>
5     <script type="text/javascript">
6         var afb = new AFB("api", "hello");
7         var ws;
8
9         function onopen() {
10                 document.getElementById("main").style.visibility = "visible";
11                 document.getElementById("connected").innerHTML = "Connected to WebSocket server";
12                 ws.onevent("*", gotevent);
13         }
14         function onabort() {
15                 document.getElementById("main").style.visibility = "hidden";
16                 document.getElementById("connected").innerHTML = "Connected Closed";
17         }
18         function init() {
19                 ws = new afb.ws(onopen, onabort);
20         }
21         function replyok(obj) {
22                 document.getElementById("output").innerHTML = "OK: "+JSON.stringify(obj);
23         }
24         function replyerr(obj) {
25                 document.getElementById("output").innerHTML = "ERROR: "+JSON.stringify(obj);
26         }
27         function gotevent(obj) {
28                 document.getElementById("outevt").innerHTML = JSON.stringify(obj);
29         }
30         function sendform() {
31                 var api = document.getElementById("api").value;
32                 var verb = document.getElementById("verb").value;
33                 var message = document.getElementById("message").value;
34                 try {
35                         var data = JSON.parse(message);
36                         ws.call(api+"/"+verb, data).then(replyok, replyerr);
37                 } catch(e) {
38                         document.getElementById("output").innerHTML = "INVALID JSON ("+e+"): "+message;
39                 }
40         }
41     </script>
42
43 <body onload="init();">
44     <h1>WebSocket Echo</h1>
45     <div id="connected">Not Connected</div>
46     <div id="main" style="visibility:hidden">
47     <a href="monitoring/monitor.html" target="_blank">Monitoring</a><br/>
48     <form>
49       API: <input type="text" id="api" value="hello" size="80"/><br/>
50       VERB: <input type="text" id="verb" value="ping" size="80"/><br/>
51       DATA: <input type="text" id="message" value="" size="80" /><br/>
52       <input type="button" value="send" onclick="sendform()"/><br/>
53       Server says... <div id="output"></div>
54       Events: <div id="outevt"></div>
55     </form>
56     </div>
57