625d3a1dccad23a5a58a49a37f58b1b215848e74
[contrib/cloudeebus.git] / doc / agent / client.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 style="width:80%" rows="32" id="script">
21 var manifest = {
22         name: "cloudeebus",
23         key: "secret",
24         permissions: [
25                 "org.cloudeebus.Sample"
26         ]
27 };
28
29
30 cloudeebus.log = function(msg) {
31   document.getElementById("log").innerHTML += msg + "\n";
32 }
33
34 function logCB(result) {
35   cloudeebus.log(JSON.stringify(result));
36 }
37
38 function errorCB(error) {
39   cloudeebus.log(error.desc ? error.desc : error);
40 }
41
42 function gotDivResult(result) {
43   cloudeebus.log("gotDivResult: " + result);
44 }
45
46 function gotAddResult(result) {
47   cloudeebus.log("gotAddResult: " + result);
48   window.sampleProxy.Div(result,3.33).then(gotDivResult,errorCB);
49 }
50
51 function signalHandler(result) {
52   cloudeebus.log("signal 'ResultChanged': " + result);
53 }
54
55 function gotProxy(proxy) {
56         proxy.connectToSignal("org.cloudeebus.Sample", "ResultChanged", signalHandler);
57         logCB(proxy);
58         window.sampleProxy = proxy;
59         testProxy();
60 }
61
62 function testProxy() {
63         var dictionary = {Name: "Mickey",
64                                          Sisters: [""], 
65                                          Married: true,
66                                          Divorced: 0,
67                                          Friends: ["Donald", "Dingo"],
68                                          Others: [""]};
69         window.sampleProxy.Variant(dictionary).then(logCB,errorCB);
70           
71         logCB('Addition');
72         for (var i=-2; i<2; i++)
73           window.sampleProxy.Add(i,i*2).then(gotAddResult,errorCB);
74 }
75
76 function connectSuccess() {
77         cloudeebus.SessionBus().getObject("org.cloudeebus.Sample", "/org/cloudeebus/Sample", gotProxy, errorCB);
78 }
79
80 if (!window.sampleProxy)
81         cloudeebus.connect("ws://localhost:9002", manifest, connectSuccess, errorCB);
82 else
83         testProxy();
84
85 </textarea>
86                 <br>
87                 <input type="button" value="run script" onclick="evalScript()"/>
88                 <input type="button" value="clear log" onclick="document.getElementById('log').innerHTML='';"/>
89                 <br>
90                 <pre id="log" style="height: 20em; overflow-x: auto; overflow-y: auto; background-color: #faa;"></pre>
91    </body>
92 </html>