Class Index | File Index

Classes


Class Paho.MQTT.Client


Defined in: mqttws31.js.

Class Summary
Constructor Attributes Constructor Name and Description
 
Paho.MQTT.Client(host, port, path, clientId)
The JavaScript application communicates to the server using a Paho.MQTT.Client object.
Field Summary
Field Attributes Field Name and Description
 
- read only used when connecting to the server.
 
- read only the server's DNS hostname or dotted decimal IP address.
 
- called when a connection has been lost.
 
called when a message has arrived in this Paho.MQTT.client.
 
called when a message has been delivered.
 
- read only the server's path.
 
- read only the server's port.
Method Summary
Method Attributes Method Name and Description
 
connect(connectOptions)
Connect this Messaging client to its server.
 
Normal disconnect of this Messaging client from its server.
 
Get the contents of the trace log.
 
send(message)
Send a message to the consumers of the destination in the Message.
 
Start tracing.
 
Stop tracing.
 
subscribe(filter, subscribeOptions)
Subscribe for messages, request receipt of a copy of messages sent to the destinations described by the filter.
 
unsubscribe(filter, unsubscribeOptions)
Unsubscribe for messages, stop receiving messages sent to destinations described by the filter.
Class Detail
Paho.MQTT.Client(host, port, path, clientId)
The JavaScript application communicates to the server using a Paho.MQTT.Client object.

Most applications will create just one Client object and then call its connect() method, however applications can create more than one Client object if they wish. In this case the combination of host, port and clientId attributes must be different for each Client object.

The send, subscribe and unsubscribe methods are implemented as asynchronous JavaScript methods (even though the underlying protocol exchange might be synchronous in nature). This means they signal their completion by calling back to the application, via Success or Failure callback functions provided by the application on the method in question. Such callbacks are called at most once per method invocation and do not persist beyond the lifetime of the script that made the invocation.

In contrast there are some callback functions, most notably onMessageArrived, that are defined on the Paho.MQTT.Client object. These may get called multiple times, and aren't directly related to specific method invocations made by the client.

Parameters:
{string} host
- the address of the messaging server, as a fully qualified WebSocket URI, as a DNS name or dotted decimal IP address.
{number} port
- the port number to connect to - only required if host is not a URI
{string} path
- the path on the host to connect to - only used if host is not a URI. Default: '/mqtt'.
{string} clientId
- the Messaging client identifier, between 1 and 23 characters in length.
Field Detail
{string} clientId
- read only used when connecting to the server.

{string} host
- read only the server's DNS hostname or dotted decimal IP address.

{function} onConnectionLost
- called when a connection has been lost. after a connect() method has succeeded. Establish the call back used when a connection has been lost. The connection may be lost because the client initiates a disconnect or because the server or network cause the client to be disconnected. The disconnect call back may be called without the connectionComplete call back being invoked if, for example the client fails to connect. A single response object parameter is passed to the onConnectionLost callback containing the following fields:
  1. errorCode
  2. errorMessage

{function} onMessageArrived
called when a message has arrived in this Paho.MQTT.client. Parameters passed to the onMessageArrived callback are:
  1. Paho.MQTT.Message that has arrived.

{function} onMessageDelivered
called when a message has been delivered. All processing that this Client will ever do has been completed. So, for example, in the case of a Qos=2 message sent by this client, the PubComp flow has been received from the server and the message has been removed from persistent storage before this callback is invoked. Parameters passed to the onMessageDelivered callback are:
  1. Paho.MQTT.Message that was delivered.

{string} path
- read only the server's path.

