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

@seriousme/opifex

v1.3.0

Published

MQTT client & server for Deno & NodeJS

Downloads

275

Readme

Deno CI CodeQL

Opifex

Opifex aims to provide a MQTT server and MQTT client in Typescript to be used with Deno or NodeJS It has no third party dependencies, it only relies on built in modules.

Its a work in progress, only does MQTT 3.1.1 and currently only has memory based persistence.

Example

A simple server example using Deno, for more elaborate examples see the Usage section below.

import { MqttServer } from "./server/mod.ts";

const listener = Deno.listen();
const mqttServer = new MqttServer(mqttOptions);
for await (const conn of this.listener) {
  mqttServer.serve(conn);
}

Architecture

  1. The basis of Opifex is the MQTT packet module (mqttPacket/mod.ts) which contains al the logic to encode and decode packets.

  2. On top of mqttPacket sits the MQTT connection module (mqttConn/mod.ts) module that reads packets from a Readable stream and writes them to Writable stream. It will take care of incomplete and/or malformed packets. mqttConn provides an async iterable that can be awaited for new packets.

  3. On top of mqttConn live the MQTT server (server/mod.ts) and MQTT client (client/mod.ts) that take care of the MQTT protocol handling like requiring an authentication to be successfull before another type of packet will be accepted. Both follow a similar model of implementation where for each packet that is received a handler is invoked which then triggers the next step. Server and client are totally independ of the technical implementation of the connection and only need a socketConn (socket) to be able to work.

  4. As the server needs to be able to serve multiple clients at the same time, it maintains a context (server/context.ts) per client to keep track of its state and associated timers.

  5. Persistence of data is handled by a pluggable persistence module (persistence) which currently only offers memory persistence (persistence/memory) but can be extended with database backed persistence supported by third party modules.

  6. The demo server listens to a platform specific socket and runs the serve() method from the server module on the platform independent streams of every connection.

  7. The demo client opens a platform specific socket and passes the resulting platform independent streams to the client module.

Usage

The most easy way to use this project is to just use the demo server (demoServer) and/or the demo client (mqtt). There are separate usage instructions for:

If you want to change the behaviour of the server and/or the client beyond what can be done with CLI options then the next step is to clone the demo server and/or the client scripts and modify them to your liking.

If you want to port the platform independent client and server libs to other types of transport (e.g. Unix sockets or websocketstream) then its recommended to clone and modify the platform specific code in /node or /deno as well.

If you want to port the platform independent client and server libs to another platform (e.g. Bun) then the platform specific code in /node or /deno might serve as inspiration.

The platform independent client and server libs should also work on Bun as they are engine independent, but the demo server and client currently do not work on Bun because of some socket incompatibilities between Bun and the rest.

Naming

Some MQTT servers have names like:

So to stay with the theme: Opifex

License

Licensed under MIT