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

@mangar2/mqttclient

v2.3.1

Published

communicates with a MQTT-Style HTTP broker

Downloads

14

Readme

Abstract

Provides a standard client to communicate with the mqtt broker

Contents

Meta

| | | | --- | --- | | File | mqttclient.js | | Abstract | Provides a standard client to communicate with the mqtt broker | | Author | Volker Böhm | | Copyright | Copyright ( c ) 2020 Volker Böhm | | License | This software is licensed under the GNU LESSER GENERAL PUBLIC LICENSE Version 3 . It is furnished "as is" , without any support , and with no warranty , express or implied , as to its usefulness for any purpose . |

Type definitions

LogPattern {Object}

| Name | Type | Description | | ---- | ---- | ------- | | topic | string | log topic pattern | | | module | string | module to log , "send" , "receive" or "all" ( for all modules ) | | | level | number | log level for the pattern | |

Callback definitions

PollCallback

Callback to retrieve messages to be sent to the mqtt broker

PollCallback returns

| Type | Description | | ---- | ----------- | | Array.<Message>, Message | messages to send to the broker |

Class MqttClient

new MqttClient(options)

Creates a standard mqtt client , connects and subscribes to the broker

MqttClient Parameters

| Name | Type | Description | | ---------- | ------------ | ----------------- | | options | Object | options to provide for connection | |

options properties

| Name | Type | Attribute | Default | Description | | ---------- | ------------ | ------------ | ------------ | ----------------- | | clientId | string | | | unique id of the client | | | broker | Object | | | information of the broker to connect to | | | listener | number | | | port this client will listen to | | | version | string | optional | '1 . 0' | interface version | | | keepAliveInSeconds | string | optional | | connection keep alive time in seconds | | | clean | boolean | optional | true | clean the broker session on disconnect | | | retry | number | | | amount of retries to send messages to the broker | | | log | Array.<LogPattern> | | | logging settings | |

broker properties

| Name | Type | Description | | ---------- | ------------ | ----------------- | | host | string | hostname of the broker | | | port | number | port of the broker | |

MqttClient Members

| Name | Type | description | | ------------ | ------------ | ------------ | | connected | boolean | Connection status . true , iff connected | | token | Object.<send:string, receive:string> | Send and receive token to be used to communicate with the mqtt broker | | version | string | Gets/Sets the interface version to use |

MqttClient Methods

_createMemoryUsageMessage

_createMemoryUsageMessage () => {Message}

Creates a message showing the memory usage

_createMemoryUsageMessage returns

| Type | Description | | ---- | ----------- | | Message | the memory usage message with the topic $SYS/ [ clientId ] /memory usage |

close

async close ()

closes the client by shutting down all services and loops

isShuttingDown

isShuttingDown () => {boolean}

checks , if the client is shutting down . Every loop must stop once isShuttingDown is true

isShuttingDown returns

| Type | Description | | ---- | ----------- | | boolean | true , iff shutting down |

on

on (event, callback)

Sets a callback .

on Parameters

| Name | Type | Description | | ---------- | ------------ | ----------------- | | event | string | supports 'shutdown' | | | callback | function | | |

on throws

| Type | Description | | ---- | ----------- | | Error | if the event is not supported | | Error | if the callback is not 'function' |

publish

publish (message, serviceName)

Publishes a message to the broker

publish Parameters

| Name | Type | Description | | ---------- | ------------ | ----------------- | | message | Message | message to publish | | | serviceName | string | name of the publishing service | |

message properties

| Name | Type | Description | | ---------- | ------------ | ----------------- | | qos | number | quality of service ( 0 , 1 , 2 ) | | | retain | boolean | true to create a retain message | |

reconnect

async reconnect ()

Connects and subscribes to the broker

registerCloseFunction

registerCloseFunction (closeFunction)

Registers close functions . It will be called when the client close function is called

registerCloseFunction Parameters

| Name | Type | Description | | ---------- | ------------ | ----------------- | | closeFunction | function | function to be called on close commands | |

registerRecipient

async registerRecipient (serviceName, subscriptions, callback)

Registeres a recipient

registerRecipient Parameters

| Name | Type | Description | | ---------- | ------------ | ----------------- | | serviceName | string | name of the subscribing service | | | subscriptions | Object | subscription entries of format { topic : qos , topic : qos , . . . } | | | callback | function | function to send received messages to | |

registerRecipient throws

| Type | Description | | ---- | ----------- | | Error | If subscriptions are not well formatted or callback is not a function |

registerSender

registerSender (intervalInMilliseconds, callback)

Registeres a service sending messages in intervals . The service must provide a function ( callback ) without parameters returing an array of messages . The messages will then be sent to the broker

registerSender Parameters

| Name | Type | Description | | ---------- | ------------ | ----------------- | | intervalInMilliseconds | number | interval in milliseconds to call the senders callback | | | callback | PollCallback | function to call | |

run

async run ()

Starts the mqttclient . Opens the listener and connects to the broker

updateSubscriptions

async updateSubscriptions (serviceName, subscriptions)

Updates the subscriptions

updateSubscriptions Parameters

| Name | Type | Description | | ---------- | ------------ | ----------------- | | serviceName | string | name of the subscribing service | | | subscriptions | Object | subscription entries of format { topic : qos , topic : qos , . . . } | |

updateSubscriptions throws

| Type | Description | | ---- | ----------- | | Error | If subscriptions are not well formatted |