Autobahn|JS Documentation

Autobahn|JS is a subproject of Autobahn and provides an open-source implementation of The Web Application Messaging Protocol (WAMP) .

WAMP runs on top of WebSocket and adds asynchronous Remote Procedure Calls and Publish & Subscribe.

Autobahn|JS runs in the browser as well as in Node.js

It is ideal for distributed, multi-client and server applications, such as multi-user database-drive business applications, sensor networks (IoT), instant messaging or MMOGs (massively multi-player online games) .

WAMP enables application architectures with application code distributed freely across processes and devices according to functional aspects. Since WAMP implementations exist for multiple languages, WAMP applications can be polyglott. Application components can be implemented in a language and run on a device which best fit the particular use case.

Show me some code

The following example implements all four roles that Autobahn|JS offers

  • Publisher
  • Subscriber
  • Caller (calls a remote procedure)
  • Callee (offers a remote procedure)

The code runs unaltered in the browser or Node.js!

var connection = new autobahn.Connection({
         url: 'ws://127.0.0.1:9000/',
         realm: 'realm1'
      });

connection.onopen = function (session) {

   // 1) subscribe to a topic
   function onevent(args) {
      console.log("Event:", args[0]);
   }
   session.subscribe('com.myapp.hello', onevent);

   // 2) publish an event
   session.publish('com.myapp.hello', ['Hello, world!']);

   // 3) register a procedure for remoting
   function add2(args) {
      return args[0] + args[1];
   }
   session.register('com.myapp.add2', add2);

   // 4) call a remote procedure
   session.call('com.myapp.add2', [2, 3]).then(
      function (res) {
         console.log("Result:", res);
      }
   );
};

connection.open();

Features

  • supports WAMP v2, works with any WAMP server
  • works both in the browser and Node.js
  • provides asynchronous RPC and PubSub messaging patterns
  • easy to use Promise-based API
  • pluggable promises/deferreds: use when.js (built-in), jQuery , Dojo , ECMA Script 6 or others
  • no dependencies
  • small size (134kB source, 74kB minified, 23kB compressed)
  • Open-Source (MIT License)

Where to go from here

Getting Started gives a brief overview of requirements, how to get Autobahn|JS, and where to get an application router which you need to route the application traffic of your JavaScript application.

The Tutorials take you step-by-step through simple sample applications that introduce core WAMP functionality and concepts.

The examples overview page lists code examples covering a broader range of uses cases and advanced WAMP features.

The Demos give the opportunity to play around with some live sample applciations made using Autobahn|JS and Crossbar.io, an application router which uses WAMP.

The API Reference provides details for the entire API.

Note

The documentation for older versions of Autobahn|JS, which implement WAMP v1, is still available as legacy documentation. The current version of Autobahn|JS no longer supports WAMP v1. WAMP v2 adds a lot of features and some completely new capabilities, so consider upgrading.

Acknowledgements

Autobahn|JS includes code from the following open-source projects

Special thanks to the Coders with an Unhealthy Javascript Obsession for creating when.js - A lightweight Promise and when() implementation, plus other async goodies.

Autobahn|JS

Autobahn|JS is a subproject of Autobahn and provide an open-source implementations of the The Web Application Messaging Protocol (WAMP) in JavaScript running in browsers and Node.