Refactor source tree and add packaging
[contrib/cloudeebus.git] / doc / sample / cloudeebus.html
1 <!DOCTYPE html>
2 <html>
3     <head>
4         <script src="./autobahn.min.js"></script>
5         <script src="../cloudeebus/cloudeebus.js"></script>
6     </head>
7    <body>
8         <center><h1>cloudeebus</h1></center>
9         <br>
10                 <textarea cols="80" rows=24 id="script">
11 cloudeebus.log = function(msg) {
12   document.getElementById("log").innerHTML += msg + "\n";
13 }
14
15 function logBusNames(busNames) {
16   for (var i=0; i<busNames.length; i++) {
17     cloudeebus.log(busNames[i]);
18   }
19 }
20
21 var proxy, interval;
22
23 function connectSuccess() {
24   var bus = cloudeebus.SessionBus();
25   bus.listNames(logBusNames);
26   handler = bus.getObject("org.gnome.ScreenSaver", "/org/gnome/ScreenSaver");
27   handler.connectToSignal("org.gnome.ScreenSaver", "ActiveChanged", successCB, errorCB);
28   proxy = bus.getObject("org.gnome.ScreenSaver", "/", lock, errorCB);
29 }
30
31 function unLock() {
32   proxy.SetActive(false, successCB, errorCB);
33   clearInterval(interval);
34 }
35
36 function lock() {
37   proxy.SetActive(true, lockOk, errorCB);
38 }
39
40 function lockOk(res) {
41   interval = setInterval(unLock,3000);
42 }
43
44 function successCB(res) {
45   cloudeebus.log("got result: " + res + "\n");
46 }
47
48 function errorCB(error) {
49   cloudeebus.log("error: " + error + "\n");
50 }
51
52 cloudeebus.connect("ws://localhost:9000", connectSuccess, errorCB);
53 </textarea>
54                 <br>
55                 <input type="button" value="run script" onclick="eval(document.getElementById('script').value)"/>
56                 <input type="button" value="clear log" onclick="document.getElementById('log').innerHTML='';"/>
57                 <br>
58                 <pre id="log" style="height: 20em; overflow-y: scroll; background-color: #faa;"></pre>
59    </body>
60 </html>