<!DOCTYPE html> <html> <head> <!-- include AutobahnJS .. that's all you need --> <script src="http://autobahn.s3.amazonaws.com/js/autobahn.min.js"></script> <script> // WAMP session object var sess = null; window.onload = function() { var wsuri; if (window.location.protocol === "file:") { wsuri = "ws://localhost:9000"; } else { wsuri = "ws://" + window.location.hostname + ":9000"; } // connect to WAMP server ab.connect(wsuri, // WAMP session was established function (session) { sess = session; console.log("Connected to " + wsuri); test(); }, // WAMP session is gone function (code, reason) { sess = null; if (code == ab.CONNECTION_UNSUPPORTED) { window.location = "http://autobahn.ws/unsupportedbrowser"; } else { console.log(reason); } } ); }; function test() { // Call a remote procedure // sess.call("http://example.com/simple/calc#add", 23, 7).then( function (res) { // RPC returned successfully console.log("RPC result: " + res); }, function (error) { // An error occured: // error.uri : The URI of the error // error.desc : Human readable, for developers and logging // error.details : Any error details (optional) console.log("RPC error: " + error.desc); } ); // Call a remote procedure, and a 2nd one with the result of the first // sess.call("http://example.com/simple/calc#sub", 15, 5).then( function (res) { // call a remote procedure sess.call("http://example.com/simple/calc#mul", res, res).then( function (res) { console.log("RPC result: " + res); } ); } ); }; </script> </head> <body> <h1>RPCs with AutobahnJS - Example 1</h1> <noscript> <span style="color: #f00; font-weight: bold;"> You need to turn on JavaScript. </span> </noscript> <p> Open development console (press F12) to watch. </p> </body> </html>