documentation: show the manifest as part of the sample code
[contrib/cloudeebus.git] / doc / sample / cloudeebus.html
1 <!DOCTYPE html>
2 <html>
3     <head>
4         <script src="../../lib/autobahn.min.js"></script>
5         <script src="../../cloudeebus/cloudeebus.js"></script>
6         <script type="text/javascript">
7                 function evalScript() {
8                         eval(
9                                 "var lambda = function() {" +
10                                         document.getElementById('script').value +
11                                 "};" + 
12                                 "lambda();"
13                         );
14                 }
15         </script>
16     </head>
17    <body>
18         <center><h1>cloudeebus</h1></center>
19         <br>
20                 <textarea cols="80" rows=24 id="script">
21 var manifest = {
22         name: "cloudeebus",
23         key: "secret",
24         permissions: [
25                 "org.freedesktop.DBus",
26                 "org.freedesktop.Notifications"
27         ]
28 };
29
30 cloudeebus.log = function(msg) {
31   document.getElementById("log").innerHTML += msg + "\n";
32 }
33
34 function errorCB(error) {
35   cloudeebus.log("error: " + error + "\n");
36 }
37
38 function logCB(result) {
39   cloudeebus.log(JSON.stringify(result));
40 }
41
42 function gotNotifProxy(proxy) {
43   proxy.Notify("Cloudeebus",0,"","Cloudeebus says:", "Hello, world !", [], {}, 0);
44 }
45
46 function gotBusProxy(proxy) {
47   proxy.ListNames(logCB, errorCB);
48 }
49
50 function connectSuccess() {
51   cloudeebus.SessionBus().getObject("org.freedesktop.DBus", "/org/freedesktop/DBus", gotBusProxy, errorCB);
52   cloudeebus.SessionBus().getObject("org.freedesktop.Notifications", "/org/freedesktop/Notifications", gotNotifProxy, errorCB);
53 }
54
55 cloudeebus.connect("ws://localhost:9000", manifest, connectSuccess, errorCB);
56 </textarea>
57                 <br>
58                 <input type="button" value="run script" onclick="evalScript()"/>
59                 <input type="button" value="clear log" onclick="document.getElementById('log').innerHTML='';"/>
60                 <br>
61                 <pre id="log" style="height: 20em; overflow-x: auto; overflow-y: auto; background-color: #faa;"></pre>
62    </body>
63 </html>