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/connections

v1.5.3

Published

Manages connections to a MQTT broker

Downloads

4

Readme

Abstract

Manages connections of the yaha Mqtt broker and provides functionality to receive/send messages from/to the managed connections in three service levels ( qos 0 , 1 , 2 )

Contents

Meta

| | | | --- | --- | | File | connections.js | | Abstract | Manages connections of the yaha Mqtt broker and provides functionality to receive/send messages from/to the managed connections in three service levels ( qos 0 , 1 , 2 ) | | 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 . |

Class Connections

new Connections(configuration)

Creates a connection object This class is part of an MQTT style broker . It manages connections to the broker .

Connections Parameters

| Name | Type | Description | | ---------- | ------------ | ----------------- | | configuration | Object | configuration | |

configuration properties

| Name | Type | Attribute | Default | Description | | ---------- | ------------ | ------------ | ------------ | ----------------- | | fileName | string | | | filename for persistence | | | directory | string | | | directory ( file path ) for persistence | | | replyTimeoutInMilliseconds | nubmber | optional | 10000 | timeout to wait for an answer of a http call | | | inFlightWindow | number | optional | 1 | amount of qos 1 and qos 2 messages send for the same topic at the same time | | | pubrelTimeoutInMilliseconds | number | optional | 24*3600*1000 | timout to wait for a corresponding pubrel message , default one day | | | maxRetryCount | number | optional | 10 | amount of resend of messages before forcing a disconnect | | | maxQueuSize | number | | | maximal amount of entries in a message queue | |

Connections Methods

acknowledgeMessage

acknowledgeMessage (queueEntry)

Acknowledges a message ( qos = 1 or 2 only )

acknowledgeMessage Parameters

| Name | Type | Description | | ---------- | ------------ | ----------------- | | queueEntry | MessageQueueEntry | entry of message queue acknowledged | |

checkToken

checkToken (token) => {string, undefined}

Checks , if a token corresponds to a client . Returns the client

checkToken Parameters

| Name | Type | | ---------- | ------------ | | token | string | |

checkToken throws

| Type | Description | | ---- | ----------- | | string | error message |

checkToken returns

| Type | Description | | ---- | ----------- | | string, undefined | clientId . |

cleanup

cleanup () => {Object}

Clean up jobs . Call regularly ( example once a minute ) Automatically disconnects clients not sending data until timeout

cleanup returns

| Type | Description | | ---- | ----------- | | Object | list of clientId beeing automatically disconnected . An object with reason : string and keepAlive : number is included for each disconnected clientId |

connect

connect (clientId, host, port, clean, version, keepAlive) => {Object}

Connects a client ( Stores a connection to a client )

connect Parameters

| Name | Type | Attribute | Default | Description | | ---------- | ------------ | ------------ | ------------ | ----------------- | | clientId | any | | | id of the client | | | host | string | | | host name | | | port | string | | | port name | | | clean | bool | | | true , if the connection will be cleaned on disconnect | | | version | string | optional | '1 . 0' | client interface version | | | keepAlive | number | optional | 3600000 | keep alive time in milliseconds . The broker will disconnect any client not sending messages in the keepAlive interval . Default is one hour | |

connect throws

| Type | Description | | ---- | ----------- | | Error | |

connect returns

| Type | Description | | ---- | ----------- | | Object | { mqttcode , present } present = = 1 , if an old session is recovered |

disconnect

disconnect (clientId)

Disconnects a client

disconnect Parameters

| Name | Type | Description | | ---------- | ------------ | ----------------- | | clientId | string | id of the client | |

disconnect throws

| Type | Description | | ---- | ----------- | | Error | |

getAllMessagesToSend

getAllMessagesToSend () => {integer}

Gets all messages to send for all clients function to be called for each message . The function has the parameter QoS and message

getAllMessagesToSend returns

| Type | Description | | ---- | ----------- | | integer | amount of messages sent |

isDuplicateQos2message

isDuplicateQos2message (clientId, topic, qos, dup, packetid)

Checks and remembers a qos2 message . Returns true , if the message is a duplicate

isDuplicateQos2message Parameters

| Name | Type | Description | | ---------- | ------------ | ----------------- | | clientId | string | id of the client | | | topic | string | topic sent | | | qos | Object | quality of service received from published headers | | | dup | boolean | true , if the message is a duplicate | | | packetid | string | id of the sender package | |

onPubrel

onPubrel (token, packetid)

Handles a pubrel message , deleting the entry from the qos2 queue

onPubrel Parameters

| Name | Type | Description | | ---------- | ------------ | ----------------- | | token | string | client send token | | | packetid | number | unique identifier of the corresponding publish packet | |

persist

async persist ()

Persists all connections

publishMessage

publishMessage (payload, qos, retain)

Adds messages that needs to be published

publishMessage Parameters

| Name | Type | Description | | ---------- | ------------ | ----------------- | | payload | Message | message to add to a publish storage | | | qos | Object | quality of service received from published headers | | | retain | boolean | true , if the message should be retained for future subscribers | |

restoreFromFile

async restoreFromFile ()

Restores all clients from last valid saved file

setWill

setWill (clientId, will)

Sets the will message of a client

setWill Parameters

| Name | Type | Description | | ---------- | ------------ | ----------------- | | clientId | string | id of the client | | | will | Object | will message configuration | |

will properties

| Name | Type | Description | | ---------- | ------------ | ----------------- | | qos | number | will message quality of service | | | retain | boolean | true , if the will message is retained | | | topic | string | topic of the will message | | | value | string, number | value of the will message | |

subscribe

subscribe (clientId, topics) => {Array.<number>}

Subscribes to topics

subscribe Parameters

| Name | Type | Description | | ---------- | ------------ | ----------------- | | clientId | string | id of the client | | | topics | Object | { QoS , topics } or { topic1 : QoS1 , topic2 : QoS2 , . . . } | |

subscribe returns

| Type | Description | | ---- | ----------- | | Array.<number> | array of QoS values |

unsubscribe

unsubscribe (clientId, topics)

Unsubsribes to topics

unsubscribe Parameters

| Name | Type | Description | | ---------- | ------------ | ----------------- | | clientId | string | id of the client | | | topics | Array.<string> | array of topics strings ( topic with wildchars '+' and '#' ) | |