Socket
Socket
Sign inDemoInstall

elws

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

elws

Simple auto-reconnect WebSocket decorator


Version published
Weekly downloads
1
decreased by-87.5%
Maintainers
1
Weekly downloads
 
Created
Source

elws

Simple auto-reconnect WebSocket adapter

Install

npm i elws -S

Usage

const RWS = require('elws');

const client = new RWS('ws://echo.websocket.org;ws://localhost:8080');

client.onopen = function () {
	// as soon as we are connected
	// just send an Hello World! to the server
	client.send('Hello World!');
};

client.onmessage = function (event) {
	// because the server is echo.websocket.org we should receive
	// "Hello World!" right after connection
	console.log('> ', event.data);
};

// connect
client.connect();

//close
setTimeout(function(){
    console.log('timeout ');
    client.forceClose(1000);
},10000);

If ws://echo.websocket.org is unreachable, RWebSocket will try to reconnect once every 3 seconds (default) and try 3 times, then switch another url

API

The only modifications to the API are:

  • the ability to give a 3rd argument to the constructor to set the retryInterval in ms
  • the ability to give a 4rth argument to the constructor to set the retryCount
  • the #connect() method to actually create a WebSocket and connect to the server
const client = new RWS('ws://echo.websocket.org;ws://localhost:8080', null, 25000,5);

Reconnection attempts will be made once every 25 seconds, and try 5 times then switch another url. NB: the 'null' param is for the protocol because the constructor is the same as the WebSocket RFC + retryInterval

the ability to give a one argument to the constructor to set the close event 'code'

client.forceClose(1000);

Keywords

FAQs

Package last updated on 03 Jan 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc