mqtt 4.2.7 → 4.3.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,792 +1,843 @@
1
- ![mqtt.js](https://raw.githubusercontent.com/mqttjs/MQTT.js/137ee0e3940c1f01049a30248c70f24dc6e6f829/MQTT.js.png)
2
- =======
3
-
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)
5
-
6
- MQTT.js is a client library for the [MQTT](http://mqtt.org/) protocol, written
7
- in JavaScript for node.js and the browser.
8
-
9
- * [Upgrade notes](#notes)
10
- * [Installation](#install)
11
- * [Example](#example)
12
- * [Command Line Tools](#cli)
13
- * [API](#api)
14
- * [Browser](#browser)
15
- * [Weapp](#weapp)
16
- * [About QoS](#qos)
17
- * [TypeScript](#typescript)
18
- * [Contributing](#contributing)
19
- * [License](#license)
20
-
21
- MQTT.js is an OPEN Open Source Project, see the [Contributing](#contributing) section to find out what this means.
22
-
23
- [![JavaScript Style
24
- Guide](https://cdn.rawgit.com/feross/standard/master/badge.svg)](https://github.com/feross/standard)
25
-
26
-
27
- <a name="notes"></a>
28
- ## Important notes for existing users
29
-
30
- __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
31
- debug logging, along with some feature additions.
32
-
33
- As a __breaking change__, by default a error handler is built into the MQTT.js client, so if any
34
- errors are emitted and the user has not created an event handler on the client for errors, the client will
35
- not break as a result of unhandled errors. Additionally, typical TLS errors like `ECONNREFUSED`, `ECONNRESET` have been
36
- added to a list of TLS errors that will be emitted from the MQTT.js client, and so can be handled as connection errors.
37
-
38
- __v3.0.0__ adds support for MQTT 5, support for node v10.x, and many fixes to improve reliability.
39
-
40
- __Note:__ MQTT v5 support is experimental as it has not been implemented by brokers yet.
41
-
42
- __v2.0.0__ removes support for node v0.8, v0.10 and v0.12, and it is 3x faster in sending
43
- packets. It also removes all the deprecated functionality in v1.0.0,
44
- mainly `mqtt.createConnection` and `mqtt.Server`. From v2.0.0,
45
- subscriptions are restored upon reconnection if `clean: true`.
46
- v1.x.x is now in *LTS*, and it will keep being supported as long as
47
- there are v0.8, v0.10 and v0.12 users.
48
-
49
- As a __breaking change__, the `encoding` option in the old client is
50
- removed, and now everything is UTF-8 with the exception of the
51
- `password` in the CONNECT message and `payload` in the PUBLISH message,
52
- which are `Buffer`.
53
-
54
- Another __breaking change__ is that MQTT.js now defaults to MQTT v3.1.1,
55
- so to support old brokers, please read the [client options doc](#client).
56
-
57
- __v1.0.0__ improves the overall architecture of the project, which is now
58
- split into three components: MQTT.js keeps the Client,
59
- [mqtt-connection](http://npm.im/mqtt-connection) includes the barebone
60
- Connection code for server-side usage, and [mqtt-packet](http://npm.im/mqtt-packet)
61
- includes the protocol parser and generator. The new Client improves
62
- performance by a 30% factor, embeds Websocket support
63
- ([MOWS](http://npm.im/mows) is now deprecated), and it has a better
64
- support for QoS 1 and 2. The previous API is still supported but
65
- deprecated, as such, it is not documented in this README.
66
-
67
- <a name="install"></a>
68
- ## Installation
69
-
70
- ```sh
71
- npm install mqtt --save
72
- ```
73
-
74
- <a name="example"></a>
75
- ## Example
76
-
77
- For the sake of simplicity, let's put the subscriber and the publisher in the same file:
78
-
79
- ```js
80
- var mqtt = require('mqtt')
81
- var client = mqtt.connect('mqtt://test.mosquitto.org')
82
-
83
- client.on('connect', function () {
84
- client.subscribe('presence', function (err) {
85
- if (!err) {
86
- client.publish('presence', 'Hello mqtt')
87
- }
88
- })
89
- })
90
-
91
- client.on('message', function (topic, message) {
92
- // message is Buffer
93
- console.log(message.toString())
94
- client.end()
95
- })
96
- ```
97
-
98
- output:
99
- ```
100
- Hello mqtt
101
- ```
102
-
103
- If you want to run your own MQTT broker, you can use
104
- [Mosquitto](http://mosquitto.org) or
105
- [Aedes-cli](https://github.com/moscajs/aedes-cli), and launch it.
106
-
107
- You can also use a test instance: test.mosquitto.org.
108
-
109
- If you do not want to install a separate broker, you can try using the
110
- [Aedes](https://github.com/moscajs/aedes).
111
-
112
- to use MQTT.js in the browser see the [browserify](#browserify) section
113
-
114
- <a name="promises"></a>
115
- ## Promise support
116
-
117
- 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.
118
-
119
- <a name="cli"></a>
120
- ## Command Line Tools
121
-
122
- MQTT.js bundles a command to interact with a broker.
123
- In order to have it available on your path, you should install MQTT.js
124
- globally:
125
-
126
- ```sh
127
- npm install mqtt -g
128
- ```
129
-
130
- Then, on one terminal
131
-
132
- ```
133
- mqtt sub -t 'hello' -h 'test.mosquitto.org' -v
134
- ```
135
-
136
- On another
137
-
138
- ```
139
- mqtt pub -t 'hello' -h 'test.mosquitto.org' -m 'from MQTT.js'
140
- ```
141
-
142
- See `mqtt help <command>` for the command help.
143
-
144
- <a name="debug"></a>
145
- ## Debug Logs
146
-
147
- 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 :
148
- ```ps
149
- # (example using PowerShell, the VS Code default)
150
- $env:DEBUG='mqttjs*'
151
-
152
- ```
153
-
154
- <a name="reconnecting"></a>
155
- ## About Reconnection
156
-
157
- An important part of any websocket connection is what to do when a connection
158
- drops off and the client needs to reconnect. MQTT has built-in reconnection
159
- support that can be configured to behave in ways that suit the application.
160
-
161
- #### Refresh Authentication Options / Signed Urls with `transformWsUrl` (Websocket Only)
162
-
163
- When an mqtt connection drops and needs to reconnect, it's common to require
164
- that any authentication associated with the connection is kept current with
165
- the underlying auth mechanism. For instance some applications may pass an auth
166
- token with connection options on the initial connection, while other cloud
167
- services may require a url be signed with each connection.
168
-
169
- By the time the reconnect happens in the application lifecycle, the original
170
- auth data may have expired.
171
-
172
- To address this we can use a hook called `transformWsUrl` to manipulate
173
- either of the connection url or the client options at the time of a reconnect.
174
-
175
- Example (update clientId & username on each reconnect):
176
- ```
177
- const transformWsUrl = (url, options, client) => {
178
- client.options.username = `token=${this.get_current_auth_token()}`;
179
- client.options.clientId = `${this.get_updated_clientId()}`;
180
-
181
- return `${this.get_signed_cloud_url(url)`;
182
- }
183
-
184
- const connection = await mqtt.connectAsync(<wss url>, {
185
- ...,
186
- transformWsUrl: transformUrl,
187
- });
188
-
189
- ```
190
- Now every time a new WebSocket connection is opened (hopefully not too often),
191
- we will get a fresh signed url or fresh auth token data.
192
-
193
- Note: Currently this hook does _not_ support promises, meaning that in order to
194
- use the latest auth token, you must have some outside mechanism running that
195
- handles application-level authentication refreshing so that the websocket
196
- connection can simply grab the latest valid token or signed url.
197
-
198
-
199
- #### Enabling Reconnection with `reconnectPeriod` option
200
-
201
- To ensure that the mqtt client automatically tries to reconnect when the
202
- connection is dropped, you must set the client option `reconnectPeriod` to a
203
- value greater than 0. A value of 0 will disable reconnection and then terminate
204
- the final connection when it drops.
205
-
206
- The default value is 1000 ms which means it will try to reconnect 1 second
207
- after losing the connection.
208
-
209
-
210
-
211
- <a name="api"></a>
212
- ## API
213
-
214
- * <a href="#connect"><code>mqtt.<b>connect()</b></code></a>
215
- * <a href="#client"><code>mqtt.<b>Client()</b></code></a>
216
- * <a href="#publish"><code>mqtt.Client#<b>publish()</b></code></a>
217
- * <a href="#subscribe"><code>mqtt.Client#<b>subscribe()</b></code></a>
218
- * <a href="#unsubscribe"><code>mqtt.Client#<b>unsubscribe()</b></code></a>
219
- * <a href="#end"><code>mqtt.Client#<b>end()</b></code></a>
220
- * <a href="#removeOutgoingMessage"><code>mqtt.Client#<b>removeOutgoingMessage()</b></code></a>
221
- * <a href="#reconnect"><code>mqtt.Client#<b>reconnect()</b></code></a>
222
- * <a href="#handleMessage"><code>mqtt.Client#<b>handleMessage()</b></code></a>
223
- * <a href="#connected"><code>mqtt.Client#<b>connected</b></code></a>
224
- * <a href="#reconnecting"><code>mqtt.Client#<b>reconnecting</b></code></a>
225
- * <a href="#getLastMessageId"><code>mqtt.Client#<b>getLastMessageId()</b></code></a>
226
- * <a href="#store"><code>mqtt.<b>Store()</b></code></a>
227
- * <a href="#put"><code>mqtt.Store#<b>put()</b></code></a>
228
- * <a href="#del"><code>mqtt.Store#<b>del()</b></code></a>
229
- * <a href="#createStream"><code>mqtt.Store#<b>createStream()</b></code></a>
230
- * <a href="#close"><code>mqtt.Store#<b>close()</b></code></a>
231
-
232
- -------------------------------------------------------
233
- <a name="connect"></a>
234
- ### mqtt.connect([url], options)
235
-
236
- Connects to the broker specified by the given url and options and
237
- returns a [Client](#client).
238
-
239
- The URL can be on the following protocols: 'mqtt', 'mqtts', 'tcp',
240
- 'tls', 'ws', 'wss'. The URL can also be an object as returned by
241
- [`URL.parse()`](http://nodejs.org/api/url.html#url_url_parse_urlstr_parsequerystring_slashesdenotehost),
242
- in that case the two objects are merged, i.e. you can pass a single
243
- object with both the URL and the connect options.
244
-
245
- You can also specify a `servers` options with content: `[{ host:
246
- 'localhost', port: 1883 }, ... ]`, in that case that array is iterated
247
- at every connect.
248
-
249
- For all MQTT-related options, see the [Client](#client)
250
- constructor.
251
-
252
- -------------------------------------------------------
253
- <a name="client"></a>
254
- ### mqtt.Client(streamBuilder, options)
255
-
256
- The `Client` class wraps a client connection to an
257
- MQTT broker over an arbitrary transport method (TCP, TLS,
258
- WebSocket, ecc).
259
-
260
- `Client` automatically handles the following:
261
-
262
- * Regular server pings
263
- * QoS flow
264
- * Automatic reconnections
265
- * Start publishing before being connected
266
-
267
- The arguments are:
268
-
269
- * `streamBuilder` is a function that returns a subclass of the `Stream` class that supports
270
- the `connect` event. Typically a `net.Socket`.
271
- * `options` is the client connection options (see: the [connect packet](https://github.com/mcollina/mqtt-packet#connect)). Defaults:
272
- * `wsOptions`: is the WebSocket connection options. Default is `{}`.
273
- It's specific for WebSockets. For possible options have a look at: https://github.com/websockets/ws/blob/master/doc/ws.md.
274
- * `keepalive`: `60` seconds, set to `0` to disable
275
- * `reschedulePings`: reschedule ping messages after sending packets (default `true`)
276
- * `clientId`: `'mqttjs_' + Math.random().toString(16).substr(2, 8)`
277
- * `protocolId`: `'MQTT'`
278
- * `protocolVersion`: `4`
279
- * `clean`: `true`, set to false to receive QoS 1 and 2 messages while
280
- offline
281
- * `reconnectPeriod`: `1000` milliseconds, interval between two
282
- reconnections. Disable auto reconnect by setting to `0`.
283
- * `connectTimeout`: `30 * 1000` milliseconds, time to wait before a
284
- CONNACK is received
285
- * `username`: the username required by your broker, if any
286
- * `password`: the password required by your broker, if any
287
- * `incomingStore`: a [Store](#store) for the incoming packets
288
- * `outgoingStore`: a [Store](#store) for the outgoing packets
289
- * `queueQoSZero`: if connection is broken, queue outgoing QoS zero messages (default `true`)
290
- * `customHandleAcks`: MQTT 5 feature of custom handling puback and pubrec packets. Its callback:
291
- ```js
292
- customHandleAcks: function(topic, message, packet, done) {/*some logic wit colling done(error, reasonCode)*/}
293
- ```
294
- * `properties`: properties MQTT 5.0.
295
- `object` that supports the following properties:
296
- * `sessionExpiryInterval`: representing the Session Expiry Interval in seconds `number`,
297
- * `receiveMaximum`: representing the Receive Maximum value `number`,
298
- * `maximumPacketSize`: representing the Maximum Packet Size the Client is willing to accept `number`,
299
- * `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`,
300
- * `requestResponseInformation`: The Client uses this value to request the Server to return Response Information in the CONNACK `boolean`,
301
- * `requestProblemInformation`: The Client uses this value to indicate whether the Reason String or User Properties are sent in the case of failures `boolean`,
302
- * `userProperties`: The User Property is allowed to appear multiple times to represent multiple name, value pairs `object`,
303
- * `authenticationMethod`: the name of the authentication method used for extended authentication `string`,
304
- * `authenticationData`: Binary Data containing authentication data `binary`
305
- * `authPacket`: settings for auth packet `object`
306
- * `will`: a message that will sent by the broker automatically when
307
- the client disconnect badly. The format is:
308
- * `topic`: the topic to publish
309
- * `payload`: the message to publish
310
- * `qos`: the QoS
311
- * `retain`: the retain flag
312
- * `properties`: properties of will by MQTT 5.0:
313
- * `willDelayInterval`: representing the Will Delay Interval in seconds `number`,
314
- * `payloadFormatIndicator`: Will Message is UTF-8 Encoded Character Data or not `boolean`,
315
- * `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`,
316
- * `contentType`: describing the content of the Will Message `string`,
317
- * `responseTopic`: String which is used as the Topic Name for a response message `string`,
318
- * `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`,
319
- * `userProperties`: The User Property is allowed to appear multiple times to represent multiple name, value pairs `object`
320
- * `transformWsUrl` : optional `(url, options, client) => url` function
321
- For ws/wss protocols only. Can be used to implement signing
322
- urls which upon reconnect can have become expired.
323
- * `resubscribe` : if connection is broken and reconnects,
324
- subscribed topics are automatically subscribed again (default `true`)
325
-
326
- In case mqtts (mqtt over tls) is required, the `options` object is
327
- passed through to
328
- [`tls.connect()`](http://nodejs.org/api/tls.html#tls_tls_connect_options_callback).
329
- If you are using a **self-signed certificate**, pass the `rejectUnauthorized: false` option.
330
- Beware that you are exposing yourself to man in the middle attacks, so it is a configuration
331
- that is not recommended for production environments.
332
-
333
- If you are connecting to a broker that supports only MQTT 3.1 (not
334
- 3.1.1 compliant), you should pass these additional options:
335
-
336
- ```js
337
- {
338
- protocolId: 'MQIsdp',
339
- protocolVersion: 3
340
- }
341
- ```
342
-
343
- This is confirmed on RabbitMQ 3.2.4, and on Mosquitto < 1.3. Mosquitto
344
- version 1.3 and 1.4 works fine without those.
345
-
346
- #### Event `'connect'`
347
-
348
- `function (connack) {}`
349
-
350
- Emitted on successful (re)connection (i.e. connack rc=0).
351
- * `connack` received connack packet. When `clean` connection option is `false` and server has a previous session
352
- for `clientId` connection option, then `connack.sessionPresent` flag is `true`. When that is the case,
353
- you may rely on stored session and prefer not to send subscribe commands for the client.
354
-
355
- #### Event `'reconnect'`
356
-
357
- `function () {}`
358
-
359
- Emitted when a reconnect starts.
360
-
361
- #### Event `'close'`
362
-
363
- `function () {}`
364
-
365
- Emitted after a disconnection.
366
-
367
- #### Event `'disconnect'`
368
-
369
- `function (packet) {}`
370
-
371
- Emitted after receiving disconnect packet from broker. MQTT 5.0 feature.
372
-
373
- #### Event `'offline'`
374
-
375
- `function () {}`
376
-
377
- Emitted when the client goes offline.
378
-
379
- #### Event `'error'`
380
-
381
- `function (error) {}`
382
-
383
- Emitted when the client cannot connect (i.e. connack rc != 0) or when a
384
- parsing error occurs.
385
-
386
- The following TLS errors will be emitted as an `error` event:
387
-
388
- * `ECONNREFUSED`
389
- * `ECONNRESET`
390
- * `EADDRINUSE`
391
- * `ENOTFOUND`
392
-
393
- #### Event `'end'`
394
-
395
- `function () {}`
396
-
397
- Emitted when <a href="#end"><code>mqtt.Client#<b>end()</b></code></a> is called.
398
- If a callback was passed to `mqtt.Client#end()`, this event is emitted once the
399
- callback returns.
400
-
401
- #### Event `'message'`
402
-
403
- `function (topic, message, packet) {}`
404
-
405
- Emitted when the client receives a publish packet
406
- * `topic` topic of the received packet
407
- * `message` payload of the received packet
408
- * `packet` received packet, as defined in
409
- [mqtt-packet](https://github.com/mcollina/mqtt-packet#publish)
410
-
411
- #### Event `'packetsend'`
412
-
413
- `function (packet) {}`
414
-
415
- Emitted when the client sends any packet. This includes .published() packets
416
- as well as packets used by MQTT for managing subscriptions and connections
417
- * `packet` received packet, as defined in
418
- [mqtt-packet](https://github.com/mcollina/mqtt-packet)
419
-
420
- #### Event `'packetreceive'`
421
-
422
- `function (packet) {}`
423
-
424
- Emitted when the client receives any packet. This includes packets from
425
- subscribed topics as well as packets used by MQTT for managing subscriptions
426
- and connections
427
- * `packet` received packet, as defined in
428
- [mqtt-packet](https://github.com/mcollina/mqtt-packet)
429
-
430
- -------------------------------------------------------
431
- <a name="publish"></a>
432
- ### mqtt.Client#publish(topic, message, [options], [callback])
433
-
434
- Publish a message to a topic
435
-
436
- * `topic` is the topic to publish to, `String`
437
- * `message` is the message to publish, `Buffer` or `String`
438
- * `options` is the options to publish with, including:
439
- * `qos` QoS level, `Number`, default `0`
440
- * `retain` retain flag, `Boolean`, default `false`
441
- * `dup` mark as duplicate flag, `Boolean`, default `false`
442
- * `properties`: MQTT 5.0 properties `object`
443
- * `payloadFormatIndicator`: Payload is UTF-8 Encoded Character Data or not `boolean`,
444
- * `messageExpiryInterval`: the lifetime of the Application Message in seconds `number`,
445
- * `topicAlias`: value that is used to identify the Topic instead of using the Topic Name `number`,
446
- * `responseTopic`: String which is used as the Topic Name for a response message `string`,
447
- * `correlationData`: used by the sender of the Request Message to identify which request the Response Message is for when it is received `binary`,
448
- * `userProperties`: The User Property is allowed to appear multiple times to represent multiple name, value pairs `object`,
449
- * `subscriptionIdentifier`: representing the identifier of the subscription `number`,
450
- * `contentType`: String describing the content of the Application Message `string`
451
- * `cbStorePut` - `function ()`, fired when message is put into `outgoingStore` if QoS is `1` or `2`.
452
- * `callback` - `function (err)`, fired when the QoS handling completes,
453
- or at the next tick if QoS 0. An error occurs if client is disconnecting.
454
-
455
- -------------------------------------------------------
456
- <a name="subscribe"></a>
457
- ### mqtt.Client#subscribe(topic/topic array/topic object, [options], [callback])
458
-
459
- Subscribe to a topic or topics
460
-
461
- * `topic` is a `String` topic to subscribe to or an `Array` of
462
- topics to subscribe to. It can also be an object, it has as object
463
- keys the topic name and as value the QoS, like `{'test1': {qos: 0}, 'test2': {qos: 1}}`.
464
- MQTT `topic` wildcard characters are supported (`+` - for single level and `#` - for multi level)
465
- * `options` is the options to subscribe with, including:
466
- * `qos` QoS subscription level, default 0
467
- * `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)
468
- * `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.)
469
- * `rh` Retain Handling MQTT 5.0 (This option specifies whether retained messages are sent when the subscription is established.)
470
- * `properties`: `object`
471
- * `subscriptionIdentifier`: representing the identifier of the subscription `number`,
472
- * `userProperties`: The User Property is allowed to appear multiple times to represent multiple name, value pairs `object`
473
- * `callback` - `function (err, granted)`
474
- callback fired on suback where:
475
- * `err` a subscription error or an error that occurs when client is disconnecting
476
- * `granted` is an array of `{topic, qos}` where:
477
- * `topic` is a subscribed to topic
478
- * `qos` is the granted QoS level on it
479
-
480
- -------------------------------------------------------
481
- <a name="unsubscribe"></a>
482
- ### mqtt.Client#unsubscribe(topic/topic array, [options], [callback])
483
-
484
- Unsubscribe from a topic or topics
485
-
486
- * `topic` is a `String` topic or an array of topics to unsubscribe from
487
- * `options`: options of unsubscribe.
488
- * `properties`: `object`
489
- * `userProperties`: The User Property is allowed to appear multiple times to represent multiple name, value pairs `object`
490
- * `callback` - `function (err)`, fired on unsuback. An error occurs if client is disconnecting.
491
-
492
- -------------------------------------------------------
493
- <a name="end"></a>
494
- ### mqtt.Client#end([force], [options], [callback])
495
-
496
- Close the client, accepts the following options:
497
-
498
- * `force`: passing it to true will close the client right away, without
499
- waiting for the in-flight messages to be acked. This parameter is
500
- optional.
501
- * `options`: options of disconnect.
502
- * `reasonCode`: Disconnect Reason Code `number`
503
- * `properties`: `object`
504
- * `sessionExpiryInterval`: representing the Session Expiry Interval in seconds `number`,
505
- * `reasonString`: representing the reason for the disconnect `string`,
506
- * `userProperties`: The User Property is allowed to appear multiple times to represent multiple name, value pairs `object`,
507
- * `serverReference`: String which can be used by the Client to identify another Server to use `string`
508
- * `callback`: will be called when the client is closed. This parameter is
509
- optional.
510
-
511
- -------------------------------------------------------
512
- <a name="removeOutgoingMessage"></a>
513
- ### mqtt.Client#removeOutgoingMessage(mId)
514
-
515
- Remove a message from the outgoingStore.
516
- The outgoing callback will be called with Error('Message removed') if the message is removed.
517
-
518
- After this function is called, the messageId is released and becomes reusable.
519
-
520
- * `mId`: The messageId of the message in the outgoingStore.
521
-
522
- -------------------------------------------------------
523
- <a name="reconnect"></a>
524
- ### mqtt.Client#reconnect()
525
-
526
- Connect again using the same options as connect()
527
-
528
- -------------------------------------------------------
529
- <a name="handleMessage"></a>
530
- ### mqtt.Client#handleMessage(packet, callback)
531
-
532
- Handle messages with backpressure support, one at a time.
533
- Override at will, but __always call `callback`__, or the client
534
- will hang.
535
-
536
- -------------------------------------------------------
537
- <a name="connected"></a>
538
- ### mqtt.Client#connected
539
-
540
- Boolean : set to `true` if the client is connected. `false` otherwise.
541
-
542
- -------------------------------------------------------
543
- <a name="getLastMessageId"></a>
544
- ### mqtt.Client#getLastMessageId()
545
-
546
- Number : get last message id. This is for sent messages only.
547
-
548
- -------------------------------------------------------
549
- <a name="reconnecting"></a>
550
- ### mqtt.Client#reconnecting
551
-
552
- Boolean : set to `true` if the client is trying to reconnect to the server. `false` otherwise.
553
-
554
- -------------------------------------------------------
555
- <a name="store"></a>
556
- ### mqtt.Store(options)
557
-
558
- In-memory implementation of the message store.
559
-
560
- * `options` is the store options:
561
- * `clean`: `true`, clean inflight messages when close is called (default `true`)
562
-
563
- Other implementations of `mqtt.Store`:
564
-
565
- * [mqtt-level-store](http://npm.im/mqtt-level-store) which uses
566
- [Level-browserify](http://npm.im/level-browserify) to store the inflight
567
- data, making it usable both in Node and the Browser.
568
- * [mqtt-nedb-store](https://github.com/behrad/mqtt-nedb-store) which
569
- uses [nedb](https://www.npmjs.com/package/nedb) to store the inflight
570
- data.
571
- * [mqtt-localforage-store](http://npm.im/mqtt-localforage-store) which uses
572
- [localForage](http://npm.im/localforage) to store the inflight
573
- data, making it usable in the Browser without browserify.
574
-
575
- -------------------------------------------------------
576
- <a name="put"></a>
577
- ### mqtt.Store#put(packet, callback)
578
-
579
- Adds a packet to the store, a packet is
580
- anything that has a `messageId` property.
581
- The callback is called when the packet has been stored.
582
-
583
- -------------------------------------------------------
584
- <a name="createStream"></a>
585
- ### mqtt.Store#createStream()
586
-
587
- Creates a stream with all the packets in the store.
588
-
589
- -------------------------------------------------------
590
- <a name="del"></a>
591
- ### mqtt.Store#del(packet, cb)
592
-
593
- Removes a packet from the store, a packet is
594
- anything that has a `messageId` property.
595
- The callback is called when the packet has been removed.
596
-
597
- -------------------------------------------------------
598
- <a name="close"></a>
599
- ### mqtt.Store#close(cb)
600
-
601
- Closes the Store.
602
-
603
- <a name="browser"></a>
604
- ## Browser
605
-
606
- <a name="cdn"></a>
607
- ### Via CDN
608
-
609
- The MQTT.js bundle is available through http://unpkg.com, specifically
610
- at https://unpkg.com/mqtt/dist/mqtt.min.js.
611
- See http://unpkg.com for the full documentation on version ranges.
612
-
613
- <a name="weapp"></a>
614
- ## WeChat Mini Program
615
- Support [WeChat Mini Program](https://mp.weixin.qq.com/). See [Doc](https://mp.weixin.qq.com/debug/wxadoc/dev/api/network-socket.html).
616
- <a name="example"></a>
617
-
618
- ## Example(js)
619
-
620
- ```js
621
- var mqtt = require('mqtt')
622
- var client = mqtt.connect('wxs://test.mosquitto.org')
623
- ```
624
-
625
- ## Example(ts)
626
-
627
- ```ts
628
- import { connect } from 'mqtt';
629
- const client = connect('wxs://test.mosquitto.org');
630
- ```
631
-
632
- ## Ali Mini Program
633
- Surport [Ali Mini Program](https://open.alipay.com/channel/miniIndex.htm). See [Doc](https://docs.alipay.com/mini/developer/getting-started).
634
- <a name="example"></a>
635
-
636
- ## Example(js)
637
-
638
- ```js
639
- var mqtt = require('mqtt')
640
- var client = mqtt.connect('alis://test.mosquitto.org')
641
- ```
642
-
643
- ## Example(ts)
644
-
645
- ```ts
646
- import { connect } from 'mqtt';
647
- const client = connect('alis://test.mosquitto.org');
648
- ```
649
-
650
- <a name="browserify"></a>
651
- ### Browserify
652
-
653
- 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.
654
-
655
- ```bash
656
- mkdir tmpdir
657
- cd tmpdir
658
- npm install mqtt
659
- npm install browserify
660
- npm install tinyify
661
- cd node_modules/mqtt/
662
- npm install .
663
- npx browserify mqtt.js -s mqtt >browserMqtt.js // use script tag
664
- # show size for compressed browser transfer
665
- gzip <browserMqtt.js | wc -c
666
- ```
667
-
668
- **Be sure to only use this bundle with `ws` or `wss` URLs in the browser. Others URL types will likey fail**
669
-
670
- <a name="webpack"></a>
671
- ### Webpack
672
-
673
- Just like browserify, export MQTT.js as library. The exported module would be `var 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.
674
-
675
- ```javascript
676
- npm install -g webpack // install webpack
677
-
678
- cd node_modules/mqtt
679
- npm install . // install dev dependencies
680
- webpack mqtt.js ./browserMqtt.js --output-library mqtt
681
- ```
682
-
683
- you can then use mqtt.js in the browser with the same api than node's one.
684
-
685
- ```html
686
- <html>
687
- <head>
688
- <title>test Ws mqtt.js</title>
689
- </head>
690
- <body>
691
- <script src="./browserMqtt.js"></script>
692
- <script>
693
- var client = mqtt.connect() // you add a ws:// url here
694
- client.subscribe("mqtt/demo")
695
-
696
- client.on("message", function (topic, payload) {
697
- alert([topic, payload].join(": "))
698
- client.end()
699
- })
700
-
701
- client.publish("mqtt/demo", "hello world!")
702
- </script>
703
- </body>
704
- </html>
705
- ```
706
-
707
- ### React
708
- ```
709
- npm install -g webpack // Install webpack globally
710
- npm install mqtt // Install MQTT library
711
- cd node_modules/mqtt
712
- npm install . // Install dev deps at current dir
713
- webpack mqtt.js --output-library mqtt // Build
714
-
715
- // now you can import the library with ES6 import, commonJS not tested
716
- ```
717
-
718
-
719
- ```javascript
720
- import React from 'react';
721
- import mqtt from 'mqtt';
722
-
723
- export default () => {
724
- const [connectionStatus, setConnectionStatus] = React.useState(false);
725
- const [messages, setMessages] = React.useState([]);
726
-
727
- useEffect(() => {
728
- const client = mqtt.connect(SOME_URL);
729
- client.on('connect', () => setConnectionStatus(true));
730
- client.on('message', (topic, payload, packet) => {
731
- setMessages(messages.concat(payload.toString()));
732
- });
733
- }, []);
734
-
735
- return (
736
- <>
737
- {lastMessages.map((message) => (
738
- <h2>{message}</h2>
739
- )
740
- </>
741
- )
742
- }
743
- ```
744
-
745
- 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)).
746
-
747
- <a name="qos"></a>
748
- ## About QoS
749
-
750
- Here is how QoS works:
751
-
752
- * QoS 0 : received **at most once** : The packet is sent, and that's it. There is no validation about whether it has been received.
753
- * 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.
754
- * QoS 2 : received **exactly once** : Same as QoS 1 but there is no duplicates.
755
-
756
- About data consumption, obviously, QoS 2 > QoS 1 > QoS 0, if that's a concern to you.
757
-
758
- <a name="typescript"></a>
759
- ## Usage with TypeScript
760
- This repo bundles TypeScript definition files for use in TypeScript projects and to support tools that can read `.d.ts` files.
761
-
762
- ### Pre-requisites
763
- Before you can begin using these TypeScript definitions with your project, you need to make sure your project meets a few of these requirements:
764
- * TypeScript >= 2.1
765
- * Set tsconfig.json: `{"compilerOptions" : {"moduleResolution" : "node"}, ...}`
766
- * Includes the TypeScript definitions for node. You can use npm to install this by typing the following into a terminal window:
767
- `npm install --save-dev @types/node`
768
-
769
- <a name="contributing"></a>
770
- ## Contributing
771
-
772
- MQTT.js is an **OPEN Open Source Project**. This means that:
773
-
774
- > Individuals making significant and valuable contributions are given commit-access to the project to contribute as they see fit. This project is more like an open wiki than a standard guarded open source project.
775
-
776
- See the [CONTRIBUTING.md](https://github.com/mqttjs/MQTT.js/blob/master/CONTRIBUTING.md) file for more details.
777
-
778
- ### Contributors
779
-
780
- MQTT.js is only possible due to the excellent work of the following contributors:
781
-
782
- <table><tbody>
783
- <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>
784
- <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>
785
- <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>
786
- <tr><th align="left">Siarhei Buntsevich</th><td><a href="https://github.com/scarry1992">GitHub/scarry1992</a></td></tr>
787
- </tbody></table>
788
-
789
- <a name="license"></a>
790
- ## License
791
-
792
- MIT
1
+ ![mqtt.js](https://raw.githubusercontent.com/mqttjs/MQTT.js/137ee0e3940c1f01049a30248c70f24dc6e6f829/MQTT.js.png)
2
+ =======
3
+
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)
5
+
6
+ MQTT.js is a client library for the [MQTT](http://mqtt.org/) protocol, written
7
+ in JavaScript for node.js and the browser.
8
+
9
+ ## 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)
23
+
24
+ MQTT.js is an OPEN Open Source Project, see the [Contributing](#contributing) section to find out what this means.
25
+
26
+ [![JavaScript Style
27
+ Guide](https://cdn.rawgit.com/feross/standard/master/badge.svg)](https://github.com/feross/standard)
28
+
29
+ <a name="vnext"></a>
30
+ ## Discussion on the next major version of MQTT.js
31
+ There are discussions happening on the future of MQTT.js and the next major version (vNext). We invite the community to provide their thoughts and feedback in [this GitHub discussion](https://github.com/mqttjs/MQTT.js/discussions/1324)
32
+
33
+ <a name="notes"></a>
34
+ ## Important notes for existing users
35
+
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
37
+ debug logging, along with some feature additions.
38
+
39
+ As a __breaking change__, by default a error handler is built into the MQTT.js client, so if any
40
+ errors are emitted and the user has not created an event handler on the client for errors, the client will
41
+ not break as a result of unhandled errors. Additionally, typical TLS errors like `ECONNREFUSED`, `ECONNRESET` have been
42
+ 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
+
44
+ __v3.0.0__ adds support for MQTT 5, support for node v10.x, and many fixes to improve reliability.
45
+
46
+ __Note:__ MQTT v5 support is experimental as it has not been implemented by brokers yet.
47
+
48
+ __v2.0.0__ removes support for node v0.8, v0.10 and v0.12, and it is 3x faster in sending
49
+ packets. It also removes all the deprecated functionality in v1.0.0,
50
+ mainly `mqtt.createConnection` and `mqtt.Server`. From v2.0.0,
51
+ 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
53
+ there are v0.8, v0.10 and v0.12 users.
54
+
55
+ As a __breaking change__, the `encoding` option in the old client is
56
+ removed, and now everything is UTF-8 with the exception of the
57
+ `password` in the CONNECT message and `payload` in the PUBLISH message,
58
+ which are `Buffer`.
59
+
60
+ Another __breaking change__ is that MQTT.js now defaults to MQTT v3.1.1,
61
+ so to support old brokers, please read the [client options doc](#client).
62
+
63
+ __v1.0.0__ improves the overall architecture of the project, which is now
64
+ split into three components: MQTT.js keeps the Client,
65
+ [mqtt-connection](http://npm.im/mqtt-connection) includes the barebone
66
+ Connection code for server-side usage, and [mqtt-packet](http://npm.im/mqtt-packet)
67
+ includes the protocol parser and generator. The new Client improves
68
+ performance by a 30% factor, embeds Websocket support
69
+ ([MOWS](http://npm.im/mows) is now deprecated), and it has a better
70
+ support for QoS 1 and 2. The previous API is still supported but
71
+ deprecated, as such, it is not documented in this README.
72
+
73
+ <a name="install"></a>
74
+ ## Installation
75
+
76
+ ```sh
77
+ npm install mqtt --save
78
+ ```
79
+
80
+ <a name="example"></a>
81
+ ## Example
82
+
83
+ For the sake of simplicity, let's put the subscriber and the publisher in the same file:
84
+
85
+ ```js
86
+ const mqtt = require('mqtt')
87
+ const client = mqtt.connect('mqtt://test.mosquitto.org')
88
+
89
+ client.on('connect', function () {
90
+ client.subscribe('presence', function (err) {
91
+ if (!err) {
92
+ client.publish('presence', 'Hello mqtt')
93
+ }
94
+ })
95
+ })
96
+
97
+ client.on('message', function (topic, message) {
98
+ // message is Buffer
99
+ console.log(message.toString())
100
+ client.end()
101
+ })
102
+ ```
103
+
104
+ output:
105
+ ```
106
+ Hello mqtt
107
+ ```
108
+
109
+ If you want to run your own MQTT broker, you can use
110
+ [Mosquitto](http://mosquitto.org) or
111
+ [Aedes-cli](https://github.com/moscajs/aedes-cli), and launch it.
112
+
113
+ You can also use a test instance: test.mosquitto.org.
114
+
115
+ If you do not want to install a separate broker, you can try using the
116
+ [Aedes](https://github.com/moscajs/aedes).
117
+
118
+ to use MQTT.js in the browser see the [browserify](#browserify) section
119
+
120
+ <a name="import_styles"></a>
121
+ ## Import styles
122
+ ### CommonJS (Require)
123
+ ```js
124
+ const mqtt = require('mqtt') // require mqtt
125
+ const client = mqtt.connect('est.mosquitto.org') // create a client
126
+ ```
127
+ ### ES6 Modules (Import)
128
+ #### Aliased wildcard import
129
+ ```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
132
+ ```
133
+ #### Importing individual components
134
+ ```js
135
+ import { connect } from "mqtt" // import connect from mqtt
136
+ let client = connect('mqtt://test.mosquitto.org') // create a client
137
+ ```
138
+
139
+ <a name="promises"></a>
140
+ ## Promise support
141
+
142
+ 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
+
144
+ <a name="cli"></a>
145
+ ## Command Line Tools
146
+
147
+ MQTT.js bundles a command to interact with a broker.
148
+ In order to have it available on your path, you should install MQTT.js
149
+ globally:
150
+
151
+ ```sh
152
+ npm install mqtt -g
153
+ ```
154
+
155
+ Then, on one terminal
156
+
157
+ ```
158
+ mqtt sub -t 'hello' -h 'test.mosquitto.org' -v
159
+ ```
160
+
161
+ On another
162
+
163
+ ```
164
+ mqtt pub -t 'hello' -h 'test.mosquitto.org' -m 'from MQTT.js'
165
+ ```
166
+
167
+ See `mqtt help <command>` for the command help.
168
+
169
+ <a name="debug"></a>
170
+ ## Debug Logs
171
+
172
+ 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 :
173
+ ```ps
174
+ # (example using PowerShell, the VS Code default)
175
+ $env:DEBUG='mqttjs*'
176
+
177
+ ```
178
+
179
+ <a name="reconnecting"></a>
180
+ ## About Reconnection
181
+
182
+ An important part of any websocket connection is what to do when a connection
183
+ drops off and the client needs to reconnect. MQTT has built-in reconnection
184
+ support that can be configured to behave in ways that suit the application.
185
+
186
+ #### Refresh Authentication Options / Signed Urls with `transformWsUrl` (Websocket Only)
187
+
188
+ When an mqtt connection drops and needs to reconnect, it's common to require
189
+ that any authentication associated with the connection is kept current with
190
+ the underlying auth mechanism. For instance some applications may pass an auth
191
+ token with connection options on the initial connection, while other cloud
192
+ services may require a url be signed with each connection.
193
+
194
+ By the time the reconnect happens in the application lifecycle, the original
195
+ auth data may have expired.
196
+
197
+ To address this we can use a hook called `transformWsUrl` to manipulate
198
+ either of the connection url or the client options at the time of a reconnect.
199
+
200
+ Example (update clientId & username on each reconnect):
201
+ ```
202
+ const transformWsUrl = (url, options, client) => {
203
+ client.options.username = `token=${this.get_current_auth_token()}`;
204
+ client.options.clientId = `${this.get_updated_clientId()}`;
205
+
206
+ return `${this.get_signed_cloud_url(url)`;
207
+ }
208
+
209
+ const connection = await mqtt.connectAsync(<wss url>, {
210
+ ...,
211
+ transformWsUrl: transformUrl,
212
+ });
213
+
214
+ ```
215
+ Now every time a new WebSocket connection is opened (hopefully not too often),
216
+ we will get a fresh signed url or fresh auth token data.
217
+
218
+ Note: Currently this hook does _not_ support promises, meaning that in order to
219
+ use the latest auth token, you must have some outside mechanism running that
220
+ handles application-level authentication refreshing so that the websocket
221
+ connection can simply grab the latest valid token or signed url.
222
+
223
+
224
+ #### Enabling Reconnection with `reconnectPeriod` option
225
+
226
+ To ensure that the mqtt client automatically tries to reconnect when the
227
+ connection is dropped, you must set the client option `reconnectPeriod` to a
228
+ value greater than 0. A value of 0 will disable reconnection and then terminate
229
+ the final connection when it drops.
230
+
231
+ The default value is 1000 ms which means it will try to reconnect 1 second
232
+ after losing the connection.
233
+
234
+ <a name="topicalias"></a>
235
+ ## About Topic Alias Management
236
+
237
+ ### Enabling automatic Topic Alias using
238
+ If the client sets the option `autoUseTopicAlias:true` then MQTT.js uses existing topic alias automatically.
239
+
240
+ example scenario:
241
+ ```
242
+ 1. PUBLISH topic:'t1', ta:1 (register)
243
+ 2. PUBLISH topic:'t1' -> topic:'', ta:1 (auto use existing map entry)
244
+ 3. PUBLISH topic:'t2', ta:1 (register overwrite)
245
+ 4. PUBLISH topic:'t2' -> topic:'', ta:1 (auto use existing map entry based on the receent map)
246
+ 5. PUBLISH topic:'t1' (t1 is no longer mapped to ta:1)
247
+ ```
248
+
249
+ User doesn't need to manage which topic is mapped to which topic alias.
250
+ If the user want to register topic alias, then publish topic with topic alias.
251
+ 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
+
253
+ ### Enabling automatic Topic Alias assign
254
+
255
+ If the client sets the option `autoAssignTopicAlias:true` then MQTT.js uses existing topic alias automatically.
256
+ 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
+
258
+ example scenario:
259
+ ```
260
+ The broker returns CONNACK (TopicAliasMaximum:3)
261
+ 1. PUBLISH topic:'t1' -> 't1', ta:1 (auto assign t1:1 and register)
262
+ 2. PUBLISH topic:'t1' -> '' , ta:1 (auto use existing map entry)
263
+ 3. PUBLISH topic:'t2' -> 't2', ta:2 (auto assign t1:2 and register. 2 was vacant)
264
+ 4. PUBLISH topic:'t3' -> 't3', ta:3 (auto assign t1:3 and register. 3 was vacant)
265
+ 5. PUBLISH topic:'t4' -> 't4', ta:1 (LRU entry is overwritten)
266
+ ```
267
+
268
+ Also user can manually register topic-alias pair using PUBLISH topic:'some', ta:X. It works well with automatic topic alias assign.
269
+
270
+ <a name="api"></a>
271
+ ## API
272
+
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
+ -------------------------------------------------------
292
+ <a name="connect"></a>
293
+ ### mqtt.connect([url], options)
294
+
295
+ Connects to the broker specified by the given url and options and
296
+ returns a [Client](#client).
297
+
298
+ The URL can be on the following protocols: 'mqtt', 'mqtts', 'tcp',
299
+ 'tls', 'ws', 'wss', 'wxs', 'alis'. The URL can also be an object as returned by
300
+ [`URL.parse()`](http://nodejs.org/api/url.html#url_url_parse_urlstr_parsequerystring_slashesdenotehost),
301
+ in that case the two objects are merged, i.e. you can pass a single
302
+ object with both the URL and the connect options.
303
+
304
+ You can also specify a `servers` options with content: `[{ host:
305
+ 'localhost', port: 1883 }, ... ]`, in that case that array is iterated
306
+ at every connect.
307
+
308
+ For all MQTT-related options, see the [Client](#client)
309
+ constructor.
310
+
311
+ -------------------------------------------------------
312
+ <a name="client"></a>
313
+ ### mqtt.Client(streamBuilder, options)
314
+
315
+ The `Client` class wraps a client connection to an
316
+ MQTT broker over an arbitrary transport method (TCP, TLS,
317
+ WebSocket, ecc).
318
+
319
+ `Client` automatically handles the following:
320
+
321
+ * Regular server pings
322
+ * QoS flow
323
+ * Automatic reconnections
324
+ * Start publishing before being connected
325
+
326
+ The arguments are:
327
+
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
339
+ offline
340
+ * `reconnectPeriod`: `1000` milliseconds, interval between two
341
+ reconnections. Disable auto reconnect by setting to `0`.
342
+ * `connectTimeout`: `30 * 1000` milliseconds, time to wait before a
343
+ 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.
387
+
388
+ In case mqtts (mqtt over tls) is required, the `options` object is
389
+ passed through to
390
+ [`tls.connect()`](http://nodejs.org/api/tls.html#tls_tls_connect_options_callback).
391
+ If you are using a **self-signed certificate**, pass the `rejectUnauthorized: false` option.
392
+ Beware that you are exposing yourself to man in the middle attacks, so it is a configuration
393
+ that is not recommended for production environments.
394
+
395
+ If you are connecting to a broker that supports only MQTT 3.1 (not
396
+ 3.1.1 compliant), you should pass these additional options:
397
+
398
+ ```js
399
+ {
400
+ protocolId: 'MQIsdp',
401
+ protocolVersion: 3
402
+ }
403
+ ```
404
+
405
+ This is confirmed on RabbitMQ 3.2.4, and on Mosquitto < 1.3. Mosquitto
406
+ version 1.3 and 1.4 works fine without those.
407
+
408
+ #### Event `'connect'`
409
+
410
+ `function (connack) {}`
411
+
412
+ 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.
416
+
417
+ #### Event `'reconnect'`
418
+
419
+ `function () {}`
420
+
421
+ Emitted when a reconnect starts.
422
+
423
+ #### Event `'close'`
424
+
425
+ `function () {}`
426
+
427
+ Emitted after a disconnection.
428
+
429
+ #### Event `'disconnect'`
430
+
431
+ `function (packet) {}`
432
+
433
+ Emitted after receiving disconnect packet from broker. MQTT 5.0 feature.
434
+
435
+ #### Event `'offline'`
436
+
437
+ `function () {}`
438
+
439
+ Emitted when the client goes offline.
440
+
441
+ #### Event `'error'`
442
+
443
+ `function (error) {}`
444
+
445
+ Emitted when the client cannot connect (i.e. connack rc != 0) or when a
446
+ parsing error occurs.
447
+
448
+ The following TLS errors will be emitted as an `error` event:
449
+
450
+ * `ECONNREFUSED`
451
+ * `ECONNRESET`
452
+ * `EADDRINUSE`
453
+ * `ENOTFOUND`
454
+
455
+ #### Event `'end'`
456
+
457
+ `function () {}`
458
+
459
+ Emitted when <a href="#end"><code>mqtt.Client#<b>end()</b></code></a> is called.
460
+ If a callback was passed to `mqtt.Client#end()`, this event is emitted once the
461
+ callback returns.
462
+
463
+ #### Event `'message'`
464
+
465
+ `function (topic, message, packet) {}`
466
+
467
+ 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
471
+ [mqtt-packet](https://github.com/mcollina/mqtt-packet#publish)
472
+
473
+ #### Event `'packetsend'`
474
+
475
+ `function (packet) {}`
476
+
477
+ Emitted when the client sends any packet. This includes .published() packets
478
+ as well as packets used by MQTT for managing subscriptions and connections
479
+ * `packet` received packet, as defined in
480
+ [mqtt-packet](https://github.com/mcollina/mqtt-packet)
481
+
482
+ #### Event `'packetreceive'`
483
+
484
+ `function (packet) {}`
485
+
486
+ Emitted when the client receives any packet. This includes packets from
487
+ subscribed topics as well as packets used by MQTT for managing subscriptions
488
+ and connections
489
+ * `packet` received packet, as defined in
490
+ [mqtt-packet](https://github.com/mcollina/mqtt-packet)
491
+
492
+ -------------------------------------------------------
493
+ <a name="publish"></a>
494
+ ### mqtt.Client#publish(topic, message, [options], [callback])
495
+
496
+ Publish a message to a topic
497
+
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,
515
+ or at the next tick if QoS 0. An error occurs if client is disconnecting.
516
+
517
+ -------------------------------------------------------
518
+ <a name="subscribe"></a>
519
+ ### mqtt.Client#subscribe(topic/topic array/topic object, [options], [callback])
520
+
521
+ Subscribe to a topic or topics
522
+
523
+ * `topic` is a `String` topic to subscribe to or an `Array` of
524
+ topics to subscribe to. It can also be an object, it has as object
525
+ keys the topic name and as value the QoS, like `{'test1': {qos: 0}, 'test2': {qos: 1}}`.
526
+ 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)`
536
+ 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
541
+
542
+ -------------------------------------------------------
543
+ <a name="unsubscribe"></a>
544
+ ### mqtt.Client#unsubscribe(topic/topic array, [options], [callback])
545
+
546
+ Unsubscribe from a topic or topics
547
+
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.
553
+
554
+ -------------------------------------------------------
555
+ <a name="end"></a>
556
+ ### mqtt.Client#end([force], [options], [callback])
557
+
558
+ Close the client, accepts the following options:
559
+
560
+ * `force`: passing it to true will close the client right away, without
561
+ waiting for the in-flight messages to be acked. This parameter is
562
+ 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
571
+ optional.
572
+
573
+ -------------------------------------------------------
574
+ <a name="removeOutgoingMessage"></a>
575
+ ### mqtt.Client#removeOutgoingMessage(mId)
576
+
577
+ Remove a message from the outgoingStore.
578
+ The outgoing callback will be called with Error('Message removed') if the message is removed.
579
+
580
+ After this function is called, the messageId is released and becomes reusable.
581
+
582
+ * `mId`: The messageId of the message in the outgoingStore.
583
+
584
+ -------------------------------------------------------
585
+ <a name="reconnect"></a>
586
+ ### mqtt.Client#reconnect()
587
+
588
+ Connect again using the same options as connect()
589
+
590
+ -------------------------------------------------------
591
+ <a name="handleMessage"></a>
592
+ ### mqtt.Client#handleMessage(packet, callback)
593
+
594
+ Handle messages with backpressure support, one at a time.
595
+ Override at will, but __always call `callback`__, or the client
596
+ will hang.
597
+
598
+ -------------------------------------------------------
599
+ <a name="connected"></a>
600
+ ### mqtt.Client#connected
601
+
602
+ Boolean : set to `true` if the client is connected. `false` otherwise.
603
+
604
+ -------------------------------------------------------
605
+ <a name="getLastMessageId"></a>
606
+ ### mqtt.Client#getLastMessageId()
607
+
608
+ Number : get last message id. This is for sent messages only.
609
+
610
+ -------------------------------------------------------
611
+ <a name="reconnecting"></a>
612
+ ### mqtt.Client#reconnecting
613
+
614
+ Boolean : set to `true` if the client is trying to reconnect to the server. `false` otherwise.
615
+
616
+ -------------------------------------------------------
617
+ <a name="store"></a>
618
+ ### mqtt.Store(options)
619
+
620
+ In-memory implementation of the message store.
621
+
622
+ * `options` is the store options:
623
+ * `clean`: `true`, clean inflight messages when close is called (default `true`)
624
+
625
+ Other implementations of `mqtt.Store`:
626
+
627
+ * [mqtt-level-store](http://npm.im/mqtt-level-store) which uses
628
+ [Level-browserify](http://npm.im/level-browserify) to store the inflight
629
+ data, making it usable both in Node and the Browser.
630
+ * [mqtt-nedb-store](https://github.com/behrad/mqtt-nedb-store) which
631
+ uses [nedb](https://www.npmjs.com/package/nedb) to store the inflight
632
+ data.
633
+ * [mqtt-localforage-store](http://npm.im/mqtt-localforage-store) which uses
634
+ [localForage](http://npm.im/localforage) to store the inflight
635
+ data, making it usable in the Browser without browserify.
636
+
637
+ -------------------------------------------------------
638
+ <a name="put"></a>
639
+ ### mqtt.Store#put(packet, callback)
640
+
641
+ Adds a packet to the store, a packet is
642
+ anything that has a `messageId` property.
643
+ The callback is called when the packet has been stored.
644
+
645
+ -------------------------------------------------------
646
+ <a name="createStream"></a>
647
+ ### mqtt.Store#createStream()
648
+
649
+ Creates a stream with all the packets in the store.
650
+
651
+ -------------------------------------------------------
652
+ <a name="del"></a>
653
+ ### mqtt.Store#del(packet, cb)
654
+
655
+ Removes a packet from the store, a packet is
656
+ anything that has a `messageId` property.
657
+ The callback is called when the packet has been removed.
658
+
659
+ -------------------------------------------------------
660
+ <a name="close"></a>
661
+ ### mqtt.Store#close(cb)
662
+
663
+ Closes the Store.
664
+
665
+ <a name="browser"></a>
666
+ ## Browser
667
+
668
+ <a name="cdn"></a>
669
+ ### Via CDN
670
+
671
+ The MQTT.js bundle is available through http://unpkg.com, specifically
672
+ at https://unpkg.com/mqtt/dist/mqtt.min.js.
673
+ See http://unpkg.com for the full documentation on version ranges.
674
+
675
+ <a name="browserify"></a>
676
+ ### Browserify
677
+
678
+ 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.
679
+
680
+ ```bash
681
+ mkdir tmpdir
682
+ cd tmpdir
683
+ npm install mqtt
684
+ npm install browserify
685
+ npm install tinyify
686
+ cd node_modules/mqtt/
687
+ npm install .
688
+ npx browserify mqtt.js -s mqtt >browserMqtt.js // use script tag
689
+ # show size for compressed browser transfer
690
+ gzip <browserMqtt.js | wc -c
691
+ ```
692
+
693
+ **Be sure to only use this bundle with `ws` or `wss` URLs in the browser. Others URL types will likey fail**
694
+
695
+ <a name="webpack"></a>
696
+ ### Webpack
697
+
698
+ 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.
699
+
700
+ ```javascript
701
+ npm install -g webpack // install webpack
702
+
703
+ cd node_modules/mqtt
704
+ npm install . // install dev dependencies
705
+ webpack mqtt.js ./browserMqtt.js --output-library mqtt
706
+ ```
707
+
708
+ you can then use mqtt.js in the browser with the same api than node's one.
709
+
710
+ ```html
711
+ <html>
712
+ <head>
713
+ <title>test Ws mqtt.js</title>
714
+ </head>
715
+ <body>
716
+ <script src="./browserMqtt.js"></script>
717
+ <script>
718
+ const client = mqtt.connect() // you add a ws:// url here
719
+ client.subscribe("mqtt/demo")
720
+
721
+ client.on("message", function (topic, payload) {
722
+ alert([topic, payload].join(": "))
723
+ client.end()
724
+ })
725
+
726
+ client.publish("mqtt/demo", "hello world!")
727
+ </script>
728
+ </body>
729
+ </html>
730
+ ```
731
+
732
+ ### React
733
+ ```
734
+ npm install -g webpack // Install webpack globally
735
+ npm install mqtt // Install MQTT library
736
+ cd node_modules/mqtt
737
+ npm install . // Install dev deps at current dir
738
+ webpack mqtt.js --output-library mqtt // Build
739
+
740
+ // now you can import the library with ES6 import, commonJS not tested
741
+ ```
742
+
743
+
744
+ ```javascript
745
+ import React from 'react';
746
+ import mqtt from 'mqtt';
747
+
748
+ export default () => {
749
+ const [connectionStatus, setConnectionStatus] = React.useState(false);
750
+ const [messages, setMessages] = React.useState([]);
751
+
752
+ useEffect(() => {
753
+ const client = mqtt.connect(SOME_URL);
754
+ client.on('connect', () => setConnectionStatus(true));
755
+ client.on('message', (topic, payload, packet) => {
756
+ setMessages(messages.concat(payload.toString()));
757
+ });
758
+ }, []);
759
+
760
+ return (
761
+ <>
762
+ {messages.map((message) => (
763
+ <h2>{message}</h2>
764
+ )
765
+ </>
766
+ )
767
+ }
768
+ ```
769
+
770
+ 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)).
771
+
772
+ <a name="qos"></a>
773
+ ## About QoS
774
+
775
+ Here is how QoS works:
776
+
777
+ * QoS 0 : received **at most once** : The packet is sent, and that's it. There is no validation about whether it has been received.
778
+ * 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.
779
+ * QoS 2 : received **exactly once** : Same as QoS 1 but there is no duplicates.
780
+
781
+ About data consumption, obviously, QoS 2 > QoS 1 > QoS 0, if that's a concern to you.
782
+
783
+ <a name="typescript"></a>
784
+ ## Usage with TypeScript
785
+ This repo bundles TypeScript definition files for use in TypeScript projects and to support tools that can read `.d.ts` files.
786
+
787
+ ### Pre-requisites
788
+ Before you can begin using these TypeScript definitions with your project, you need to make sure your project meets a few of these requirements:
789
+ * TypeScript >= 2.1
790
+ * Set tsconfig.json: `{"compilerOptions" : {"moduleResolution" : "node"}, ...}`
791
+ * Includes the TypeScript definitions for node. You can use npm to install this by typing the following into a terminal window:
792
+ `npm install --save-dev @types/node`
793
+
794
+ ### Typescript example
795
+ ```
796
+ import * as mqtt from "mqtt"
797
+ let client : mqtt.MqttClient = mqtt.connect('mqtt://test.mosquitto.org')
798
+ ```
799
+
800
+ <a name="weapp-alipay"></a>
801
+ ## WeChat and Ali Mini Program support
802
+ ### WeChat Mini Program
803
+ 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).
804
+
805
+ ```js
806
+ const mqtt = require('mqtt')
807
+ const client = mqtt.connect('wxs://test.mosquitto.org')
808
+ ```
809
+
810
+ ### Ali Mini Program
811
+ 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).
812
+ <a name="example"></a>
813
+
814
+ ```js
815
+ const mqtt = require('mqtt')
816
+ const client = mqtt.connect('alis://test.mosquitto.org')
817
+ ```
818
+
819
+ <a name="contributing"></a>
820
+ ## Contributing
821
+
822
+ MQTT.js is an **OPEN Open Source Project**. This means that:
823
+
824
+ > Individuals making significant and valuable contributions are given commit-access to the project to contribute as they see fit. This project is more like an open wiki than a standard guarded open source project.
825
+
826
+ See the [CONTRIBUTING.md](https://github.com/mqttjs/MQTT.js/blob/master/CONTRIBUTING.md) file for more details.
827
+
828
+ ### Contributors
829
+
830
+ MQTT.js is only possible due to the excellent work of the following contributors:
831
+
832
+ <table><tbody>
833
+ <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>
834
+ <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>
835
+ <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>
836
+ <tr><th align="left">Siarhei Buntsevich</th><td><a href="https://github.com/scarry1992">GitHub/scarry1992</a></td></tr>
837
+ </tbody></table>
838
+
839
+
840
+ <a name="license"></a>
841
+ ## License
842
+
843
+ MIT