🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
DemoInstallSign in
Socket

@sergtyapkin/reconnecting-websocket

Package Overview
Dependencies
Maintainers
0
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@sergtyapkin/reconnecting-websocket

![Static Badge](https://img.shields.io/badge/Vue.js-plugin-green) ![npm](https://img.shields.io/npm/dt/%40sergtyapkin%2Freconnecting-websocket)

1.0.5
latest
Source
npm
Version published
Weekly downloads
54
237.5%
Maintainers
0
Weekly downloads
 
Created
Source

Reconnecting WebSocket

Static Badge npm

WebSocket that will try to reconnects to server when lost connection.

First reconnection attempt after reconnectTimeout milliseconds. With each subsequent reconnection, the timeout will increase by x2 but max reconnection timeout is maxReconnectTimeout.

Default values:

reconnectTimeout = 1000
maxReconnectTimeout = 4000

Example without Vue framework:

import WS from "@sergtyapkin/reconnecting-websocket";

WS.handlers.some_event = (jsonData) => {console.log(jsonData)};
// WS.onopen = (event) => {};
// WS.onerror = (event) => {};
// WS.onclose = (event) => {};

// to disable some handler
delete WS.handlers.some_event;

Example entrypoint using Vue.js:

// index.js

import { createApp } from 'vue';
import App from './App.vue';
import WS from "@sergtyapkin/reconnecting-websocket";

const app = createApp(App)
  .use(WS, `wss://${location.host}/ws`)
  .mount('#app');

// Now WS class available in any child component by:
// this.$ws

Keywords

modal

FAQs

Package last updated on 05 Oct 2024

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