Socket
Socket
Sign inDemoInstall

ws-heartbeat

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ws-heartbeat

Server-side and client-side heartbeat library for ws and browser-side Websocket.


Version published
Weekly downloads
2.4K
increased by19.65%
Maintainers
1
Weekly downloads
 
Created
Source

Dependency Status devDependency Status Build Status npm version Downloads

ws-heartbeat

Server-side and client-side heartbeat library for ws and browser-side Websocket.

install

npm i ws-heartbeat

client side usage
import { setWsHeartbeat } from "ws-heartbeat/client";
// import * as WebSocket from "ws";
const ws = new WebSocket("ws://localhost:8000");

setWsHeartbeat(ws, '{"kind":"ping"}');

options:

setWsHeartbeat(ws, '{"kind":"ping"}', {
    pingTimeout: 60000, // in 60 seconds, if no message accepted from server, close the connection.
    pingInterval: 25000, // every 25 seconds, send a ping message to the server.
});
server-side usage
import { setWsHeartbeat } from "ws-heartbeat/server";
import * as WebSocket from "ws";

const wss = new WebSocket.Server();

setWsHeartbeat(wss, (ws, data, binary) => {
    if (data === '{"kind":"ping"}') { // send pong if recieved a ping.
        ws.send('{"kind":"pong"}');
    }
});

options:

setWsHeartbeat(wss, (ws, data, flag) => {
    if (data === '{"kind":"ping"}') {
        ws.send('{"kind":"pong"}');
    }
}, 60000); // in 60 seconds, if no message accepted from client, close the connection.

FAQs

Package last updated on 17 Nov 2020

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