1.5.3 • Published 3 years ago

@mangar2/connections v1.5.3

Weekly downloads
19
License
LGPL-3.0-or-later
Repository
github
Last release
3 years ago

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

Fileconnections.js
AbstractManages 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 )
AuthorVolker Böhm
CopyrightCopyright ( c ) 2020 Volker Böhm
LicenseThis 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

NameTypeDescription
configurationObjectconfiguration

configuration properties

NameTypeAttributeDefaultDescription
fileNamestringfilename for persistence
directorystringdirectory ( file path ) for persistence
replyTimeoutInMillisecondsnubmberoptional10000timeout to wait for an answer of a http call
inFlightWindownumberoptional1amount of qos 1 and qos 2 messages send for the same topic at the same time
pubrelTimeoutInMillisecondsnumberoptional24*3600*1000timout to wait for a corresponding pubrel message , default one day
maxRetryCountnumberoptional10amount of resend of messages before forcing a disconnect
maxQueuSizenumbermaximal amount of entries in a message queue

Connections Methods

acknowledgeMessage

acknowledgeMessage (queueEntry)

Acknowledges a message ( qos = 1 or 2 only )

acknowledgeMessage Parameters
NameTypeDescription
queueEntryMessageQueueEntryentry of message queue acknowledged

checkToken

checkToken (token) => {string, undefined}

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

checkToken Parameters
NameType
tokenstring
checkToken throws
TypeDescription
stringerror message
checkToken returns
TypeDescription
string, undefinedclientId .

cleanup

cleanup () => {Object}

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

cleanup returns
TypeDescription
Objectlist 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
NameTypeAttributeDefaultDescription
clientIdanyid of the client
hoststringhost name
portstringport name
cleanbooltrue , if the connection will be cleaned on disconnect
versionstringoptional'1 . 0'client interface version
keepAlivenumberoptional3600000keep alive time in milliseconds . The broker will disconnect any client not sending messages in the keepAlive interval . Default is one hour
connect throws
TypeDescription
Error
connect returns
TypeDescription
Object{ mqttcode , present } present = = 1 , if an old session is recovered

disconnect

disconnect (clientId)

Disconnects a client

disconnect Parameters
NameTypeDescription
clientIdstringid of the client
disconnect throws
TypeDescription
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
TypeDescription
integeramount 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
NameTypeDescription
clientIdstringid of the client
topicstringtopic sent
qosObjectquality of service received from published headers
dupbooleantrue , if the message is a duplicate
packetidstringid of the sender package

onPubrel

onPubrel (token, packetid)

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

onPubrel Parameters
NameTypeDescription
tokenstringclient send token
packetidnumberunique 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
NameTypeDescription
payloadMessagemessage to add to a publish storage
qosObjectquality of service received from published headers
retainbooleantrue , 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
NameTypeDescription
clientIdstringid of the client
willObjectwill message configuration

will properties

NameTypeDescription
qosnumberwill message quality of service
retainbooleantrue , if the will message is retained
topicstringtopic of the will message
valuestring, numbervalue of the will message

subscribe

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

Subscribes to topics

subscribe Parameters
NameTypeDescription
clientIdstringid of the client
topicsObject{ QoS , topics } or { topic1 : QoS1 , topic2 : QoS2 , . . . }
subscribe returns
TypeDescription
Array.<number>array of QoS values

unsubscribe

unsubscribe (clientId, topics)

Unsubsribes to topics

unsubscribe Parameters
NameTypeDescription
clientIdstringid of the client
topicsArray.<string>array of topics strings ( topic with wildchars '+' and '#' )
1.5.3

3 years ago

1.5.2

3 years ago

1.5.1

3 years ago

1.5.0

3 years ago

1.3.4

4 years ago

1.4.0

4 years ago

1.3.3

4 years ago

1.3.0

4 years ago

1.1.1

4 years ago

1.1.0

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago