Getting Started

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.

WAMP router

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.

Example Code

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.)

Node.js

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.

Docker

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.

For a WAMP router, there’s also a Docker image of Crossbar.io. This has a demo realm realm1 so that the above Docker image can connect to it.

Browsers

You can get the latest pre-built Autobahn|JS release from here:

  1. Production (minimized and gzipped)
  2. Production (only minimized)]
  3. Development

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:

  1. 0.8.2 Production (minimized and gzipped)
  2. 0.8.2 Production (only minimized)
  3. 0.8.2 Development

AMD and RequireJS

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 these instructions

Running a WAMP router

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 or, for an all-JavaScript application, how to set things up for an application with a Node.js backend.

What now?

  • Take a look at the Introduction to WAMP 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.
Reactive Manifesto: We are reactive banner