websocketwrapper v1.0.4
WebSocketWrapper
Wrapper over the WebSocket class to manage disconnections transparently.
Installation
- With npm:
$ npm install websocketwrapperUsage in Node/Browserify
var WebSocketWrapper = require('websocketwrapper');Usage Example
var ws = new WebSocketWrapper(url, protocol);
ws.reconnectionDelay = 5000;
ws.onopen = function() {
    console.log('connected');
    // Send some kind of registration message.
    ws.send('REGISTER');
};
ws.onreconnect = function() {
    console.log('reconnected');
    // Send some kind of registration message.
    ws.send('REGISTER');
};
ws.onmessage = function(e) {
    // do something
};Documentation
WebSocketWrapper Class API
An instance of WebSocketWrapper holds an instance of a native WebSocket. The exposed API is the same as the native one. Just some differences/additions are described below.
new WebSocketWrapper(url, protocols) constructor
- urland- protocolsmean the same as in the native API.
Events
open event is fired for the first WebSocket connection. If the connection is closed by the server or due to a netwotk error then close is fired and, after a delay, a new connection is attempted. If it connects to the server, reconnect event is fired.
Custom API
ws.reconnectionDelay property
Reconnection delay (in milliseconds). Default value is 5000 ms. If it's set to 0 no reconnection attempt will be performed.
ws.reconnectionDelay = 2000;Debugging
The library includes the Node debug module and produces logs with prefix WebSocketWrapper.
Author
Iñaki Baz Castillo.
License
ISC.
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
10 years ago
10 years ago
10 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago