<!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() { sess.subscribe("http://example.com/simple", onEvent); } function onEvent(topicUri, event) { console.log(topicUri); console.log(event); } function publishEvent() { sess.publish("http://example.com/simple", {'foo': 'bar', 'baz': 23}); } </script> </head> <body> <h1>PubSub with AutobahnJS - Example 1</h1> <noscript> <span style="color: #f00; font-weight: bold;"> You need to turn on JavaScript. </span> </noscript> <button onclick="publishEvent()">Publish</button> <p> Open development console (press F12) to watch. </p> </body> </html>