Skip to content
This repository has been archived by the owner on May 29, 2020. It is now read-only.
/ PersistentWS Public archive
forked from Densaugeo/PersistentWS

Browser WebSocket wrapper for auto-reconnection

License

Notifications You must be signed in to change notification settings

lamassu/PersistentWS

 
 

Repository files navigation

PersistentWS

Provides a constructor for WebSockets that automatically attempt to reconnect after being disconnected. Reconnection times start at ~5s for the first attempt, double after each failed attempt, and are randomized by +/- 10% to prevent clients from reconnecting at the exact same time after a server event.

npm Code Climate Build Status

Installation

Install with bower, npm, or link PersistentWS.js from your html:

wget https://raw.githubusercontent.com/Densaugeo/PersistentWS/master/PersistentWS.js

OR

bower install --save persistent-ws

OR

npm install --save persistent-ws

Import

Supports node.js, AMD, and browser global modules.

In your html:
<script type="text/javascript" src="/your/folders/PersistentWS.js"></script>

Or with browserify:
var PersistentWS = require('persistent-ws');

Usage

<script type="text/javascript">
var pws = new PersistentWS('wss://your.websocket/server');

pws.addEventListener('message', function(message) {
  console.log('Received: ' + message);
});

pws.send('Hello from a persitent websocket!');
</script>

License

MIT

About

Browser WebSocket wrapper for auto-reconnection

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 97.9%
  • HTML 2.1%