npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ws-reqonet

v2.0.0

Published

Simple WebSocket wrapper with reconnect logic

Downloads

23

Readme

ws-reqonet [formerly ws-rekanet]

Publish

Simple WebSocket wrapper with reconnect logic 💫

Motivation

The Websocket API although effective and simple doesn't provide any reconnection logic. This library aims to solve this shortcoming by providing a mechanism to shore up session_affinity between the client [a web browser] and the server. It also provides a simple queue implementation where data being sent while the connection is broken are bucketed, to be relayed when connection is restored.

Notes

  1. the library is basically a wrapper for native WebSocket class, re-exposing its API.
  2. it's built on browser event interface which allows it to emit native WebSocket events.
  3. well tested with AVA.

🛠 installation

# yarn
yarn add ws-reqonet

# pnpm
pnpm install ws-reqonet

# npm
npm install ws-reqonet

🔱 Usage

import WSReqonet from "ws-reqonet";

const url = `ws://localhost:3001/`;
const protocols = [];
const options = {
  maxRetryAttempts: 10,
  queueMessage: true,
};

// initialize
const wsClient = new WSReqonet(url, protocols, options);

wsClient.on("open", () => {
  console.log("websocket connection established");
});
wsClient.on("message", (event: any) => {
  console.log(event.data);
});
wsClient.on("error", (error: any) => {
  console.log("websocket error", error);
});
wsClient.on("close", () => {
  console.log("websocket connection closed");
});

const payload = { message };
wsClient.send(JSON.stringify(payload));

🎯 API

url

Type: string

protocols

Type: string | string[] Default: []

Either a single protocol string or an array of protocol strings. These strings are used to indicate sub-protocols, so that a single server can implement multiple WebSocket sub-protocols (for example, you might want one server to be able to handle different types of interactions depending on the specified protocol). See more MDN, WhatWG#web-sockets

options

Type: object

maxRetryAttempts

The maximum number of retries - how many attempts at reconnecting

Type: number
Default: 5

queueMessage

Whether to store 'send' data when the connection is broken, which is to be relayed when connection is restored.

Type: boolean
Default: true

disableReconnect

Whether to disable reconnection

Type: boolean
Default: false

debug

Whether to run in debug mode which enables logging to dev tools

Type: boolean
Default: false

events

open, close, message, error

The same as native WebSocket events

reconnection_timeout

Indicates when reconnection attempts timeout.

reconnected

Emitted when reconnection attempt is successful - connection restored