websocket first version works
[src/app-framework-binder.git] / test / websock.html
1 <html>
2 <head>
3     <title>WebSocket Echo</title>
4     <script type="text/javascript" src="websock.js"></script>
5     <script type="text/javascript">
6         var ws;
7
8         function onopen() {
9                 document.getElementById("main").style.visibility = "visible";
10                 document.getElementById("connected").innerHTML = "Connected to WebSocket server";
11         }
12         function onabort() {
13                 document.getElementById("main").style.visibility = "hidden";
14                 document.getElementById("connected").innerHTML = "Connected Closed";
15         }
16         function init() {
17                 ws = new AfbWsItf("api", onopen, onabort, new AfbCtxItf("hello"));
18         }
19         function replyok(obj) {
20                 document.getElementById("output").innerHTML = "OK: "+JSON.stringify(obj);
21         }
22         function replyerr(obj) {
23                 document.getElementById("output").innerHTML = "ERROR: "+JSON.stringify(obj);
24         }
25         function send(message) {
26                 ws.call("hello", "ping", {data:message}, replyok, replyerr);
27         }
28     </script>
29
30 <body onload="init();">
31     <h1>WebSocket Echo</h1>
32     <div id="connected">Not Connected</div>
33     <div id="main" style="visibility:hidden">
34     Enter Message: <input type="text" name="message" value="" size="80" onchange="send(this.value)"/><br/>
35     Server says... <div id="output"></div>
36     </div>
37