1.3.2 • Published 3 years ago

@mangar2/connect v1.3.2

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

Abstract

Provides functions to connect to the ( http based ) yaha mqtt broker

Contents

Meta

Fileconnect.js
AbstractProvides functions to connect to the ( http based ) yaha mqtt broker
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 Connect

new Connect(clientId, brokerHost, brokerPort, listenerPort)

Organises connections to broker This is part of the http based mqtt broker . Use this class to connect/disconnect and subscribe/unsubscribe to the broker All functions are based on async/promises

Example

let connect = new Connect("/connect/test", "127.0.0.1", 9001, 9002);
result = await connect.connect(CLEAN);

Connect Parameters

NameTypeDescription
clientIdstringid of this client
brokerHoststringhostname ( or ip ) of the broker
brokerPortnumberport of the broker
listenerPortnumberport to listen for published messages from broker

Connect Members

NameTypedescription
isConnectedbooleanTrue , if the client is connected
tokenObject.<send:string, receive:string>Gets/Sets send and receive token

Connect Methods

close

async close ()

Closes the connection to the broker

connect

async connect (clean, version, keepAlive) => {Object}

Connects to the broker

connect Parameters
NameTypeAttributeDefaultDescription
cleanbooleantrue , if a disconnect shall clean any connection information
versionstringoptional'1 . 0'interface version ( 0 . 0 or 1 . 0 )
keepAlivenumberoptional600000time in milliseconds the broker will keep the connection without receiving calls
connect returns
TypeDescription
Objectpayload returned from connect request

connectAndSubscribe

async connectAndSubscribe (clean, topics, version, keepAlive) => {Object}

First connect , then subscribe

connectAndSubscribe Parameters
NameTypeAttributeDefaultDescription
cleanbooleantrue , if a disconnect shall clean any connection information
topicsObjecttopics to subscribe to { topic1 : QoS1 , topic2 : QoS2 , . . . }
versionstringoptional'1 . 0'interface version ( 0 . 0 or 1 . 0 )
keepAlivenumberoptional600000time in milliseconds the broker will keep the connection without receiving calls
connectAndSubscribe returns
TypeDescription
Objectcombined result from connect and subscribe

disconnect

async disconnect (version) => {Object}

Disconnects from the broker

disconnect Parameters
NameTypeAttributeDefaultDescription
versionstringoptional'1 . 0'interface version ( 0 . 0 or 1 . 0 )
disconnect returns
TypeDescription
Objectempty object

on

on (event, callback)

Sets a callback .

on Parameters
NameTypeDescription
eventstringevent name ( not case sensitive ) for the callback
callbackfunction( parameter )
on throws
TypeDescription
Errorif the event is not supported
Errorif the callback is not 'function'

pingreq

async pingreq () => {boolean}

Sends a ping request to signal the client is alive

pingreq returns
TypeDescription
booleantrue on success

subscribe

async subscribe (topics, version) => {Object}

Subscribe to the broker

subscribe Parameters
NameTypeAttributeDefaultDescription
topicsObjecttopics to subscribe to { topic1 : QoS1 , topic2 : QoS2 , . . . }
versionstringoptional'1 . 0'interface version ( 0 . 0 or 1 . 0 )
subscribe returns
TypeDescription
Objectpayload returned from subscribe request

unsubscribe

async unsubscribe (topics, version) => {Object}

Unsubscribes from the broker

unsubscribe Parameters
NameTypeAttributeDefaultDescription
topicsArraytopics to unsubscribe topic1 , topic2 , . . .
versionstringoptional'1 . 0'interface version ( 0 . 0 or 1 . 0 )
unsubscribe returns
TypeDescription
Objectempty object
1.3.2

3 years ago

1.3.1

4 years ago

1.3.0

4 years ago

1.2.1

5 years ago

1.2.0

5 years ago

1.1.5

5 years ago

1.1.4

5 years ago

1.1.2

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago