The autobahn.Connection object provides two primary callbacks for lifecycle management:
onopen
Fired when the connection is established and a new WAMP session is created. It receives (session, details) where session is an autobahn.Session instance.
autobahn.Connection.onopen = function (session, details) {
// session is an instance of autobahn.Session
};
onclose
Fired when the connection is closed explicitly, lost, or failed to establish. It receives (reason, details).
Possible reason values:
"closed": Explicitly closed. No reconnection attempted."lost": Connection was established but lost. Automatic reconnection will happen unless you return a truthy value from this callback."unreachable": Connection could not be established (e.g., invalid URL). No reconnection attempted."unsupported": No WebSocket transport could be created.
details contains the reason and message passed to .close(), but is not applicable for "lost" or "unreachable" cases.
autobahn.Connection.onopen = function (session, details) {
// Underlying transport to WAMP router established and new WAMP session started.
// session is an instance of autobahn.Session
};
autobahn.Connection.onclose = function (reason, details) {
// connection closed, lost or unable to connect
};