mqtt 5.0.0-beta.0 → 5.0.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,25 +1,28 @@
1
- ![mqtt.js](https://raw.githubusercontent.com/mqttjs/MQTT.js/137ee0e3940c1f01049a30248c70f24dc6e6f829/MQTT.js.png)
2
- =======
1
+ # ![mqtt.js](https://raw.githubusercontent.com/mqttjs/MQTT.js/137ee0e3940c1f01049a30248c70f24dc6e6f829/MQTT.js.png)
3
2
 
4
- ![Github Test Status](https://github.com/mqttjs/MQTT.js/workflows/MQTT.js%20CI/badge.svg) [![codecov](https://codecov.io/gh/mqttjs/MQTT.js/branch/master/graph/badge.svg)](https://codecov.io/gh/mqttjs/MQTT.js)
3
+ ![Github Test Status](https://github.com/mqttjs/MQTT.js/workflows/MQTT.js%20CI/badge.svg) [![codecov](https://codecov.io/gh/mqttjs/MQTT.js/branch/master/graph/badge.svg)](https://codecov.io/gh/mqttjs/MQTT.js)
5
4
 
6
5
  MQTT.js is a client library for the [MQTT](http://mqtt.org/) protocol, written
7
6
  in JavaScript for node.js and the browser.
8
7
 
8
+ > MQTT [5.0.0-beta.0](https://github.com/mqttjs/MQTT.js/releases/tag/v5.0.0-beta.0) is now available! Try it out and give us feedback! `npm i mqtt@5.0.0-beta.0`
9
+
9
10
  ## Table of Contents
10
- * [__MQTT.js vNext__](#vnext)
11
- * [Upgrade notes](#notes)
12
- * [Installation](#install)
13
- * [Example](#example)
14
- * [Import Styles](#example)
15
- * [Command Line Tools](#cli)
16
- * [API](#api)
17
- * [Browser](#browser)
18
- * [About QoS](#qos)
19
- * [TypeScript](#typescript)
20
- * [Weapp and Ali support](#weapp-alipay)
21
- * [Contributing](#contributing)
22
- * [License](#license)
11
+
12
+ - [**MQTT.js vNext**](#vnext)
13
+ - [Upgrade notes](#notes)
14
+ - [Installation](#install)
15
+ - [Example](#example)
16
+ - [Import Styles](#example)
17
+ - [Command Line Tools](#cli)
18
+ - [API](#api)
19
+ - [Browser](#browser)
20
+ - [About QoS](#qos)
21
+ - [TypeScript](#typescript)
22
+ - [Weapp and Ali support](#weapp-alipay)
23
+ - [Contributing](#contributing)
24
+ - [Sponsor](#sponsor)
25
+ - [License](#license)
23
26
 
24
27
  MQTT.js is an OPEN Open Source Project, see the [Contributing](#contributing) section to find out what this means.
25
28
 
@@ -27,40 +30,45 @@ MQTT.js is an OPEN Open Source Project, see the [Contributing](#contributing) se
27
30
  Guide](https://cdn.rawgit.com/feross/standard/master/badge.svg)](https://github.com/feross/standard)
28
31
 
29
32
  <a name="vnext"></a>
33
+
30
34
  ## Next major version of MQTT.js
35
+
31
36
  There is work being done on the next generation of MQTT.js (vNext). We invite the community to provide their contributions [this repository](https://github.com/mqttjs/mqttjs-v5)
32
37
 
33
38
  <a name="notes"></a>
39
+
34
40
  ## Important notes for existing users
35
41
 
36
- __v4.0.0__ (Released 04/2020) removes support for all end of life node versions, and now supports node v12 and v14. It also adds improvements to
42
+ **v5.0.0** (**BETA** 06/2023) removes support for all end of life node versions (v12 and v14), and now supports node v18 and v20.
43
+
44
+ **v4.0.0** (Released 04/2020) removes support for all end of life node versions, and now supports node v12 and v14. It also adds improvements to
37
45
  debug logging, along with some feature additions.
38
46
 
39
- As a __breaking change__, by default a error handler is built into the MQTT.js client, so if any
47
+ As a **breaking change**, by default a error handler is built into the MQTT.js client, so if any
40
48
  errors are emitted and the user has not created an event handler on the client for errors, the client will
41
49
  not break as a result of unhandled errors. Additionally, typical TLS errors like `ECONNREFUSED`, `ECONNRESET` have been
42
50
  added to a list of TLS errors that will be emitted from the MQTT.js client, and so can be handled as connection errors.
43
51
 
44
- __v3.0.0__ adds support for MQTT 5, support for node v10.x, and many fixes to improve reliability.
52
+ **v3.0.0** adds support for MQTT 5, support for node v10.x, and many fixes to improve reliability.
45
53
 
46
- __Note:__ MQTT v5 support is experimental as it has not been implemented by brokers yet.
54
+ **Note:** MQTT v5 support is experimental as it has not been implemented by brokers yet.
47
55
 
48
- __v2.0.0__ removes support for node v0.8, v0.10 and v0.12, and it is 3x faster in sending
56
+ **v2.0.0** removes support for node v0.8, v0.10 and v0.12, and it is 3x faster in sending
49
57
  packets. It also removes all the deprecated functionality in v1.0.0,
50
58
  mainly `mqtt.createConnection` and `mqtt.Server`. From v2.0.0,
51
59
  subscriptions are restored upon reconnection if `clean: true`.
52
- v1.x.x is now in *LTS*, and it will keep being supported as long as
60
+ v1.x.x is now in _LTS_, and it will keep being supported as long as
53
61
  there are v0.8, v0.10 and v0.12 users.
54
62
 
55
- As a __breaking change__, the `encoding` option in the old client is
63
+ As a **breaking change**, the `encoding` option in the old client is
56
64
  removed, and now everything is UTF-8 with the exception of the
57
65
  `password` in the CONNECT message and `payload` in the PUBLISH message,
58
66
  which are `Buffer`.
59
67
 
60
- Another __breaking change__ is that MQTT.js now defaults to MQTT v3.1.1,
68
+ Another **breaking change** is that MQTT.js now defaults to MQTT v3.1.1,
61
69
  so to support old brokers, please read the [client options doc](#client).
62
70
 
63
- __v1.0.0__ improves the overall architecture of the project, which is now
71
+ **v1.0.0** improves the overall architecture of the project, which is now
64
72
  split into three components: MQTT.js keeps the Client,
65
73
  [mqtt-connection](http://npm.im/mqtt-connection) includes the barebone
66
74
  Connection code for server-side usage, and [mqtt-packet](http://npm.im/mqtt-packet)
@@ -71,6 +79,7 @@ support for QoS 1 and 2. The previous API is still supported but
71
79
  deprecated, as such, it is not documented in this README.
72
80
 
73
81
  <a name="install"></a>
82
+
74
83
  ## Installation
75
84
 
76
85
  ```sh
@@ -78,30 +87,32 @@ npm install mqtt --save
78
87
  ```
79
88
 
80
89
  <a name="example"></a>
90
+
81
91
  ## Example
82
92
 
83
93
  For the sake of simplicity, let's put the subscriber and the publisher in the same file:
84
94
 
85
95
  ```js
86
- const mqtt = require('mqtt')
87
- const client = mqtt.connect('mqtt://test.mosquitto.org')
96
+ const mqtt = require("mqtt");
97
+ const client = mqtt.connect("mqtt://test.mosquitto.org");
88
98
 
89
- client.on('connect', function () {
90
- client.subscribe('presence', function (err) {
99
+ client.on("connect", function () {
100
+ client.subscribe("presence", function (err) {
91
101
  if (!err) {
92
- client.publish('presence', 'Hello mqtt')
102
+ client.publish("presence", "Hello mqtt");
93
103
  }
94
- })
95
- })
104
+ });
105
+ });
96
106
 
97
- client.on('message', function (topic, message) {
107
+ client.on("message", function (topic, message) {
98
108
  // message is Buffer
99
- console.log(message.toString())
100
- client.end()
101
- })
109
+ console.log(message.toString());
110
+ client.end();
111
+ });
102
112
  ```
103
113
 
104
114
  output:
115
+
105
116
  ```
106
117
  Hello mqtt
107
118
  ```
@@ -118,30 +129,40 @@ If you do not want to install a separate broker, you can try using the
118
129
  to use MQTT.js in the browser see the [browserify](#browserify) section
119
130
 
120
131
  <a name="import_styles"></a>
132
+
121
133
  ## Import styles
134
+
122
135
  ### CommonJS (Require)
136
+
123
137
  ```js
124
- const mqtt = require('mqtt') // require mqtt
125
- const client = mqtt.connect('est.mosquitto.org') // create a client
138
+ const mqtt = require("mqtt") // require mqtt
139
+ const client = mqtt.connect("test.mosquitto.org") // create a client
126
140
  ```
141
+
127
142
  ### ES6 Modules (Import)
143
+
128
144
  #### Aliased wildcard import
145
+
129
146
  ```js
130
- import * as mqtt from "mqtt" // import everything inside the mqtt module and give it the namespace "mqtt"
131
- let client = mqtt.connect('mqtt://test.mosquitto.org') // create a client
147
+ import * as mqtt from "mqtt"; // import everything inside the mqtt module and give it the namespace "mqtt"
148
+ let client = mqtt.connect("mqtt://test.mosquitto.org"); // create a client
132
149
  ```
150
+
133
151
  #### Importing individual components
152
+
134
153
  ```js
135
- import { connect } from "mqtt" // import connect from mqtt
136
- let client = connect('mqtt://test.mosquitto.org') // create a client
154
+ import { connect } from "mqtt"; // import connect from mqtt
155
+ let client = connect("mqtt://test.mosquitto.org"); // create a client
137
156
  ```
138
157
 
139
158
  <a name="promises"></a>
159
+
140
160
  ## Promise support
141
161
 
142
162
  If you want to use the new [async-await](https://blog.risingstack.com/async-await-node-js-7-nightly/) functionality in JavaScript, or just prefer using Promises instead of callbacks, [async-mqtt](https://github.com/mqttjs/async-mqtt) is a wrapper over MQTT.js which uses promises instead of callbacks when possible.
143
163
 
144
164
  <a name="cli"></a>
165
+
145
166
  ## Command Line Tools
146
167
 
147
168
  MQTT.js bundles a command to interact with a broker.
@@ -167,9 +188,11 @@ mqtt pub -t 'hello' -h 'test.mosquitto.org' -m 'from MQTT.js'
167
188
  See `mqtt help <command>` for the command help.
168
189
 
169
190
  <a name="debug"></a>
191
+
170
192
  ## Debug Logs
171
193
 
172
194
  MQTT.js uses the [debug](https://www.npmjs.com/package/debug#cmd) package for debugging purposes. To enable debug logs, add the following environment variable on runtime :
195
+
173
196
  ```ps
174
197
  # (example using PowerShell, the VS Code default)
175
198
  $env:DEBUG='mqttjs*'
@@ -177,6 +200,7 @@ $env:DEBUG='mqttjs*'
177
200
  ```
178
201
 
179
202
  <a name="reconnecting"></a>
203
+
180
204
  ## About Reconnection
181
205
 
182
206
  An important part of any websocket connection is what to do when a connection
@@ -198,6 +222,7 @@ To address this we can use a hook called `transformWsUrl` to manipulate
198
222
  either of the connection url or the client options at the time of a reconnect.
199
223
 
200
224
  Example (update clientId & username on each reconnect):
225
+
201
226
  ```
202
227
  const transformWsUrl = (url, options, client) => {
203
228
  client.options.username = `token=${this.get_current_auth_token()}`;
@@ -212,6 +237,7 @@ Example (update clientId & username on each reconnect):
212
237
  });
213
238
 
214
239
  ```
240
+
215
241
  Now every time a new WebSocket connection is opened (hopefully not too often),
216
242
  we will get a fresh signed url or fresh auth token data.
217
243
 
@@ -220,7 +246,6 @@ use the latest auth token, you must have some outside mechanism running that
220
246
  handles application-level authentication refreshing so that the websocket
221
247
  connection can simply grab the latest valid token or signed url.
222
248
 
223
-
224
249
  #### Enabling Reconnection with `reconnectPeriod` option
225
250
 
226
251
  To ensure that the mqtt client automatically tries to reconnect when the
@@ -232,12 +257,15 @@ The default value is 1000 ms which means it will try to reconnect 1 second
232
257
  after losing the connection.
233
258
 
234
259
  <a name="topicalias"></a>
260
+
235
261
  ## About Topic Alias Management
236
262
 
237
263
  ### Enabling automatic Topic Alias using
264
+
238
265
  If the client sets the option `autoUseTopicAlias:true` then MQTT.js uses existing topic alias automatically.
239
266
 
240
267
  example scenario:
268
+
241
269
  ```
242
270
  1. PUBLISH topic:'t1', ta:1 (register)
243
271
  2. PUBLISH topic:'t1' -> topic:'', ta:1 (auto use existing map entry)
@@ -250,12 +278,13 @@ User doesn't need to manage which topic is mapped to which topic alias.
250
278
  If the user want to register topic alias, then publish topic with topic alias.
251
279
  If the user want to use topic alias, then publish topic without topic alias. If there is a mapped topic alias then added it as a property and update the topic to empty string.
252
280
 
253
- ### Enabling automatic Topic Alias assign
281
+ ### Enabling automatic Topic Alias assign
254
282
 
255
283
  If the client sets the option `autoAssignTopicAlias:true` then MQTT.js uses existing topic alias automatically.
256
284
  If no topic alias exists, then assign a new vacant topic alias automatically. If topic alias is fully used, then LRU(Least Recently Used) topic-alias entry is overwritten.
257
285
 
258
286
  example scenario:
287
+
259
288
  ```
260
289
  The broker returns CONNACK (TopicAliasMaximum:3)
261
290
  1. PUBLISH topic:'t1' -> 't1', ta:1 (auto assign t1:1 and register)
@@ -268,28 +297,31 @@ The broker returns CONNACK (TopicAliasMaximum:3)
268
297
  Also user can manually register topic-alias pair using PUBLISH topic:'some', ta:X. It works well with automatic topic alias assign.
269
298
 
270
299
  <a name="api"></a>
300
+
271
301
  ## API
272
302
 
273
- * <a href="#connect"><code>mqtt.<b>connect()</b></code></a>
274
- * <a href="#client"><code>mqtt.<b>Client()</b></code></a>
275
- * <a href="#publish"><code>mqtt.Client#<b>publish()</b></code></a>
276
- * <a href="#subscribe"><code>mqtt.Client#<b>subscribe()</b></code></a>
277
- * <a href="#unsubscribe"><code>mqtt.Client#<b>unsubscribe()</b></code></a>
278
- * <a href="#end"><code>mqtt.Client#<b>end()</b></code></a>
279
- * <a href="#removeOutgoingMessage"><code>mqtt.Client#<b>removeOutgoingMessage()</b></code></a>
280
- * <a href="#reconnect"><code>mqtt.Client#<b>reconnect()</b></code></a>
281
- * <a href="#handleMessage"><code>mqtt.Client#<b>handleMessage()</b></code></a>
282
- * <a href="#connected"><code>mqtt.Client#<b>connected</b></code></a>
283
- * <a href="#reconnecting"><code>mqtt.Client#<b>reconnecting</b></code></a>
284
- * <a href="#getLastMessageId"><code>mqtt.Client#<b>getLastMessageId()</b></code></a>
285
- * <a href="#store"><code>mqtt.<b>Store()</b></code></a>
286
- * <a href="#put"><code>mqtt.Store#<b>put()</b></code></a>
287
- * <a href="#del"><code>mqtt.Store#<b>del()</b></code></a>
288
- * <a href="#createStream"><code>mqtt.Store#<b>createStream()</b></code></a>
289
- * <a href="#close"><code>mqtt.Store#<b>close()</b></code></a>
290
-
291
- -------------------------------------------------------
303
+ - <a href="#connect"><code>mqtt.<b>connect()</b></code></a>
304
+ - <a href="#client"><code>mqtt.<b>Client()</b></code></a>
305
+ - <a href="#publish"><code>mqtt.Client#<b>publish()</b></code></a>
306
+ - <a href="#subscribe"><code>mqtt.Client#<b>subscribe()</b></code></a>
307
+ - <a href="#unsubscribe"><code>mqtt.Client#<b>unsubscribe()</b></code></a>
308
+ - <a href="#end"><code>mqtt.Client#<b>end()</b></code></a>
309
+ - <a href="#removeOutgoingMessage"><code>mqtt.Client#<b>removeOutgoingMessage()</b></code></a>
310
+ - <a href="#reconnect"><code>mqtt.Client#<b>reconnect()</b></code></a>
311
+ - <a href="#handleMessage"><code>mqtt.Client#<b>handleMessage()</b></code></a>
312
+ - <a href="#connected"><code>mqtt.Client#<b>connected</b></code></a>
313
+ - <a href="#reconnecting"><code>mqtt.Client#<b>reconnecting</b></code></a>
314
+ - <a href="#getLastMessageId"><code>mqtt.Client#<b>getLastMessageId()</b></code></a>
315
+ - <a href="#store"><code>mqtt.<b>Store()</b></code></a>
316
+ - <a href="#put"><code>mqtt.Store#<b>put()</b></code></a>
317
+ - <a href="#del"><code>mqtt.Store#<b>del()</b></code></a>
318
+ - <a href="#createStream"><code>mqtt.Store#<b>createStream()</b></code></a>
319
+ - <a href="#close"><code>mqtt.Store#<b>close()</b></code></a>
320
+
321
+ ---
322
+
292
323
  <a name="connect"></a>
324
+
293
325
  ### mqtt.connect([url], options)
294
326
 
295
327
  Connects to the broker specified by the given url and options and
@@ -308,8 +340,10 @@ at every connect.
308
340
  For all MQTT-related options, see the [Client](#client)
309
341
  constructor.
310
342
 
311
- -------------------------------------------------------
343
+ ---
344
+
312
345
  <a name="client"></a>
346
+
313
347
  ### mqtt.Client(streamBuilder, options)
314
348
 
315
349
  The `Client` class wraps a client connection to an
@@ -318,72 +352,72 @@ WebSocket, ecc).
318
352
 
319
353
  `Client` automatically handles the following:
320
354
 
321
- * Regular server pings
322
- * QoS flow
323
- * Automatic reconnections
324
- * Start publishing before being connected
355
+ - Regular server pings
356
+ - QoS flow
357
+ - Automatic reconnections
358
+ - Start publishing before being connected
325
359
 
326
360
  The arguments are:
327
361
 
328
- * `streamBuilder` is a function that returns a subclass of the `Stream` class that supports
329
- the `connect` event. Typically a `net.Socket`.
330
- * `options` is the client connection options (see: the [connect packet](https://github.com/mcollina/mqtt-packet#connect)). Defaults:
331
- * `wsOptions`: is the WebSocket connection options. Default is `{}`.
332
- It's specific for WebSockets. For possible options have a look at: https://github.com/websockets/ws/blob/master/doc/ws.md.
333
- * `keepalive`: `60` seconds, set to `0` to disable
334
- * `reschedulePings`: reschedule ping messages after sending packets (default `true`)
335
- * `clientId`: `'mqttjs_' + Math.random().toString(16).substr(2, 8)`
336
- * `protocolId`: `'MQTT'`
337
- * `protocolVersion`: `4`
338
- * `clean`: `true`, set to false to receive QoS 1 and 2 messages while
362
+ - `streamBuilder` is a function that returns a subclass of the `Stream` class that supports
363
+ the `connect` event. Typically a `net.Socket`.
364
+ - `options` is the client connection options (see: the [connect packet](https://github.com/mcollina/mqtt-packet#connect)). Defaults:
365
+ - `wsOptions`: is the WebSocket connection options. Default is `{}`.
366
+ It's specific for WebSockets. For possible options have a look at: https://github.com/websockets/ws/blob/master/doc/ws.md.
367
+ - `keepalive`: `60` seconds, set to `0` to disable
368
+ - `reschedulePings`: reschedule ping messages after sending packets (default `true`)
369
+ - `clientId`: `'mqttjs_' + Math.random().toString(16).substr(2, 8)`
370
+ - `protocolId`: `'MQTT'`
371
+ - `protocolVersion`: `4`
372
+ - `clean`: `true`, set to false to receive QoS 1 and 2 messages while
339
373
  offline
340
- * `reconnectPeriod`: `1000` milliseconds, interval between two
374
+ - `reconnectPeriod`: `1000` milliseconds, interval between two
341
375
  reconnections. Disable auto reconnect by setting to `0`.
342
- * `connectTimeout`: `30 * 1000` milliseconds, time to wait before a
376
+ - `connectTimeout`: `30 * 1000` milliseconds, time to wait before a
343
377
  CONNACK is received
344
- * `username`: the username required by your broker, if any
345
- * `password`: the password required by your broker, if any
346
- * `incomingStore`: a [Store](#store) for the incoming packets
347
- * `outgoingStore`: a [Store](#store) for the outgoing packets
348
- * `queueQoSZero`: if connection is broken, queue outgoing QoS zero messages (default `true`)
349
- * `customHandleAcks`: MQTT 5 feature of custom handling puback and pubrec packets. Its callback:
350
- ```js
351
- customHandleAcks: function(topic, message, packet, done) {/*some logic wit colling done(error, reasonCode)*/}
352
- ```
353
- * `autoUseTopicAlias`: enabling automatic Topic Alias using functionality
354
- * `autoAssignTopicAlias`: enabling automatic Topic Alias assign functionality
355
- * `properties`: properties MQTT 5.0.
356
- `object` that supports the following properties:
357
- * `sessionExpiryInterval`: representing the Session Expiry Interval in seconds `number`,
358
- * `receiveMaximum`: representing the Receive Maximum value `number`,
359
- * `maximumPacketSize`: representing the Maximum Packet Size the Client is willing to accept `number`,
360
- * `topicAliasMaximum`: representing the Topic Alias Maximum value indicates the highest value that the Client will accept as a Topic Alias sent by the Server `number`,
361
- * `requestResponseInformation`: The Client uses this value to request the Server to return Response Information in the CONNACK `boolean`,
362
- * `requestProblemInformation`: The Client uses this value to indicate whether the Reason String or User Properties are sent in the case of failures `boolean`,
363
- * `userProperties`: The User Property is allowed to appear multiple times to represent multiple name, value pairs `object`,
364
- * `authenticationMethod`: the name of the authentication method used for extended authentication `string`,
365
- * `authenticationData`: Binary Data containing authentication data `binary`
366
- * `authPacket`: settings for auth packet `object`
367
- * `will`: a message that will sent by the broker automatically when
368
- the client disconnect badly. The format is:
369
- * `topic`: the topic to publish
370
- * `payload`: the message to publish
371
- * `qos`: the QoS
372
- * `retain`: the retain flag
373
- * `properties`: properties of will by MQTT 5.0:
374
- * `willDelayInterval`: representing the Will Delay Interval in seconds `number`,
375
- * `payloadFormatIndicator`: Will Message is UTF-8 Encoded Character Data or not `boolean`,
376
- * `messageExpiryInterval`: value is the lifetime of the Will Message in seconds and is sent as the Publication Expiry Interval when the Server publishes the Will Message `number`,
377
- * `contentType`: describing the content of the Will Message `string`,
378
- * `responseTopic`: String which is used as the Topic Name for a response message `string`,
379
- * `correlationData`: The Correlation Data is used by the sender of the Request Message to identify which request the Response Message is for when it is received `binary`,
380
- * `userProperties`: The User Property is allowed to appear multiple times to represent multiple name, value pairs `object`
381
- * `transformWsUrl` : optional `(url, options, client) => url` function
382
- For ws/wss protocols only. Can be used to implement signing
383
- urls which upon reconnect can have become expired.
384
- * `resubscribe` : if connection is broken and reconnects,
385
- subscribed topics are automatically subscribed again (default `true`)
386
- * `messageIdProvider`: custom messageId provider. when `new UniqueMessageIdProvider()` is set, then non conflict messageId is provided.
378
+ - `username`: the username required by your broker, if any
379
+ - `password`: the password required by your broker, if any
380
+ - `incomingStore`: a [Store](#store) for the incoming packets
381
+ - `outgoingStore`: a [Store](#store) for the outgoing packets
382
+ - `queueQoSZero`: if connection is broken, queue outgoing QoS zero messages (default `true`)
383
+ - `customHandleAcks`: MQTT 5 feature of custom handling puback and pubrec packets. Its callback:
384
+ ```js
385
+ customHandleAcks: function(topic, message, packet, done) {/*some logic wit colling done(error, reasonCode)*/}
386
+ ```
387
+ - `autoUseTopicAlias`: enabling automatic Topic Alias using functionality
388
+ - `autoAssignTopicAlias`: enabling automatic Topic Alias assign functionality
389
+ - `properties`: properties MQTT 5.0.
390
+ `object` that supports the following properties:
391
+ - `sessionExpiryInterval`: representing the Session Expiry Interval in seconds `number`,
392
+ - `receiveMaximum`: representing the Receive Maximum value `number`,
393
+ - `maximumPacketSize`: representing the Maximum Packet Size the Client is willing to accept `number`,
394
+ - `topicAliasMaximum`: representing the Topic Alias Maximum value indicates the highest value that the Client will accept as a Topic Alias sent by the Server `number`,
395
+ - `requestResponseInformation`: The Client uses this value to request the Server to return Response Information in the CONNACK `boolean`,
396
+ - `requestProblemInformation`: The Client uses this value to indicate whether the Reason String or User Properties are sent in the case of failures `boolean`,
397
+ - `userProperties`: The User Property is allowed to appear multiple times to represent multiple name, value pairs `object`,
398
+ - `authenticationMethod`: the name of the authentication method used for extended authentication `string`,
399
+ - `authenticationData`: Binary Data containing authentication data `binary`
400
+ - `authPacket`: settings for auth packet `object`
401
+ - `will`: a message that will sent by the broker automatically when
402
+ the client disconnect badly. The format is:
403
+ - `topic`: the topic to publish
404
+ - `payload`: the message to publish
405
+ - `qos`: the QoS
406
+ - `retain`: the retain flag
407
+ - `properties`: properties of will by MQTT 5.0:
408
+ - `willDelayInterval`: representing the Will Delay Interval in seconds `number`,
409
+ - `payloadFormatIndicator`: Will Message is UTF-8 Encoded Character Data or not `boolean`,
410
+ - `messageExpiryInterval`: value is the lifetime of the Will Message in seconds and is sent as the Publication Expiry Interval when the Server publishes the Will Message `number`,
411
+ - `contentType`: describing the content of the Will Message `string`,
412
+ - `responseTopic`: String which is used as the Topic Name for a response message `string`,
413
+ - `correlationData`: The Correlation Data is used by the sender of the Request Message to identify which request the Response Message is for when it is received `binary`,
414
+ - `userProperties`: The User Property is allowed to appear multiple times to represent multiple name, value pairs `object`
415
+ - `transformWsUrl` : optional `(url, options, client) => url` function
416
+ For ws/wss protocols only. Can be used to implement signing
417
+ urls which upon reconnect can have become expired.
418
+ - `resubscribe` : if connection is broken and reconnects,
419
+ subscribed topics are automatically subscribed again (default `true`)
420
+ - `messageIdProvider`: custom messageId provider. when `new UniqueMessageIdProvider()` is set, then non conflict messageId is provided.
387
421
 
388
422
  In case mqtts (mqtt over tls) is required, the `options` object is
389
423
  passed through to
@@ -410,9 +444,10 @@ version 1.3 and 1.4 works fine without those.
410
444
  `function (connack) {}`
411
445
 
412
446
  Emitted on successful (re)connection (i.e. connack rc=0).
413
- * `connack` received connack packet. When `clean` connection option is `false` and server has a previous session
414
- for `clientId` connection option, then `connack.sessionPresent` flag is `true`. When that is the case,
415
- you may rely on stored session and prefer not to send subscribe commands for the client.
447
+
448
+ - `connack` received connack packet. When `clean` connection option is `false` and server has a previous session
449
+ for `clientId` connection option, then `connack.sessionPresent` flag is `true`. When that is the case,
450
+ you may rely on stored session and prefer not to send subscribe commands for the client.
416
451
 
417
452
  #### Event `'reconnect'`
418
453
 
@@ -447,10 +482,10 @@ parsing error occurs.
447
482
 
448
483
  The following TLS errors will be emitted as an `error` event:
449
484
 
450
- * `ECONNREFUSED`
451
- * `ECONNRESET`
452
- * `EADDRINUSE`
453
- * `ENOTFOUND`
485
+ - `ECONNREFUSED`
486
+ - `ECONNRESET`
487
+ - `EADDRINUSE`
488
+ - `ENOTFOUND`
454
489
 
455
490
  #### Event `'end'`
456
491
 
@@ -465,9 +500,10 @@ callback returns.
465
500
  `function (topic, message, packet) {}`
466
501
 
467
502
  Emitted when the client receives a publish packet
468
- * `topic` topic of the received packet
469
- * `message` payload of the received packet
470
- * `packet` received packet, as defined in
503
+
504
+ - `topic` topic of the received packet
505
+ - `message` payload of the received packet
506
+ - `packet` received packet, as defined in
471
507
  [mqtt-packet](https://github.com/mcollina/mqtt-packet#publish)
472
508
 
473
509
  #### Event `'packetsend'`
@@ -476,7 +512,8 @@ Emitted when the client receives a publish packet
476
512
 
477
513
  Emitted when the client sends any packet. This includes .published() packets
478
514
  as well as packets used by MQTT for managing subscriptions and connections
479
- * `packet` received packet, as defined in
515
+
516
+ - `packet` received packet, as defined in
480
517
  [mqtt-packet](https://github.com/mcollina/mqtt-packet)
481
518
 
482
519
  #### Event `'packetreceive'`
@@ -486,92 +523,103 @@ as well as packets used by MQTT for managing subscriptions and connections
486
523
  Emitted when the client receives any packet. This includes packets from
487
524
  subscribed topics as well as packets used by MQTT for managing subscriptions
488
525
  and connections
489
- * `packet` received packet, as defined in
526
+
527
+ - `packet` received packet, as defined in
490
528
  [mqtt-packet](https://github.com/mcollina/mqtt-packet)
491
529
 
492
- -------------------------------------------------------
530
+ ---
531
+
493
532
  <a name="publish"></a>
533
+
494
534
  ### mqtt.Client#publish(topic, message, [options], [callback])
495
535
 
496
536
  Publish a message to a topic
497
537
 
498
- * `topic` is the topic to publish to, `String`
499
- * `message` is the message to publish, `Buffer` or `String`
500
- * `options` is the options to publish with, including:
501
- * `qos` QoS level, `Number`, default `0`
502
- * `retain` retain flag, `Boolean`, default `false`
503
- * `dup` mark as duplicate flag, `Boolean`, default `false`
504
- * `properties`: MQTT 5.0 properties `object`
505
- * `payloadFormatIndicator`: Payload is UTF-8 Encoded Character Data or not `boolean`,
506
- * `messageExpiryInterval`: the lifetime of the Application Message in seconds `number`,
507
- * `topicAlias`: value that is used to identify the Topic instead of using the Topic Name `number`,
508
- * `responseTopic`: String which is used as the Topic Name for a response message `string`,
509
- * `correlationData`: used by the sender of the Request Message to identify which request the Response Message is for when it is received `binary`,
510
- * `userProperties`: The User Property is allowed to appear multiple times to represent multiple name, value pairs `object`,
511
- * `subscriptionIdentifier`: representing the identifier of the subscription `number`,
512
- * `contentType`: String describing the content of the Application Message `string`
513
- * `cbStorePut` - `function ()`, fired when message is put into `outgoingStore` if QoS is `1` or `2`.
514
- * `callback` - `function (err)`, fired when the QoS handling completes,
538
+ - `topic` is the topic to publish to, `String`
539
+ - `message` is the message to publish, `Buffer` or `String`
540
+ - `options` is the options to publish with, including:
541
+ - `qos` QoS level, `Number`, default `0`
542
+ - `retain` retain flag, `Boolean`, default `false`
543
+ - `dup` mark as duplicate flag, `Boolean`, default `false`
544
+ - `properties`: MQTT 5.0 properties `object`
545
+ - `payloadFormatIndicator`: Payload is UTF-8 Encoded Character Data or not `boolean`,
546
+ - `messageExpiryInterval`: the lifetime of the Application Message in seconds `number`,
547
+ - `topicAlias`: value that is used to identify the Topic instead of using the Topic Name `number`,
548
+ - `responseTopic`: String which is used as the Topic Name for a response message `string`,
549
+ - `correlationData`: used by the sender of the Request Message to identify which request the Response Message is for when it is received `binary`,
550
+ - `userProperties`: The User Property is allowed to appear multiple times to represent multiple name, value pairs `object`,
551
+ - `subscriptionIdentifier`: representing the identifier of the subscription `number`,
552
+ - `contentType`: String describing the content of the Application Message `string`
553
+ - `cbStorePut` - `function ()`, fired when message is put into `outgoingStore` if QoS is `1` or `2`.
554
+ - `callback` - `function (err)`, fired when the QoS handling completes,
515
555
  or at the next tick if QoS 0. An error occurs if client is disconnecting.
516
556
 
517
- -------------------------------------------------------
557
+ ---
558
+
518
559
  <a name="subscribe"></a>
560
+
519
561
  ### mqtt.Client#subscribe(topic/topic array/topic object, [options], [callback])
520
562
 
521
563
  Subscribe to a topic or topics
522
564
 
523
- * `topic` is a `String` topic to subscribe to or an `Array` of
565
+ - `topic` is a `String` topic to subscribe to or an `Array` of
524
566
  topics to subscribe to. It can also be an object, it has as object
525
567
  keys the topic name and as value the QoS, like `{'test1': {qos: 0}, 'test2': {qos: 1}}`.
526
568
  MQTT `topic` wildcard characters are supported (`+` - for single level and `#` - for multi level)
527
- * `options` is the options to subscribe with, including:
528
- * `qos` QoS subscription level, default 0
529
- * `nl` No Local MQTT 5.0 flag (If the value is true, Application Messages MUST NOT be forwarded to a connection with a ClientID equal to the ClientID of the publishing connection)
530
- * `rap` Retain as Published MQTT 5.0 flag (If true, Application Messages forwarded using this subscription keep the RETAIN flag they were published with. If false, Application Messages forwarded using this subscription have the RETAIN flag set to 0.)
531
- * `rh` Retain Handling MQTT 5.0 (This option specifies whether retained messages are sent when the subscription is established.)
532
- * `properties`: `object`
533
- * `subscriptionIdentifier`: representing the identifier of the subscription `number`,
534
- * `userProperties`: The User Property is allowed to appear multiple times to represent multiple name, value pairs `object`
535
- * `callback` - `function (err, granted)`
569
+ - `options` is the options to subscribe with, including:
570
+ - `qos` QoS subscription level, default 0
571
+ - `nl` No Local MQTT 5.0 flag (If the value is true, Application Messages MUST NOT be forwarded to a connection with a ClientID equal to the ClientID of the publishing connection)
572
+ - `rap` Retain as Published MQTT 5.0 flag (If true, Application Messages forwarded using this subscription keep the RETAIN flag they were published with. If false, Application Messages forwarded using this subscription have the RETAIN flag set to 0.)
573
+ - `rh` Retain Handling MQTT 5.0 (This option specifies whether retained messages are sent when the subscription is established.)
574
+ - `properties`: `object`
575
+ - `subscriptionIdentifier`: representing the identifier of the subscription `number`,
576
+ - `userProperties`: The User Property is allowed to appear multiple times to represent multiple name, value pairs `object`
577
+ - `callback` - `function (err, granted)`
536
578
  callback fired on suback where:
537
- * `err` a subscription error or an error that occurs when client is disconnecting
538
- * `granted` is an array of `{topic, qos}` where:
539
- * `topic` is a subscribed to topic
540
- * `qos` is the granted QoS level on it
579
+ - `err` a subscription error or an error that occurs when client is disconnecting
580
+ - `granted` is an array of `{topic, qos}` where:
581
+ - `topic` is a subscribed to topic
582
+ - `qos` is the granted QoS level on it
583
+
584
+ ---
541
585
 
542
- -------------------------------------------------------
543
586
  <a name="unsubscribe"></a>
587
+
544
588
  ### mqtt.Client#unsubscribe(topic/topic array, [options], [callback])
545
589
 
546
590
  Unsubscribe from a topic or topics
547
591
 
548
- * `topic` is a `String` topic or an array of topics to unsubscribe from
549
- * `options`: options of unsubscribe.
550
- * `properties`: `object`
551
- * `userProperties`: The User Property is allowed to appear multiple times to represent multiple name, value pairs `object`
552
- * `callback` - `function (err)`, fired on unsuback. An error occurs if client is disconnecting.
592
+ - `topic` is a `String` topic or an array of topics to unsubscribe from
593
+ - `options`: options of unsubscribe.
594
+ - `properties`: `object`
595
+ - `userProperties`: The User Property is allowed to appear multiple times to represent multiple name, value pairs `object`
596
+ - `callback` - `function (err)`, fired on unsuback. An error occurs if client is disconnecting.
597
+
598
+ ---
553
599
 
554
- -------------------------------------------------------
555
600
  <a name="end"></a>
601
+
556
602
  ### mqtt.Client#end([force], [options], [callback])
557
603
 
558
604
  Close the client, accepts the following options:
559
605
 
560
- * `force`: passing it to true will close the client right away, without
606
+ - `force`: passing it to true will close the client right away, without
561
607
  waiting for the in-flight messages to be acked. This parameter is
562
608
  optional.
563
- * `options`: options of disconnect.
564
- * `reasonCode`: Disconnect Reason Code `number`
565
- * `properties`: `object`
566
- * `sessionExpiryInterval`: representing the Session Expiry Interval in seconds `number`,
567
- * `reasonString`: representing the reason for the disconnect `string`,
568
- * `userProperties`: The User Property is allowed to appear multiple times to represent multiple name, value pairs `object`,
569
- * `serverReference`: String which can be used by the Client to identify another Server to use `string`
570
- * `callback`: will be called when the client is closed. This parameter is
609
+ - `options`: options of disconnect.
610
+ - `reasonCode`: Disconnect Reason Code `number`
611
+ - `properties`: `object`
612
+ - `sessionExpiryInterval`: representing the Session Expiry Interval in seconds `number`,
613
+ - `reasonString`: representing the reason for the disconnect `string`,
614
+ - `userProperties`: The User Property is allowed to appear multiple times to represent multiple name, value pairs `object`,
615
+ - `serverReference`: String which can be used by the Client to identify another Server to use `string`
616
+ - `callback`: will be called when the client is closed. This parameter is
571
617
  optional.
572
618
 
573
- -------------------------------------------------------
619
+ ---
620
+
574
621
  <a name="removeOutgoingMessage"></a>
622
+
575
623
  ### mqtt.Client#removeOutgoingMessage(mId)
576
624
 
577
625
  Remove a message from the outgoingStore.
@@ -579,95 +627,117 @@ The outgoing callback will be called with Error('Message removed') if the messag
579
627
 
580
628
  After this function is called, the messageId is released and becomes reusable.
581
629
 
582
- * `mId`: The messageId of the message in the outgoingStore.
630
+ - `mId`: The messageId of the message in the outgoingStore.
631
+
632
+ ---
583
633
 
584
- -------------------------------------------------------
585
634
  <a name="reconnect"></a>
635
+
586
636
  ### mqtt.Client#reconnect()
587
637
 
588
638
  Connect again using the same options as connect()
589
639
 
590
- -------------------------------------------------------
640
+ ---
641
+
591
642
  <a name="handleMessage"></a>
643
+
592
644
  ### mqtt.Client#handleMessage(packet, callback)
593
645
 
594
646
  Handle messages with backpressure support, one at a time.
595
- Override at will, but __always call `callback`__, or the client
647
+ Override at will, but **always call `callback`**, or the client
596
648
  will hang.
597
649
 
598
- -------------------------------------------------------
650
+ ---
651
+
599
652
  <a name="connected"></a>
653
+
600
654
  ### mqtt.Client#connected
601
655
 
602
656
  Boolean : set to `true` if the client is connected. `false` otherwise.
603
657
 
604
- -------------------------------------------------------
658
+ ---
659
+
605
660
  <a name="getLastMessageId"></a>
661
+
606
662
  ### mqtt.Client#getLastMessageId()
607
663
 
608
664
  Number : get last message id. This is for sent messages only.
609
665
 
610
- -------------------------------------------------------
666
+ ---
667
+
611
668
  <a name="reconnecting"></a>
669
+
612
670
  ### mqtt.Client#reconnecting
613
671
 
614
672
  Boolean : set to `true` if the client is trying to reconnect to the server. `false` otherwise.
615
673
 
616
- -------------------------------------------------------
674
+ ---
675
+
617
676
  <a name="store"></a>
677
+
618
678
  ### mqtt.Store(options)
619
679
 
620
680
  In-memory implementation of the message store.
621
681
 
622
- * `options` is the store options:
623
- * `clean`: `true`, clean inflight messages when close is called (default `true`)
682
+ - `options` is the store options:
683
+ - `clean`: `true`, clean inflight messages when close is called (default `true`)
624
684
 
625
685
  Other implementations of `mqtt.Store`:
626
686
 
627
- * [mqtt-jsonl-store](https://github.com/robertsLando/mqtt-jsonl-store) which uses
687
+ - [mqtt-jsonl-store](https://github.com/robertsLando/mqtt-jsonl-store) which uses
628
688
  [jsonl-db](https://github.com/AlCalzone/jsonl-db) to store inflight data, it works only on Node.
629
- * [mqtt-level-store](http://npm.im/mqtt-level-store) which uses
689
+ - [mqtt-level-store](http://npm.im/mqtt-level-store) which uses
630
690
  [Level-browserify](http://npm.im/level-browserify) to store the inflight
631
691
  data, making it usable both in Node and the Browser.
632
- * [mqtt-nedb-store](https://github.com/behrad/mqtt-nedb-store) which
692
+ - [mqtt-nedb-store](https://github.com/behrad/mqtt-nedb-store) which
633
693
  uses [nedb](https://www.npmjs.com/package/nedb) to store the inflight
634
694
  data.
635
- * [mqtt-localforage-store](http://npm.im/mqtt-localforage-store) which uses
695
+ - [mqtt-localforage-store](http://npm.im/mqtt-localforage-store) which uses
636
696
  [localForage](http://npm.im/localforage) to store the inflight
637
697
  data, making it usable in the Browser without browserify.
638
698
 
639
- -------------------------------------------------------
699
+ ---
700
+
640
701
  <a name="put"></a>
702
+
641
703
  ### mqtt.Store#put(packet, callback)
642
704
 
643
705
  Adds a packet to the store, a packet is
644
706
  anything that has a `messageId` property.
645
707
  The callback is called when the packet has been stored.
646
708
 
647
- -------------------------------------------------------
709
+ ---
710
+
648
711
  <a name="createStream"></a>
712
+
649
713
  ### mqtt.Store#createStream()
650
714
 
651
715
  Creates a stream with all the packets in the store.
652
716
 
653
- -------------------------------------------------------
717
+ ---
718
+
654
719
  <a name="del"></a>
720
+
655
721
  ### mqtt.Store#del(packet, cb)
656
722
 
657
723
  Removes a packet from the store, a packet is
658
724
  anything that has a `messageId` property.
659
725
  The callback is called when the packet has been removed.
660
726
 
661
- -------------------------------------------------------
727
+ ---
728
+
662
729
  <a name="close"></a>
730
+
663
731
  ### mqtt.Store#close(cb)
664
732
 
665
733
  Closes the Store.
666
734
 
667
735
  <a name="browser"></a>
736
+
668
737
  ## Browser
669
738
 
670
739
  <a name="cdn"></a>
740
+
671
741
  ### Via CDN
672
742
 
673
743
  The MQTT.js bundle is available through http://unpkg.com, specifically
@@ -675,6 +745,7 @@ at https://unpkg.com/mqtt/dist/mqtt.min.js.
675
745
  See http://unpkg.com for the full documentation on version ranges.
676
746
 
677
747
  <a name="browserify"></a>
748
+
678
749
  ### Browserify
679
750
 
680
751
  In order to use MQTT.js as a browserify module you can either require it in your browserify bundles or build it as a stand alone module. The exported module is AMD/CommonJs compatible and it will add an object in the global space.
@@ -695,6 +766,7 @@ gzip <browserMqtt.js | wc -c
695
766
  **Be sure to only use this bundle with `ws` or `wss` URLs in the browser. Others URL types will likey fail**
696
767
 
697
768
  <a name="webpack"></a>
769
+
698
770
  ### Webpack
699
771
 
700
772
  Just like browserify, export MQTT.js as library. The exported module would be `const mqtt = xxx` and it will add an object in the global space. You could also export module in other [formats (AMD/CommonJS/others)](http://webpack.github.io/docs/configuration.html#output-librarytarget) by setting **output.libraryTarget** in webpack configuration.
@@ -711,27 +783,28 @@ you can then use mqtt.js in the browser with the same api than node's one.
711
783
 
712
784
  ```html
713
785
  <html>
714
- <head>
715
- <title>test Ws mqtt.js</title>
716
- </head>
717
- <body>
718
- <script src="./browserMqtt.js"></script>
719
- <script>
720
- const client = mqtt.connect() // you add a ws:// url here
721
- client.subscribe("mqtt/demo")
722
-
723
- client.on("message", function (topic, payload) {
724
- alert([topic, payload].join(": "))
725
- client.end()
726
- })
727
-
728
- client.publish("mqtt/demo", "hello world!")
729
- </script>
730
- </body>
786
+ <head>
787
+ <title>test Ws mqtt.js</title>
788
+ </head>
789
+ <body>
790
+ <script src="./browserMqtt.js"></script>
791
+ <script>
792
+ const client = mqtt.connect(); // you add a ws:// url here
793
+ client.subscribe("mqtt/demo");
794
+
795
+ client.on("message", function (topic, payload) {
796
+ alert([topic, payload].join(": "));
797
+ client.end();
798
+ });
799
+
800
+ client.publish("mqtt/demo", "hello world!");
801
+ </script>
802
+ </body>
731
803
  </html>
732
804
  ```
733
805
 
734
806
  ### React
807
+
735
808
  ```
736
809
  npm install -g webpack // Install webpack globally
737
810
  npm install mqtt // Install MQTT library
@@ -742,7 +815,6 @@ webpack mqtt.js --output-library mqtt // Build
742
815
  // now you can import the library with ES6 import, commonJS not tested
743
816
  ```
744
817
 
745
-
746
818
  ```javascript
747
819
  import React from 'react';
748
820
  import mqtt from 'mqtt';
@@ -772,56 +844,67 @@ export default () => {
772
844
  Your broker should accept websocket connection (see [MQTT over Websockets](https://github.com/moscajs/aedes/blob/master/docs/Examples.md#mqtt-server-over-websocket-using-server-factory) to setup [Aedes](https://github.com/moscajs/aedes)).
773
845
 
774
846
  <a name="qos"></a>
847
+
775
848
  ## About QoS
776
849
 
777
850
  Here is how QoS works:
778
851
 
779
- * QoS 0 : received **at most once** : The packet is sent, and that's it. There is no validation about whether it has been received.
780
- * QoS 1 : received **at least once** : The packet is sent and stored as long as the client has not received a confirmation from the server. MQTT ensures that it *will* be received, but there can be duplicates.
781
- * QoS 2 : received **exactly once** : Same as QoS 1 but there is no duplicates.
852
+ - QoS 0 : received **at most once** : The packet is sent, and that's it. There is no validation about whether it has been received.
853
+ - QoS 1 : received **at least once** : The packet is sent and stored as long as the client has not received a confirmation from the server. MQTT ensures that it _will_ be received, but there can be duplicates.
854
+ - QoS 2 : received **exactly once** : Same as QoS 1 but there is no duplicates.
782
855
 
783
856
  About data consumption, obviously, QoS 2 > QoS 1 > QoS 0, if that's a concern to you.
784
857
 
785
858
  <a name="typescript"></a>
859
+
786
860
  ## Usage with TypeScript
861
+
787
862
  This repo bundles TypeScript definition files for use in TypeScript projects and to support tools that can read `.d.ts` files.
788
863
 
789
864
  ### Pre-requisites
865
+
790
866
  Before you can begin using these TypeScript definitions with your project, you need to make sure your project meets these requirements:
791
- * TypeScript >= 2.1
792
- * Set tsconfig.json: `{"compilerOptions" : {"moduleResolution" : "node"}, ...}`
793
- * Includes the TypeScript definitions for Node and [ws](https://www.npmjs.com/package/ws). These types are used as
794
- parameters to some of the MQTT client's APIs and if you don't install them they get treated as `any`, which means you lose type
795
- safety.
796
- Use npm to install them by typing the following into a terminal window:
797
- `npm install --save-dev @types/node @types/ws`
867
+
868
+ - TypeScript >= 2.1
869
+ - Set tsconfig.json: `{"compilerOptions" : {"moduleResolution" : "node"}, ...}`
870
+ - Includes the TypeScript definitions for Node and [ws](https://www.npmjs.com/package/ws). These types are used as
871
+ parameters to some of the MQTT client's APIs and if you don't install them they get treated as `any`, which means you lose type
872
+ safety.
873
+ Use npm to install them by typing the following into a terminal window:
874
+ `npm install --save-dev @types/node @types/ws`
798
875
 
799
876
  ### TypeScript example
877
+
800
878
  ```
801
879
  import * as mqtt from "mqtt"
802
880
  let client : mqtt.MqttClient = mqtt.connect('mqtt://test.mosquitto.org')
803
881
  ```
804
882
 
805
883
  <a name="weapp-alipay"></a>
884
+
806
885
  ## WeChat and Ali Mini Program support
886
+
807
887
  ### WeChat Mini Program
888
+
808
889
  Supports [WeChat Mini Program](https://mp.weixin.qq.com/). Use the `wxs` protocol. See [the WeChat docs](https://mp.weixin.qq.com/debug/wxadoc/dev/api/network-socket.html).
809
890
 
810
891
  ```js
811
- const mqtt = require('mqtt')
812
- const client = mqtt.connect('wxs://test.mosquitto.org')
892
+ const mqtt = require("mqtt");
893
+ const client = mqtt.connect("wxs://test.mosquitto.org");
813
894
  ```
814
895
 
815
896
  ### Ali Mini Program
897
+
816
898
  Supports [Ali Mini Program](https://open.alipay.com/channel/miniIndex.htm). Use the `alis` protocol. See [the Alipay docs](https://docs.alipay.com/mini/developer/getting-started).
817
899
  <a name="example"></a>
818
900
 
819
901
  ```js
820
- const mqtt = require('mqtt')
821
- const client = mqtt.connect('alis://test.mosquitto.org')
902
+ const mqtt = require("mqtt");
903
+ const client = mqtt.connect("alis://test.mosquitto.org");
822
904
  ```
823
905
 
824
906
  <a name="contributing"></a>
907
+
825
908
  ## Contributing
826
909
 
827
910
  MQTT.js is an **OPEN Open Source Project**. This means that:
@@ -834,15 +917,25 @@ See the [CONTRIBUTING.md](https://github.com/mqttjs/MQTT.js/blob/master/CONTRIBU
834
917
 
835
918
  MQTT.js is only possible due to the excellent work of the following contributors:
836
919
 
837
- <table><tbody>
838
- <tr><th align="left">Adam Rudd</th><td><a href="https://github.com/adamvr">GitHub/adamvr</a></td><td><a href="http://twitter.com/adam_vr">Twitter/@adam_vr</a></td></tr>
839
- <tr><th align="left">Matteo Collina</th><td><a href="https://github.com/mcollina">GitHub/mcollina</a></td><td><a href="http://twitter.com/matteocollina">Twitter/@matteocollina</a></td></tr>
840
- <tr><th align="left">Maxime Agor</th><td><a href="https://github.com/4rzael">GitHub/4rzael</a></td><td><a href="http://twitter.com/4rzael">Twitter/@4rzael</a></td></tr>
841
- <tr><th align="left">Siarhei Buntsevich</th><td><a href="https://github.com/scarry1992">GitHub/scarry1992</a></td></tr>
842
- </tbody></table>
920
+ | Name | GitHub | Twitter |
921
+ | ------------------ | -------------------------------------------------- | ---------------------------------------------------------- |
922
+ | Adam Rudd | [GitHub/adamvr](https://github.com/adamvr) | [Twitter/@adam_vr](http://twitter.com/adam_vr) |
923
+ | Matteo Collina | [GitHub/mcollina](https://github.com/mcollina) | [Twitter/@matteocollina](http://twitter.com/matteocollina) |
924
+ | Maxime Agor | [GitHub/4rzael](https://github.com/4rzael) | [Twitter/@4rzael](http://twitter.com/4rzael) |
925
+ | Siarhei Buntsevich | [GitHub/scarry1992](https://github.com/scarry1992) | |
926
+ | Daniel Lando | [GitHub/robertsLando](https://github.com/robertsLando) | |
927
+
928
+ <a name="sponsor"></a>
929
+
930
+ ## Sponsor
843
931
 
932
+ If you would like to support MQTT.js, please consider sponsoring the author and active maintainers:
933
+
934
+ - [Matteo Collina](https://github.com/sponsors/mcollina): author of MQTT.js
935
+ - [Daniel Lando](https://github.com/sponsors/robertsLando): active maintainer
844
936
 
845
937
  <a name="license"></a>
938
+
846
939
  ## License
847
940
 
848
941
  MIT