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

tether-agent

v3.1.3

Published

Tether is a standardised MQTT+MessagePack system for inter-process communication, created, maintained and actively in use by [Random Studio](https://random.studio).

Downloads

8

Readme

Tether Base Agent

Tether is a standardised MQTT+MessagePack system for inter-process communication, created, maintained and actively in use by Random Studio.

Read more about Tether in the main Tether repo.

Use in NodeJS / Browser

This package is JavaScript base agent for the browser and NodeJS.

The JS Base Agent can be used by both NodeJS scripts (TCP or Websocket) and web pages (Websocket only). We provide some easy defaults (import BROKER_DEFAULTS) for each environment:

// Example of browser defaults, but override the host (and hostname)
const agent = await TetherAgent.create("dummy", {
  brokerOptions: {
    ...BROKER_DEFAULTS.browser,
    host: "192.168.27.100",
  }
);
// Example of NodeJS defaults, with no overrides
const agent = await TetherAgent.create("dummy", {
  brokerOptions: BROKER_DEFAULTS.nodeJS
);

Features

The Base Agent is intentionally a very thin layer on top of standard MQTT. We merely add some conventions on top of what MQTT can already provide. See the main Tether documentation for more information on our approach.

For the JS Base Agent specifically, we encapsulate the functionality of a Tether Agent in a class, which retains:

  • The details for the MQTT Broker, and methods to connect and disconnect it
  • The "Role" and "ID" for this agent
  • The Input and Output "Plugs" which are used to subscribe and publish respectively

We also provide the encode and decode functions from the @msgpack/msgpack JS library dependency to allow easy encoding and decoding of payloads.

Usage

You can find some ES6-style Javascript sample code in /examples/nodejs and some React with Typescript sample code in /examples/react-ts.

The basic steps are usually something similar to the following:

  1. Create a Tether Agent instance with const agent = await TetherAgent.create("someRole") - this connects automatically to the MQTT broker, by default
  2. Create Output Plug(s) that you need with const myOutputPlug = new OutputPlug("somePlugName")
  3. Create Input Plug(s) that you need with const myInputPlug = await InputPlug.create(agent, "somePlugName")

For Output Plugs, you can send messages like this:

await myOutputPlug.publish(encode({ foo: "bar }));

For Input Plugs, the subscription is set up automatically on .create but you need to handle incoming messages, e.g.:

myInputPlug.on("message", (payload, _topic) => {
  const decoded = decode(payload);
});