ae24d01bd32d30b67edce085b23e579b04f38de0
[umurmur.git] / shm_utils / umurmurd-websocket / web / mon_umurmurd.html
1 <!DOCTYPE HTML>
2 <html lang="en">
3
4 <head>
5 <meta charset='utf-8'>
6 <title>uMurmurd Websocket demo HTML page</title>
7 <link rel="stylesheet" href="css/mon_umurmurd.css" >
8 <link rel="stylesheet" href="css/json.human.css" >
9 </head>
10
11 <body>
12
13 <div id="output"> </div>
14 <input type=button id=offset value="Update" onclick="update();">
15 <script src="/js/jquery.min.js"></script>
16 <script src="/js/crel.js"></script>
17 <script src="/js/json.human.js"></script>
18 <script>
19
20      function convert(input, output) {
21         var output = document.getElementById("output"),
22             raw = document.getElementById("output-raw");
23         var node = JsonHuman.format(input);
24
25         output.innerHTML = "";
26         output.appendChild(node);
27         
28     }
29       
30 </script>       
31 <script>
32
33 function get_appropriate_ws_url()
34 {
35         var pcol;
36         var u = document.URL;
37   var m, s;
38   //document.writeln( u + "<br>" );
39   
40         /*
41          * We open the websocket encrypted if this page came on an
42          * https:// url itself, otherwise unencrypted
43          */
44
45         if (u.substring(0, 5) == "https") {
46                 pcol = "wss://";
47                 u = u.substr(8);
48         } else {
49                 pcol = "ws://";
50                 if (u.substring(0, 4) == "http")
51                         u = u.substr(7);
52         }
53
54         u = u.split('/');
55   m = u[0].split(':');
56         
57   /* + "/xxx" bit is for IE10 workaround */
58   /* ":7681" bit makes this function work even if this html file gets served from another server   */
59   /* browser may complain about it but it works in firefox 30.0. If you do this umurmurd_websocket */
60   /* will just act as the websocket server. I will make a reduced down version of the server if    */
61   /* enough people request it                                                                      */
62   return pcol + m[0] + ":7681" + "/xxx";
63 }
64         var socket_json;
65   var json_data;
66
67         if (typeof MozWebSocket != "undefined") {
68                 socket_json = new MozWebSocket(get_appropriate_ws_url(),
69                                    "umurmur-json-protocol");
70         } else {
71                 socket_json = new WebSocket(get_appropriate_ws_url(),
72                                    "umurmur-json-protocol");
73         }
74
75   
76                 socket_json.onopen = function() {
77       socket_json.send("update\n");
78                 } 
79                 socket_json.onmessage = function (jmsg) {
80                    
81         json_data = JSON.parse(jmsg.data);
82         
83         convert(json_data, output);
84    
85     }
86                 socket_json.onclose = function(){
87         
88                 }      
89 function update() {
90         socket_json.send("update\n");
91 }
92 </script>
93 </body>
94 </html>