API Reference¶
This section documents the public API of Autobahn|JS.
Note
Full auto-generated API documentation from JSDoc is planned for a future release. This page provides a manual reference for the main classes and functions.
Core Classes¶
Connection¶
The Connection class manages the WebSocket connection and WAMP session lifecycle.
Constructor
new autobahn.Connection(options)
Options
Option |
Type |
Description |
|---|---|---|
|
string |
WebSocket URL (e.g., |
|
string |
WAMP realm to join |
|
array |
Authentication methods (e.g., |
|
string |
Authentication ID (username) |
|
function |
Callback for authentication challenges |
|
array |
Serializers in preference order |
|
number |
Maximum reconnection attempts (default: 15) |
|
number |
Initial retry delay in seconds (default: 1.5) |
|
number |
Maximum retry delay in seconds (default: 300) |
|
number |
Retry delay multiplier (default: 1.5) |
Properties
connection.session— The currentSessionobject (or null if not connected)connection.isOpen— Boolean indicating connection stateconnection.isRetrying— Boolean indicating if reconnection is in progress
Callbacks
connection.onopen = function(session, details) { }— Called when connectedconnection.onclose = function(reason, details) { }— Called when disconnected
Methods
connection.open()— Open the connectionconnection.close(reason, message)— Close the connection
Session¶
The Session class provides WAMP RPC and PubSub functionality.
Properties
session.id— The WAMP session IDsession.realm— The realm namesession.isOpen— Boolean indicating session state
RPC Methods
// Register a procedure
session.register(procedure, endpoint, options)
.then(function(registration) { })
.catch(function(error) { });
// Call a procedure
session.call(procedure, args, kwargs, options)
.then(function(result) { })
.catch(function(error) { });
// Unregister a procedure
registration.unregister()
.then(function() { });
PubSub Methods
// Subscribe to a topic
session.subscribe(topic, handler, options)
.then(function(subscription) { })
.catch(function(error) { });
// Publish an event
session.publish(topic, args, kwargs, options)
.then(function(publication) { })
.catch(function(error) { });
// Unsubscribe from a topic
subscription.unsubscribe()
.then(function() { });
Serializers¶
Autobahn|JS supports multiple serialization formats:
JSONSerializer¶
new autobahn.serializer.JSONSerializer()
The default serializer. Human-readable, widely supported.
MsgpackSerializer¶
new autobahn.serializer.MsgpackSerializer()
Binary format, more compact than JSON. Requires msgpack5 package.
CBORSerializer¶
new autobahn.serializer.CBORSerializer()
Binary format (RFC 8949). Requires cbor package.
Authentication¶
WAMP-CRA Functions¶
// Sign a challenge
autobahn.auth_cra.sign(secret, challenge)
// Derive a key from password
autobahn.auth_cra.derive_key(secret, salt, iterations, keylen)
Error Handling¶
Error Class¶
// Throw a WAMP application error
throw new autobahn.Error(uri, args, kwargs)
// Error properties
error.error // Error URI (e.g., 'wamp.error.no_such_procedure')
error.args // Positional arguments
error.kwargs // Keyword arguments
Registration and Subscription Objects¶
Registration¶
Returned by session.register().
registration.id— Registration IDregistration.procedure— Procedure URIregistration.unregister()— Unregister the procedure
Subscription¶
Returned by session.subscribe().
subscription.id— Subscription IDsubscription.topic— Topic URIsubscription.unsubscribe()— Unsubscribe from the topic
Publication¶
Returned by session.publish() when acknowledge: true.
publication.id— Publication ID
Call and Invocation Options¶
Call Options¶
session.call('procedure', [args], {kwargs}, {
timeout: 10000, // Call timeout in ms
receive_progress: true, // Receive progressive results
disclose_me: true // Disclose caller identity
});
Registration Options¶
session.register('procedure', handler, {
match: 'prefix', // Pattern matching: 'exact', 'prefix', 'wildcard'
invoke: 'roundrobin' // Invocation policy: 'single', 'roundrobin', 'random', 'first', 'last'
});
Subscription Options¶
session.subscribe('topic', handler, {
match: 'prefix', // Pattern matching: 'exact', 'prefix', 'wildcard'
get_retained: true // Get retained event on subscribe
});
Publish Options¶
session.publish('topic', [args], {kwargs}, {
acknowledge: true, // Wait for broker acknowledgment
exclude_me: true, // Don't send to publisher (default: true)
exclude: [session_id], // Exclude specific sessions
eligible: [session_id], // Only send to specific sessions
retain: true // Retain event for late subscribers
});