connManager

Takes care of remote tcp-ip connections by attempting automatic reconnects and handling timeouts.
Version:
  • 1.0.2
Author:
  • Pedro Miguel P. S. Martins
Source:

Methods

(inner) connect(connectOpts) → {Promise}

Attempts to connect to the tcp-ip server provided with the given options.

It will not resolve until a connection is made. Once a connection is made it fires onOpen, and every time it retries to establish a connection it fires onRetry().

Once a connection is established, it starts the heartbeat to periodically check the health of the target. If the connection dies or times out, it fires onClose and automatic reconnection is attempted, called onRetry for every failed attempt.

Source:
See:
Parameters:
Name Type Description
connectOpts Object An object with connect options. This is the object that will be passed to connectFn to attempt connect. The default connectFn makes a socket connection, so the connections object passed to the default should be the one used is net.createConnection().
Throws:
If there is no connection options. There must always be a connectOpts parameter.
Type
OptionsNotProvided
Returns:
Type:
Promise

(inner) disconnect()

Kills the connection to the target, stops the heartbeat and fires onClose
Source:
See:
  • onClose

(inner) isConnected() → {boolean}

Returns true if the connection is up, false otherwise. If a reconnection is taking place, it will still return false.
Source:
Returns:
Type:
boolean
true if the connection is up, false otherwise.

(inner) onClose(newFn)

Runs the given function every time the onClose event is triggered, passing it the argument false.
Source:
Parameters:
Name Type Description
newFn function The function to run when the onClose event is fired.
Throws:
If newFn is not a function.
Type
CallbackNotAFunction

(inner) onOpen(newFn)

Runs the given function every time the onOpen event is triggered, passing it the argument code>true.
Source:
Parameters:
Name Type Description
newFn function The function to run when the onOpen event is fired.
Throws:
If newFn is not a function.
Type
CallbackNotAFunction

(inner) onRead(newFn)

Runs the given function every time the onRead event is triggered, passing it the received data as an argument.
Source:
Parameters:
Name Type Description
newFn function The function to run when the onRead event is fired.
Throws:
If newFn is not a function.
Type
CallbackNotAFunction

(inner) onRetry(newFn)

Runs the given function every time the onRetry event is triggered, passing it the error that caused the retry, as well as a count of the number of retries.
Source:
Parameters:
Name Type Description
newFn function The function to run when the onRetry event is fired.
Throws:
If newFn is not a function.
Type
CallbackNotAFunction

(inner) send(message)

Sends a message to the target.
Source:
See:
  • isConnected
Parameters:
Name Type Description
message Object The message object we want to send.
Throws:
If the connection is down. You can check this via isConnected.
Type
ConnectionDown

(inner) setConnectFn(newFn)

Used when you need a custom connect function because the target has a specific handshake or protocol. The function passed must return the socket used for the connection.
Source:
Parameters:
Name Type Description
newFn function The function to be used when connect is called and every time automatic reconnection takes place.
Throws:
If newFn is not a function.
Type
ConnectHandlerNotAFunction