Socket
Socket
Sign inDemoInstall

websocket-reconnector

Package Overview
Dependencies
2
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    websocket-reconnector

A wrapper to W3C WebSocket objects to seamlesly add reconnection feature


Version published
Weekly downloads
5
decreased by-78.26%
Maintainers
1
Install size
75.1 kB
Created
Weekly downloads
 

Readme

Source

websocket-reconnector

Build Status

A wrapper to W3C WebSocket objects to seamlesly add reconnection feature.

Installation

$ npm install --save websocket-reconnector

Usage

const WebSocketReconnector = require('websocket-reconnector')

// Wrap any W3C WebSocket implementation
const ReconnectingWebSocket = WebSocketReconnector(WebSocket)

// Create your WebSocket client as usual and attach events
const client = ReconnectingWebsocket('ws://localhost')

// On connection and one every reconnection, send a message
client.onopen(() => client.send('Hello server'))

// A response is always received, no need to resubscribe to events
client.onmessage(event => console.log(`Message received: ${event.data}`))

API

The API is fully compatible with the W3C WebSocket API.

In addition, the following additional method is available:

client.reconnect()

Closes the underlying websocket instance and initiates a new connection.

License

MIT

Keywords

FAQs

Last updated on 07 Sep 2018

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc