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

yamux-js

v0.1.2

Published

[![npm version](https://badge.fury.io/js/yamux-js.svg)](https://www.npmjs.com/package/yamux-js) [![Build status](https://img.shields.io/github/actions/workflow/status/th-ch/yamux-js/node.js.yml?branch=master)](https://github.com/th-ch/yamux-js) [![GitHub

Downloads

3,178,414

Readme

Yamux-js

npm version Build status GitHub license

Yamux-js (Yet another Multiplexer) is a Node.js (TypeScript/JavaScript) port of the multiplexing library for Golang made by HashiCorp: https://github.com/hashicorp/yamux. The 2 libraries are fully interoperable (you can have a client in Golang and a server in JS, or the other way around).

From https://github.com/hashicorp/yamux:

It relies on an underlying connection to provide reliability and ordering, such as TCP or Unix domain sockets, and provides stream-oriented multiplexing. It is inspired by SPDY but is not interoperable with it.

Yamux features include:

  • Bi-directional streams
    • Streams can be opened by either client or server
    • Useful for NAT traversal
    • Server-side push support
  • Flow control
    • Avoid starvation
    • Back-pressure to prevent overwhelming a receiver
  • Keep Alives
    • Enables persistent connections over a load balancer
  • Efficient
    • Enables thousands of logical streams with low overhead

Installation

Install Yamux-js using yarn:

yarn add yamux-js

Or npm:

npm install --save yamux-js

Usage

Client side

var {Client} = require('yamux-js');

var client = new Client();
client.on('error', (err) => {
    console.log('An error occured:', err);
});
client.pipe(commonXXXChannel).pipe(client);

var stream1 = client.open();
stream1.on('end', () => {
    console.log('client disconnected');
});
stream1.on('data', (data) => {
    console.log('recv:', data.toString());
});
stream1.on('error', (err) => {
    console.log('An error occured:', err);
});
stream1.write('Sending data');

var stream2 = client.open();
// ...

Server side

var {Server} = require('yamux-js');

var server = new Server((stream) => {
    stream.on('end', () => {
        console.log('client disconnected');
    });
    stream.on('data', (data) => {
        console.log('recv:', data.toString());
        stream.write('Sending back data');
    });
    stream.on('error', (err) => {
        console.log('An error occured:', err);
    });
});
server.on('error', (err) => {
    console.log('An error occured:', err);
});

server.pipe(commonXXXChannel).pipe(server);

Configuration

Both Server and Client can take a custom config as last argument in their constructor:

{
    // AcceptBacklog is used to limit how many streams may be
    // waiting an accept.
    // WARNING [Difference with the Go implementation]: total number of streams, not in-flight
    acceptBacklog: number; // default: 256

    // EnableKeepalive is used to do a period keep alive
    // messages using a ping.
    enableKeepAlive: boolean; // default: true

    // KeepAliveInterval is how often to perform the keep alive
    keepAliveInterval: number; // In seconds, default: 30

    // ConnectionWriteTimeout is meant to be a "safety valve" timeout after
    // we which will suspect a problem with the underlying connection and
    // close it. This is only applied to writes, where's there's generally
    // an expectation that things will move along quickly.
    connectionWriteTimeout: number; // In seconds, default: 10

    // MaxStreamWindowSize is used to control the maximum
    // window size that we allow for a stream.
    maxStreamWindowSize: number; // default: 256 * 1024 (256 KB)

    // Logger is used to pass in the logger to be used.
    logger: typeof console.log; // default: console.log
}