Methods
clientId() → {string}
Returns:
the client identifier
- Type
- string
closeHandler(closeHandler) → {MqttClient}
Set a handler that will be called when the connection with server is closed
Parameters:
Name | Type | Description |
---|---|---|
closeHandler |
function | handler to call |
Returns:
current MQTT client instance
- Type
- MqttClient
connect(connectHandler) → {MqttClient}
Connects to an MQTT server calling connectHandler after connection
Parameters:
Name | Type | Description |
---|---|---|
connectHandler |
function | handler called when the asynchronous connect call ends |
Returns:
current MQTT client instance
- Type
- MqttClient
disconnect(disconnectHandler) → {MqttClient}
Disconnects from the MQTT server calling disconnectHandler after disconnection
Parameters:
Name | Type | Description |
---|---|---|
disconnectHandler |
function | handler called when asynchronous disconnect call ends |
Returns:
current MQTT client instance
- Type
- MqttClient
exceptionHandler(handler) → {MqttClient}
Set an exception handler for the client, that will be called when an error happens
in internal netty structures.
io.netty.handler.codec.DecoderException
can be one of the cause
Parameters:
Name | Type | Description |
---|---|---|
handler |
function | the exception handler |
Returns:
current MQTT client instance
- Type
- MqttClient
ping() → {MqttClient}
This method is needed by the client in order to avoid server closes the
connection due to the keep alive timeout if client has no messages to send
Returns:
current MQTT client instance
- Type
- MqttClient
pingResponseHandler(pingResponseHandler) → {MqttClient}
Sets handler which will be called after PINGRESP packet receiving
Parameters:
Name | Type | Description |
---|---|---|
pingResponseHandler |
function | handler to call |
Returns:
current MQTT client instance
- Type
- MqttClient
publish(topic, payload, qosLevel, isDup, isRetain, publishSentHandler) → {MqttClient}
Sends the PUBLISH message to the remote MQTT server
Parameters:
Name | Type | Description |
---|---|---|
topic |
string | topic on which the message is published |
payload |
Buffer | message payload |
qosLevel |
Object | QoS level |
isDup |
boolean | if the message is a duplicate |
isRetain |
boolean | if the message needs to be retained |
publishSentHandler |
function | handler called after PUBLISH packet sent with packetid (not when QoS 0) |
Returns:
current MQTT client instance
- Type
- MqttClient
publishCompleteHandler(publishCompleteHandler) → {MqttClient}
Sets handler which will be called each time publish is completed
Parameters:
Name | Type | Description |
---|---|---|
publishCompleteHandler |
function | handler called with the packetId |
Returns:
current MQTT client instance
- Type
- MqttClient
publishHandler(publishHandler) → {MqttClient}
Sets handler which will be called each time server publish something to client
Parameters:
Name | Type | Description |
---|---|---|
publishHandler |
function | handler to call |
Returns:
current MQTT client instance
- Type
- MqttClient
subscribe(topic, qos, subscribeSentHandler) → {MqttClient}
Subscribes to the topic with a specified QoS level
Parameters:
Name | Type | Description |
---|---|---|
topic |
string | topic you subscribe on |
qos |
number | QoS level |
subscribeSentHandler |
function | handler called after SUBSCRIBE packet sent with packetid |
Returns:
current MQTT client instance
- Type
- MqttClient
subscribeCompleteHandler(subscribeCompleteHandler) → {MqttClient}
Sets handler which will be called after SUBACK packet receiving
Parameters:
Name | Type | Description |
---|---|---|
subscribeCompleteHandler |
function | handler to call. List inside is a granted QoS array |
Returns:
current MQTT client instance
- Type
- MqttClient
unsubscribe(topic, unsubscribeSentHandler) → {MqttClient}
Unsubscribe from receiving messages on given topic
Parameters:
Name | Type | Description |
---|---|---|
topic |
string | Topic you want to unsubscribe from |
unsubscribeSentHandler |
function | handler called after UNSUBSCRIBE packet sent |
Returns:
current MQTT client instance
- Type
- MqttClient
unsubscribeCompleteHandler(unsubscribeCompleteHandler) → {MqttClient}
Sets handler which will be called after UNSUBACK packet receiving
Parameters:
Name | Type | Description |
---|---|---|
unsubscribeCompleteHandler |
function | handler to call with the packetid |
Returns:
current MQTT client instance
- Type
- MqttClient