Fix displayed idle and online time, add CHANGES files, and some code clean up
[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 <input type=button id=offset value="AutoUpdate" onclick="autoupdate();">
16 <script src="/js/jquery.min.js"></script>
17 <script src="/js/crel.js"></script>
18 <script src="/js/json.human.js"></script>
19 <script>
20
21      function convert(input, output) {
22         var output = document.getElementById("output"),
23             raw = document.getElementById("output-raw");
24         var node = JsonHuman.format(input);
25
26         output.innerHTML = "";
27         output.appendChild(node);
28         
29     }
30       
31 </script>       
32 <script>
33
34 function get_appropriate_ws_url()
35 {
36         var pcol;
37         var u = document.URL;
38   var m, s;
39   //document.writeln( u + "<br>" );
40   
41         /*
42          * We open the websocket encrypted if this page came on an
43          * https:// url itself, otherwise unencrypted
44          */
45
46         if (u.substring(0, 5) == "https") {
47                 pcol = "wss://";
48                 u = u.substr(8);
49         } else {
50                 pcol = "ws://";
51                 if (u.substring(0, 4) == "http")
52                         u = u.substr(7);
53         }
54
55         u = u.split('/');
56   m = u[0].split(':');
57         
58   /* + "/xxx" bit is for IE10 workaround */
59   /* ":7681" bit makes this function work even if this html file gets served from another server   */
60   /* browser may complain about it but it works in firefox 30.0. If you do this umurmurd_websocket */
61   /* will just act as the websocket server. I will make a reduced down version of the server if    */
62   /* enough people request it                                                                      */
63   return pcol + m[0] + ":7681" + "/xxx";
64 }
65         var socket_json;
66   var json_data;
67
68         if (typeof MozWebSocket != "undefined") {
69                 socket_json = new MozWebSocket(get_appropriate_ws_url(),
70                                    "umurmurd-json-protocol");
71         } else {
72                 socket_json = new WebSocket(get_appropriate_ws_url(),
73                                    "umurmurd-json-protocol");
74         }
75
76   
77                 socket_json.onopen = function() {
78       socket_json.send("update\n");
79                 } 
80                 socket_json.onmessage = function (jmsg) {
81                    
82         json_data = JSON.parse(jmsg.data);
83         
84         convert(json_data, output);
85    
86     }
87                 socket_json.onclose = function(){
88         
89                 }      
90 function update() {
91         socket_json.send("update\n");
92 }
93 function autoupdate() {
94         socket_json.send("autoupdate\n");
95 }
96 </script>
97 </body>
98 </html>