With Autobahn|JS, you can develop application components in JavaScript, and those components can be hosted inside browsers, Node.js and PostgreSQL (under development).
This page explains what you need in order to include Autobahn|JS in your projects, and to route your application messages.
Autobahn|JS does not connect application components directly to each other, but enables a connection to a WAMP router. This connects the application components. The routing is rule-based - no application code runs inside the router.
You can find a list of WAMP v2 compatible routers at the WAMP project site. We recommend using Crossbar.io, which offers a lot of features, but the examples here should work with any WAMP router.
You can find complete examples for code running in both the browser and Node.js in the Autobahn|Python Github repository. (The examples are also provided in Python versions.)
You can get Autobahn|JS for Node.js using the Node Package Manager:
npm install autobahn
and then, in your code
var autobahn = require('autobahn')
note
On Windows, ignore any potential error messages regarding missing Visual C++ components. Autobahn|JS depends on packages which try to build native extensions for higher performance - but that is not strictly necessary for running it.
We offer a Docker Image with Node.js and Autobahn|JS pre-installed. To use this, if you have Docker already installed, just do
sudo docker run -it crossbario/autobahn-js node root/client.js ws://IP_of_WAMP_router/ws realm1
This starts up a Docker container and client.js, which connects to a Crossbar.io router at the given URL and to the given realm.
You can get the latest pre-built Autobahn|JS release from here:
For development purposes, you can include these directly like so
<!DOCTYPE html>
<html>
<body>
<script
src="https://autobahn.s3.amazonaws.com/autobahnjs/latest/autobahn.min.jgz">
</script>
<script>
console.log("Ok, Autobahn loaded", autobahn.version);
</script>
</body>
</html>
note
We place restrictions on HTTP referrers, so using the above in production would not work in most cases.
For production use, please host Autobahn|JS yourself.
The old Autobahn|JS, which supports the deprecated version 1 of WAMP is still available from here:
If you are using a module system like RequireJS, you can use Autobahn|JS like so:
<!DOCTYPE html>
<html>
<body>
<script src="http://requirejs.org/docs/release/2.1.11/minified/require.js"></script>
<script>
require.config({
baseUrl: ".",
paths: {
"autobahn":
"https://autobahn.s3.amazonaws.com/autobahnjs/latest/autobahn.min",
"when": "https://cdnjs.cloudflare.com/ajax/libs/when/2.7.1/when"
},
shim: {
"autobahn": {
deps: ["when"]
}
}
});
require(["autobahn"], function(autobahn) {
console.log("Ok, Autobahn loaded", autobahn.version);
});
</script>
</body>
</html>
Building Autobahn|JS -------------
Instead of using the versions provided for download (browser) or via npm (Node.js), you can also build Autobahn|JS from the GitHub repository.
Doing so allows you to use forks of Autobahn|JS, e.g. ones which may implement features you desire, but which have not made it into the mainstream version.
It also allows you to hack on Autobahn|JS yourself.
To build Autobahn|JS, follow the instructions in Building;
To route your application messages, your application components, e.g. your browser frontend and your backend on the server, need to connect to a WAMP router which then routes the events and calls.
Several WAMP router implementations exist, across several languages.
We suggest using Crossbar.io, which not only offers stable, performant and scalable WAMP routing, but also other features such as application scaffolding and hosting of application components.
For Crossbar.io, you can take a look at the quick start instructions.
- Take a look at Programming, which gives an overview of how to connect your application components, and do basic RPC and PubSub.
- If you want to see some live Web apps using Autobahn|JS? Take a look at the Crossbar.io demos.