agent server sample: un-comment autobahn and cloudeebus scripts inclusion
[contrib/cloudeebus.git] / doc / agent / server.html
index 4baded4..aa8ca3e 100644 (file)
@@ -1,8 +1,11 @@
 <!DOCTYPE html>
 <html>
     <head>
-        <script src="../../lib/autobahn.min.js"></script>
-        <script src="../../cloudeebus/cloudeebus.js"></script>
+        <!-- Do not load autobahn or cloudeebus if already provided by Crosswalk browser extensions. -->
+        <script type="text/javascript">
+          typeof cloudeebus != 'undefined' ||
+          document.write(unescape('%3Cscript src=%27../../lib/autobahn.min.js%27%3E %3C/script%3E %3Cscript src=%27../../cloudeebus/cloudeebus.js%27%3E%3C/script%3E'));
+        </script>
         <script type="text/javascript">
                function evalScript(field) {
                        eval(
@@ -27,7 +30,7 @@ var manifest = {
 };
 
 
-var sampleXml= '<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"\n"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">\n<node><interface name="org.cloudeebus.Sample1"><method name="Release"></method><method name="Add"><arg type="i" name="arg1"/><arg type="i" name="arg2"/><arg type="i" name="result" direction="out"/></method><method name="Variant"><arg type="a{sv}" name="arg1"/><arg type="a{sv}" name="result" direction="out"/></method><signal name="ResultChanged"><arg type="v" name="result"/></signal></interface><interface name="org.cloudeebus.Sample2"><method name="Div"><arg type="d" name="arg1"/><arg type="d" name="arg2"/><arg type="d" name="result" direction="out"/></method></interface></node>';
+var sampleXml= '<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"\n"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">\n<node><interface name="org.cloudeebus.Sample"><method name="Add"><arg type="i" name="arg1"/><arg type="i" name="arg2"/><arg type="i" name="result" direction="out"/></method><method name="Div"><arg type="d" name="arg1"/><arg type="d" name="arg2"/><arg type="d" name="result" direction="out"/></method><method name="Variant"><arg type="a{sv}" name="arg1"/><arg type="a{sv}" name="result" direction="out"/></method><signal name="ResultChanged"><arg type="v" name="result"/></signal></interface></node>';
 
 cloudeebus.log = function(msg) {
   document.getElementById("log").innerHTML += msg + "\n";
@@ -51,9 +54,6 @@ sampleObjectHandler = {
     cloudeebus.log("Get and return :" + JSON.stringify(a));
     return a;
   }, 
-  Release: function() {
-    gService.remove().then(logCB, errorCB);
-  },
   Div: function(a,b) {
     cloudeebus.log("Div " + a + " / " + b);
        this.ResultChanged(a/b);
@@ -63,24 +63,34 @@ sampleObjectHandler = {
 
 function addAgent(service) {
   window.gService = service;
-  var agent = new cloudeebus.Agent(service.name, "/org/cloudeebus/Sample", sampleObjectHandler, sampleXml);
+  var agent = new cloudeebus.Agent("/org/cloudeebus/Sample", sampleObjectHandler, sampleXml);
   cloudeebus.log("Adding agent " + agent.objectPath + " on " + service.name + ", mapped on Javascript object: 'sampleObjectHandler");
   service.addAgent(agent).then(logCB, errorCB);
+  window.gAgent = agent;
 }
 
 function connectSuccess() {
   cloudeebus.SessionBus().addService("org.cloudeebus.Sample").then(addAgent, errorCB);
 }
 
-cloudeebus.connect("ws://localhost:9003", manifest, connectSuccess, errorCB);
+if (!window.gService)
+  cloudeebus.connect("ws://localhost:9003", manifest, connectSuccess, errorCB);
 </textarea>
                <br>
 -              <input type="button" value="run script" onclick="evalScript('script')"/>
                <input type="button" value="clear log" onclick="document.getElementById('log').innerHTML='';"/>
                <br>
+<textarea style="width:80%" rows="7" id="removeCmd">
+function removeService() {
+       window.gService.remove();
+    cloudeebus.log("Service removed");
+       window.gService = null;
+}
+
+window.gService.removeAgent(window.gAgent).then(removeService, null);
+</textarea>
+               <br>
                <input type="button" value="Unregister service" onclick="evalScript('removeCmd')"/>
--              <input id="removeCmd" type="text" value="window.gService.remove()"/>
                <br>
                <pre id="log" style="height: 20em; overflow-x: auto; overflow-y: auto; background-color: #faa;"></pre>
    </body>