<head>
<script src="../../lib/autobahn.min.js"></script>
<script src="../../cloudeebus/cloudeebus.js"></script>
+ <script type="text/javascript">
+ function evalScript() {
+ eval(
+ "var lambda = function() {" +
+ document.getElementById('script').value +
+ "};" +
+ "lambda();"
+ );
+ }
+ </script>
</head>
<body>
<center><h1>cloudeebus</h1></center>
<br>
- <textarea cols="80" rows=24 id="script">
+ <textarea style="width:80%" rows="32" id="script">
+var manifest = {
+ name: "cloudeebus",
+ key: "secret",
+ permissions: [
+ "org.freedesktop.DBus",
+ "org.freedesktop.Notifications"
+ ]
+};
+
cloudeebus.log = function(msg) {
document.getElementById("log").innerHTML += msg + "\n";
}
-function logBusNames(busNames) {
- for (var i=0; i<busNames.length; i++) {
- cloudeebus.log(busNames[i]);
- }
-}
-
-var proxy, interval;
-
-function connectSuccess() {
- var bus = cloudeebus.SessionBus();
- bus.listNames(logBusNames);
- handler = bus.getObject("org.gnome.ScreenSaver", "/org/gnome/ScreenSaver");
- handler.connectToSignal("org.gnome.ScreenSaver", "ActiveChanged", successCB, errorCB);
- proxy = bus.getObject("org.gnome.ScreenSaver", "/", lock, errorCB);
-}
-
-function unLock() {
- proxy.SetActive(false, successCB, errorCB);
- clearInterval(interval);
+function errorCB(error) {
+ cloudeebus.log("error: " + error + "\n");
}
-function lock() {
- proxy.SetActive(true, lockOk, errorCB);
+function logCB(result) {
+ cloudeebus.log(JSON.stringify(result));
}
-function lockOk(res) {
- interval = setInterval(unLock,3000);
+function gotNotifProxy(proxy) {
+ for (var ifproxy in proxy.interfaceProxies)
+ cloudeebus.log(ifproxy);
+ proxy.getInterface("org.freedesktop.Notifications").Notify("Cloudeebus",0,"","Cloudeebus says:", "Hello, world !", [], {}, 0);
}
-function successCB(res) {
- cloudeebus.log("got result: " + res + "\n");
+function gotBusProxy(proxy) {
+ proxy.ListNames().then(logCB, errorCB);
}
-function errorCB(error) {
- cloudeebus.log("error: " + error + "\n");
+function connectSuccess() {
+ cloudeebus.SessionBus().getObject("org.freedesktop.DBus", "/org/freedesktop/DBus", gotBusProxy, errorCB);
+ cloudeebus.SessionBus().getObject("org.freedesktop.Notifications", "/org/freedesktop/Notifications", gotNotifProxy, errorCB);
}
-cloudeebus.connect("ws://localhost:9000", connectSuccess, errorCB);
+cloudeebus.connect("ws://localhost:9000", manifest, connectSuccess, errorCB);
</textarea>
<br>
- <input type="button" value="run script" onclick="eval(document.getElementById('script').value)"/>
+ <input type="button" value="run script" onclick="evalScript()"/>
<input type="button" value="clear log" onclick="document.getElementById('log').innerHTML='';"/>
<br>
- <pre id="log" style="height: 20em; overflow-y: scroll; background-color: #faa;"></pre>
+ <pre id="log" style="height: 20em; overflow-x: auto; overflow-y: auto; background-color: #faa;"></pre>
</body>
</html>