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

@durablejs/socket

v0.0.1

Published

**@durablejs/socket** is a reconnecting websocket class, with **more accuracy**, allows Ping/Pong, intended to be used with [durablejs](https://github.com/DurableJS/DurableJS)

Downloads

5

Readme

durable socket

@durablejs/socket is a reconnecting websocket class, with more accuracy, allows Ping/Pong, intended to be used with durablejs

Installation

npm i @durablejs/socket

Basic Usage

Client-side:

import { DurableSocket } from "@durablejs/socket";

const socket = new DurableSocket({
  host: "localhost:1999",
  room: "boba",
  logLevel: 0, // Listen to all logs
});

// Starts the connection engine
socket.start();

// Similar to .addEventListener("message")
socket.eventHub.messages.subscribe((message) => {
  // console.log(message.data);
});

//Updates when status changes
sock.eventHub.status.subscribe((status) => {
  //logs engine status. use this if you need a more detailed one
  console.log(status);

  //logs 'connected' | 'closed' | 'initial' | 'failed' | 'connecting' | 'reconnecting'
  console.log(socket.getStatus());
});

// Closes the socket
socket.close();

// Reconnects, this will drop the current connection if there is one
socket.reconnect();

// Closes the socket if any, stops the engine, no further messages accepted
// until .start() is called again
socket.stop();

Server-side:

import { Connection, Server } from "Durablekit/server";

export default class Playground implements Server {
  onMessage(message: string | ArrayBuffer, sender: Connection<unknown>) {
    // Send pong for ping
    if (message === "PING") {
      sender.send("PONG");
    }
  }
}

Authentication

new DurableSocket({
  host: "localhost:1999", // The host
  room: "boba", // Room name/id

  auth: async () => {
    return {
      // Data will be included in the query that is sent to the server,
      // similar to how Durablesocket works
      data: { token: "heheheheh" },

      host: "new host", // This will override the one in the config
      room: "new room", // This will override the one in the config
    };
  },
});

Configuration

new DurableSocket({
  host: "localhost:1999", // The host
  room: "boba", // Room name/id
  logLevel: 3, // Logs 0, 1, 2, 3, default is none,
  config: {
    // The time to wait for auth to resolve
    authTimeout: 20000, // 20 seconds, default is 10 sec

    // The backoff after each unsuccessful auth try
    authBackoff: [250, 500, 1000, 2000, 5000], // Default is [250, 500, 1000, 5000]

    // The time to wait for socket connection
    socketConnectTimeout: 20000, // 20 seconds, default is 10 sec

    // The backoff after each unsuccessful connection try
    connectionBackoff: [250, 500, 1000, 2000, 5000], // Default is [250, 500, 1000, 5000]

    // The interval for ping/pong
    heartbeatInterval: 10000, // 10 seconds, default is 30 seconds

    // Max auth tries after consecutive failure
    maxAuthTries: 10, // Default is 5

    // Max connection tries after consecutive failure
    maxConnTries: 10, // Default is 5
  },
});

// Docs are incomplete; there are some other config methods...