ReliableConnection

new ReliableConnection(config) → {ReliableConnection}

Connection Class.

Parameters:
Name Type Description
config object

Connection Configuration.

Properties
Name Type Attributes Default Description
attempts number <optional>
10

Maximum number of connection attempts.

delays number | Array.<number> <optional>
[100, 1000, 5000]

Delays between connection attempts, in milliseconds.

It can be either a single delay, or an array of delays. The last delay in the array is reused when the number of attempts is greater than the array's length.

onConnect function

A callback to establish a connection and return a promise.

onStatus function

Status change notification, with the following parameters:

  • status
  • data
Source:
Returns:
Type
ReliableConnection

Members

(static) defaults

Default configuration parameters.

Properties:
Name Type Description
attempts number
delays Array.<number>
Source:

(static) status :string

Connection status enum.

Type:
  • string
Properties:
Name Type Description
idle

Means the class is in the state of doing nothing.

It is acquired in the following cases:

  • Immediately following instantiation of the class (the default state)
  • After reaching the state of failed
  • After reaching the state of stopped
  • After calling method disconnect

data = previous state: undefined when the class was just created, or stopped/failed/disconnected otherwise.

connected

The connection just has been established.

data - an object with connection details + statistics:

  • connection - the object that represents the connection, which is the value resolved by onConnect
  • success - number of times the connection has been established since the class was created or method stop was called.
  • attempts - number of attempts in the session it took to successfully connect
disconnected

Method disconnect just has been called.

data = undefined (not used)

connecting

Trying to connect.

data - connection statistics object:

  • start - Date/Time when the current session started
  • attempt - number of previous unsuccessful attempts in the current connection session.
failed

Permanent failure, after the maximum number of attempts has been reached.

stopped

Method stop() just has been called, the driver is about to become idle.

error

Another connection attempt has failed.

data - the error status object:

  • error - the connection error, which is the rejection reason from onConnect
  • start - Date/Time when the current connection session started
  • count - number of connection attempts made in the current connection session
  • terminal - boolean that's set when it was the last connection attempt
Source:

Methods

disconnect()

Notifies the driver of the lost connection, to trigger reconnection attempts.

Source:

start()

Initiates connection attempts.

It is to be called after creating the class, or after calling stop().

The method does nothing, if the current status is either connected or connecting.

Source:

stop()

Notifies the driver of ceasing all connectivity at once, and to reset itself to the initial state.

The connection either already has been closed, or to be closed on status = stopped.

Source: