Skip to content

Instantly share code, notes, and snippets.

@darkl
Created August 24, 2015 16:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save darkl/ab4003af525c4eb2500a to your computer and use it in GitHub Desktop.
Save darkl/ab4003af525c4eb2500a to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<body>
<h1>Hello WAMP</h1>
<p>Open JavaScript console to watch output.</p>
<script>AUTOBAHN_DEBUG = true;</script>
<script src="http://autobahn.s3.amazonaws.com/autobahnjs/latest/autobahn.min.jgz"></script>
<script>
// the URL of the WAMP Router (Crossbar.io)
//
var wsuri = "ws://127.0.0.1:8080/ws";
// the WAMP connection to the Router
//
var connection = new autobahn.Connection({
url: wsuri,
realm: "realm1"
});
// fired when connection is established and session attached
//
connection.onopen = function(session, details) {
console.log("Connected");
// SUBSCRIBE to a topic and receive events
//
function on_counter(args) {
var counter = args[0];
console.log("on_counter() event received with counter " + counter);
}
for (var i = 0; i < 800; i++) {
session.subscribe('com.example.oncounter' + i, on_counter).then(
function(sub) {
console.log('subscribed to topic');
},
function(err) {
console.log('failed to subscribe to topic', err);
}
);
}
}
connection.open();
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment