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

anysocket

v0.4.29

Published

An abstract networking layer over multiple transports, client/server agnostic with support for E2EE

Downloads

229

Readme

AnySocket

An abstract networking layer over multiple transports, client/server agnostic with support for E2EE

NPM version Downloads

  • Features
  • Benchmarks
  • Installation
  • Usage
  • Documentation / API
  • Upcoming Features
  • License

Important

This is a work in progress and API is subject to change.

Features

  • Client / Server agnostic
  • Support for request/reply
  • Custom AUTH method
  • E2EE between peers with forward secrecy
  • RPC support
  • NTP Sync between peers support
  • P2P using a proxy server (with support for direct E2EE between peers)
  • Binary support (see: AnySocket.Packer)
  • Browser support - 31kb footprint (see: /dist/anysocket.browser.js)
  • Multiple transports *(implemented atm: ws/wss, http/https)
  • All peers have a UUIDv4 associated
  • Disconnect detection using a heartbeat
  • Not Battle Tested ...yet

** http transport is experimental

Info: Binary RPC arguments and responses are auto packed/unpacked (AnySocket.Packer.pack/AnySocket.Packer.unpack).

Benchmarks

See benchmarks

Installation

npm install --save anysocket

or

<script src="/dist/anysocket.browser.js"></script>

or (if using AnySocketHTTP)

<script src="@anysocket"></script>

How to use

The following example starts a websocket server on port 3000.

const AnySocket = require("anysocket");
const server = new AnySocket();
const PORT = 3000;
server.listen("ws", PORT)
    .then(() => {
        console.log("Listening on port:", PORT);
    })
    .catch((err) => {
        console.error("Failed to start server:", err);
    });
server.on("connected", async (peer) => {
    console.log("Connected", peer.id);
    console.log(await peer.getSyncedTime()) // { time: 1674671482107, rtt: 2, offset: 0 }
    peer.send({
        hello: "world"
    });
});
server.on("message", (packet) => {
    console.log("From:", packet.peer.id, "Message:", packet.msg);
});
server.on("disconnected", (peer, reason) => {
    console.log("Disconnected", peer.id, "Reason:", reason);
});

The following example connects to a websocket on port 3000

const AnySocket = require("anysocket");
const client = new AnySocket();
const PORT = 3000;
client.connect("ws", "127.0.0.1", PORT)
    .then(() => {
        console.log("Connected to server");
    })
    .catch((err) => {
        console.error("Failed to connect to server:", err);
    });

// after negotiating the AUTH packet, it will trigger the connect event
client.on("connected", async (peer) => {
    console.log("Connected", peer.id);
    console.log(await peer.getSyncedTime()) // { time: 1674671482107, rtt: 2, offset: 0 }
    peer.send({
        hello: "world"
    });
});
client.on("message", (packet) => {
    console.log("From:", packet.peer.id, "Message:", packet.msg);
});
client.on("disconnected", (peer, reason) => {
    console.log("Disconnected", peer.id, "Reason:", reason);
});

More in the examples folder.

Documentation

See documentation and examples folder

Upcoming Features

  • Mesh Network
  • Multiple transports: tcp, udp*, ipc
  • Client reconnection

* this will require a change in the protocol, as the protocol assumes the packets are sent using a reliable, ordered connection

License

MIT