Merge pull request #24 from fpaut/agent_future
[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 var sampleProxy = null;
31
32 cloudeebus.log = function(msg) {
33   document.getElementById("log").innerHTML += msg + "\n";
34 }
35
36 function logCB(result) {
37   cloudeebus.log(JSON.stringify(result));
38 }
39
40 function errorCB(error) {
41   cloudeebus.log(error.desc ? error.desc : error);
42 }
43
44 function gotDictResult(result) {
45   cloudeebus.log("gotDictResult: " + JSON.stringify(result));
46   cloudeebus.log("Name: " + result.Name);
47 }
48
49 function gotDivResult(result) {
50   cloudeebus.log("gotDivResult: " + result);
51   var dictionary = {Name: "Mickey",
52                                  Sisters: [""], 
53                                  Married: true,
54                                  Divorced: 0,
55                                  Friends: ["Donald", "Dingo"],
56                                  Others: [""]};
57   sampleProxy.Variant(dictionary).then(gotDictResult,errorCB);  
58 //  sampleProxy.Release();
59 }
60
61 function gotAddResult(result) {
62   cloudeebus.log("gotAddResult: " + result);
63   logCB('Divide by 3.33');
64   sampleProxy.Div(result,3.33).then(gotDivResult,errorCB);
65 }
66
67 function signalHandler(result) {
68   cloudeebus.log("signal 'ResultChanged': " + result);
69 }
70
71 function gotProxy(proxy) {
72         sampleProxy = proxy;
73    logCB(sampleProxy);
74   if (0) {
75     proxy.Release();
76     return;
77    } else {
78           proxy.connectToSignal("org.cloudeebus.Sample1", "ResultChanged", signalHandler);
79           logCB('Addition');
80           
81           for (var i=-10; i<10; i++)
82             proxy.Add(i,i*2).then(gotAddResult,errorCB);
83   }
84   
85 }
86
87 function connectSuccess() {
88   cloudeebus.SessionBus().getObject("org.cloudeebus.Sample", "/org/cloudeebus/Sample", gotProxy, errorCB);
89 }
90
91 cloudeebus.connect("ws://localhost:9002", manifest, connectSuccess, errorCB);
92 </textarea>
93                 <br>
94                 <input type="button" value="run script" onclick="evalScript()"/>
95                 <input type="button" value="clear log" onclick="document.getElementById('log').innerHTML='';"/>
96                 <br>
97                 <pre id="log" style="height: 20em; overflow-x: auto; overflow-y: auto; background-color: #faa;"></pre>
98    </body>
99 </html>