rapport-reconnect
A simple plugin that adds reconnect functionality to the Rapport library.
Installation
Node: Install the plugin via NPM: npm install --save rapport-reconnect
Browser: Attach rapport.reconnect.min.js
to your HTML page
Then add the plugin to rapport:
// GloballyRapport; // In Node.jsRapport; // In the browser // Or to a instance; // In Node.js; // In the browser
Basic Usage
This plugin adds reconnect capabilities to a socket. The reconnect functionality is specified in the rapport options object:
// Enable reconnect on all sockets created by the rapport libraryRapport; // Or all sockets created by a rapport instance:const rapport = ; // Orconst rapport = ; // Or a single socketrapport;
NOTE: Only sockets that are created with .create()
can have reconnect functionality. Specifying a reconnect value for a
socket that is wrapped with .wrap()
will do nothing.
Open and Error Handlers
When this plugin is added to Rapport, the onOpen
handler will be called every time a new connection is established, with an object parameter:
const ws = rapport; ws;
Additionally, every time the connection is dropped, the onError
handler will be called:
const ws = rapport; ws;
Reconnect Options
By default, reconnection will be attempted on an interval of 500 milliseconds, with no stop condition. All of the following calls are equivalent:
rapport;rapport;rapport;rapport;rapport;
You can change the maxAttempts
and interval
as you see fit. When retrying fails (because the maxAttempts
have been
exceeded), the onClose
handler will be called as normal.
More retry methods (fibonacci and exponential) will be implemented in future versions. If there is another reconnect method you would like to see, please open an issue describing it.
Message Queueing
The reconnect plugin also supports message queueing. When enabled, messages that are sent during a reconnect will be pushed
onto a queue. When the connection is established, they will all be sent immediately. The following options all enable simple
message queueing (and the default interval
reconnect shown above):
rapport;rapport;
More queueing mechanisms can be implemented as needed, please open an issue with any requests.