{number} port
- read only the server's port.
Method Detail
connect(connectOptions)
Connect this Messaging client to its server.
Parameters:
{Object} connectOptions
- attributes used with the connection.
{number} connectOptions.timeout
- If the connect has not succeeded within this number of seconds, it is deemed to have failed. The default is 30 seconds.
{string} connectOptions.userName
- Authentication username for this connection.
{string} connectOptions.password
- Authentication password for this connection.
{Paho.MQTT.Message} connectOptions.willMessage
- sent by the server when the client disconnects abnormally.
{Number} connectOptions.keepAliveInterval
- the server disconnects this client if there is no activity for this number of seconds. The default value of 60 seconds is assumed if not set.
{boolean} connectOptions.cleanSession
- if true(default) the client and server persistent state is deleted on successful connect.
{boolean} connectOptions.useSSL
- if present and true, use an SSL Websocket connection.
{object} connectOptions.invocationContext
- passed to the onSuccess callback or onFailure callback.
{function} connectOptions.onSuccess
- called when the connect acknowledgement has been received from the server. A single response object parameter is passed to the onSuccess callback containing the following fields:
  1. invocationContext as passed in to the onSuccess method in the connectOptions.
{Number} connectOptions.mqttVersion
- The standard action is to connect as MQTT 3.1.1 if that fails fallback and try to connect as MQTT 3.1. Setting this option tells the client to connect explicitly at one level only.
  • 3 - MQTT 3.1
  • 4 - MQTT 3.1.1
{function} connectOptions.onFailure Optional
called when the connect request has failed or timed out. A single response object parameter is passed to the onFailure callback containing the following fields:
  1. invocationContext as passed in to the onFailure method in the connectOptions.
  2. errorCode a number indicating the nature of the error.
  3. errorMessage text describing the error.
{Array} connectOptions.hosts Optional
If present this contains either a set of hostnames or fully qualified WebSocket URIs (ws://example.com:1883/mqtt), that are tried in order in place of the host and port paramater on the construtor. The hosts are tried one at at time in order until one of then succeeds.
{Array} connectOptions.ports Optional
If present the set of ports matching the hosts. If hosts contains URIs, this property is not used.
Throws:
{InvalidState}
if the client is not in disconnected state. The client must have received connectionLost or disconnected before calling connect for a second or subsequent time.

disconnect()
Normal disconnect of this Messaging client from its server.
Throws:
{InvalidState}
if the client is already disconnected.

{Object[]} getTraceLog()
Get the contents of the trace log.
Returns:
{Object[]} tracebuffer containing the time ordered trace records.

send(message)
Send a message to the consumers of the destination in the Message.
Parameters:
{Paho.MQTT.Message} message
to send.
Throws:
{InvalidState}
if the client is not connected.

startTrace()
Start tracing.

stopTrace()
Stop tracing.

subscribe(filter, subscribeOptions)
Subscribe for messages, request receipt of a copy of messages sent to the destinations described by the filter.
Parameters:
{string} filter
describing the destinations to receive messages from.
{object} subscribeOptions
- used to control the subscription
{number} subscribeOptions.qos
- the maiximum qos of any publications sent as a result of making this subscription.
{object} subscribeOptions.invocationContext
- passed to the onSuccess callback or onFailure callback.
{function} subscribeOptions.onSuccess
- called when the subscribe acknowledgement has been received from the server. A single response object parameter is passed to the onSuccess callback containing the following fields:
  1. invocationContext if set in the subscribeOptions.
  2. grantedQos the QoS value granted to the subscription by the server.
{function} subscribeOptions.onFailure
- called when the subscribe request has failed or timed out. A single response object parameter is passed to the onFailure callback containing the following fields:
  1. invocationContext - if set in the subscribeOptions.
  2. errorCode - a number indicating the nature of the error.
{number} subscribeOptions.timeout
- which, if present, determines the number of seconds after which the onFailure calback is called. The presence of a timeout does not prevent the onSuccess callback from being called when the subscribe completes.
Throws:
{InvalidState}
if the client is not in connected state.

unsubscribe(filter, unsubscribeOptions)
Unsubscribe for messages, stop receiving messages sent to destinations described by the filter.
Parameters:
{string} filter
- describing the destinations to receive messages from.
{object} unsubscribeOptions
- used to control the subscription
{object} unsubscribeOptions.invocationContext
- passed to the onSuccess callback or onFailure callback.
{function} unsubscribeOptions.onSuccess
- called when the unsubscribe acknowledgement has been received from the server. A single response object parameter is passed to the onSuccess callback containing the following fields:
  1. invocationContext - if set in the unsubscribeOptions.
{function} unsubscribeOptions.onFailure
called when the unsubscribe request has failed or timed out. A single response object parameter is passed to the onFailure callback containing the following fields:
  1. invocationContext - if set in the unsubscribeOptions.
  2. errorCode - a number indicating the nature of the error.
  3. errorMessage - text describing the error.
{number} unsubscribeOptions.timeout
- which, if present, determines the number of seconds after which the onFailure callback is called. The presence of a timeout does not prevent the onSuccess callback from being called when the unsubscribe completes
Throws:
{InvalidState}
if the client is not in connected state.

Documentation generated by JsDoc Toolkit 2.4.0 on Mon Jul 21 2014 11:26:45 GMT+0100 (BST)