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

@akiroz/mqtt-port-forward

v0.0.9

Published

Forward a socket over mqtt topics

Downloads

12

Readme

MQTT Port Forwarding


This modules provides a means to forward a tcp socket, over MQTT to another mqtt recipient

It can be integrated into your mqtt iot devices, to allow estabishing a secure ssh connection from your support laptop to a specific remote iot device.

Table of Contents

Install

$ npm install mqtt-port-formward

Usage

This package, exports 2 functions to establish the port forwarding.

forwardLocalPortToMqtt - To listen on a specific port, and forward connection requests to a specific mqtt topic

forwardMqttToLocalPort - To accept connection request over mqtt topic, and forward to a specific local port on 127.0.0.1

API Documentation

The package exports 2 functions

forwardMqttToLocalPort(mqttClient, portNumber, topic, timeoutPeriod = 120000)

Subscribes on the supplied mqttClient object, to the topic pattern <topic>/tunnel/up/+.

When a new connection request is received on this topic, a socket connection is established on portNumber to the localhost. Assumes there is a service ready to accept this connection.

Once connection is establish, data received on topic <topic>/tunnel/up/+ will be sent to the socket, and data sent from the socket will be published to mqtt topic <topic>/tunnel/down/+

If the mqttClient object is closed, then any opened sockets will be closed.

If no traffic is received on the mqtt topic for timeoutPeriod, then all sockets will be closed.

forwardLocalPortToMqtt(mqttClient, portNumber, topic)

Established a local socket listener on portNumber. When connections are established, the connection and data are forward to mqtt topic <topic>/tunnel/down/+

It also uses the supplied mqttClient object to subscribe and listen for messages on topic <topic>/tunnel/up/+ to return back to the local socket.

Example

If you have a device, you wish to be able to establish a ssh connection with, over mqtt, you first need to use forwardMqttToLocalPort. This function will subscribe to a specific topic, and forward connections to a local ssh server running on your device.

This will need to be paried with the forwardLocalPortToMqtt running on another device. This function will establish a service for a specific port, and upon receiving connections/data, forward that to the appropriate device's topic

On your device, you first need a mqtt connection object - you can use the standard mqtt library or if you are using AWS aws-iot-device-sdk-js

Once you have created your mqttClient object, you can then invoke the forwardMqttToLocalPort function

  import {forwardMqttToLocalPort} from 'mqtt-port-forward'

  // Forward requests received on mqtt topic 'mydevicessh/tunnel/down/+'
  forwardMqttToLocalPort(mqttClient, 22, 'mydevice')

Then on the client device (eg: your laptop)

  import {forwardMqttToLocalPort} from 'mqtt-port-forward'

  // Listen on localhost:2222 for connection requests and forward to 'mydevice/tunnel/down/+'
  forwardLocalPortToMqtt(mqttClient, 2222, 'mydevicessh')

You will need to ensure your 2 connections are authorised to send and received on the topics <topic>/tunnel/down/+ and <topic/tunnel/up/+>

License

MIT © Dean Netherton