Create a new connection
the transports that can be used for the connecttion
a reconnection timeout
size of the recovery buffer
The reason why the connection was closed
The emitter on which to emit stream events
A finite state machine that keeps track of the internal state
The sequence number of the last message that was received
The sequence number of the last message that was sent
The timeout for reconnection attempts
The recovery buffer that stores the last messages that were dispatched
The timer handle for closing the connection due to timeout
The timer handle for trimming the recovery buffer
The active transport
The transports
Close the connection. When the connection has been closed, it will emit a
disconnected event.
the close reason
Close the connection when it is idling
Establish a connection with a provided connection request and connection options.
the connection request
options passed to the transports
a timeout after which the connection will be closed
Internal dispatch method for converting a message into a buffer and dispatching it through the active transport.
The message is added to the recovery buffer
the message that should be dispatched
Get the sequence number of the oldest message in the recovery buffer
the oldest sequence number
Get the current state of the connection.
Remove a listener from a specified event.
Example:
// Bind a single listener to the 'foo' event and then deregister it
var listener = function() {};
stream.on('foo', listener);
stream.off('foo', listener);
Example:
// Bind a listener to the 'foo' event and deregister all listeners
var listener = function() {};
stream.on('foo', listener);
stream.off('foo');
the listener to remove. All listeners for the event are removed if this is not specified. This argument is ignored if the first argument is a CallbackMap.
this stream.
Register listeners against events.
A single listener may be bound to an event by passing the event name and listener function.
Multiple listeners may be bound by passing in a CallbackMap, mapping event names to listener functions.
Example:
// Bind a single listener to the 'foo' event
stream.on('foo', function(arg1, arg2) {
console.log("Called for 'foo' event", arg1, arg2);
});
Example:
// Bind multiple listeners
stream.on({
foo : function() { ... },
bar : function() { ... },
baz : function() { ... }
});
It is possible to bind multiple listeners to the same event. In this case, the listeners will be called in the order they were bound.
the event name or CallbackMap mapping event names to listeners
the listener to bind to the event, if passed as string. This argument is ignored if the first argument is a CallbackMap.
this stream.
Close the connection and emit a close event. If the connection was in
a disconnected state, then a disconnect event is emitted instead.
the reason the transport closed, if any
Parse Message from data and emit the data event.
If the message could not be parsed, the connection will be cloed with CloseReasonEnum.CONNECTION_ERROR
the raw message data
Handle an error.
The transport's emitter raises close immediately after error, so
onClose runs next and performs the state transition: from an
active state it reaches the recoverable disconnected state and emits
a disconnect event, which engages the session's reconnection logic.
TRANSPORT_ERROR is a reconnectable close reason, and the session's
reconnect logic still gates on reason.canReconnect and the configured
reconnect timeout, so this honours that intent rather than forcing a
terminal close.
the error that occured
Handle connection response parsing errors.
error thrown parsing the response
Handle connection responses.
parsed connection response
Reset the recovery buffer and message sequence numbers
Send a message.
Sending messages is only valid in a 'connected' state. This method will return false otherwise.
the message that should be dispatched
true if the message was succesfully enqueued
on the transport.
Copyright © 2025 DiffusionData Ltd. All Rights Reserved.
The layer that abstracts across transports and handles the connection-level protocol. The externally exposed events from a connection are
connect,disconnectanderror. A connection only cares about whether it is connected or not.Higher level semantics such as reconnect or session close, are determined by the consumer of this connection's events, i.e the internal session.
The following events are emitted by the connection are
connectdatadisconnectcloseerrorTODO FB19940 update documentation to reflect the type of the handshake response