mqtt 5.0.0-beta.4 → 5.0.1

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.
Files changed (38) hide show
  1. package/README.md +113 -120
  2. package/build/package.json +1 -1
  3. package/build/src/lib/client.d.ts +37 -83
  4. package/build/src/lib/client.js +71 -14
  5. package/build/src/lib/client.js.map +1 -1
  6. package/build/src/lib/connect/ali.js.map +1 -1
  7. package/build/src/lib/connect/index.d.ts +4 -0
  8. package/build/src/lib/connect/index.js +36 -1
  9. package/build/src/lib/connect/index.js.map +1 -1
  10. package/build/src/lib/connect/tcp.js.map +1 -1
  11. package/build/src/lib/connect/tls.js.map +1 -1
  12. package/build/src/lib/connect/ws.js +1 -1
  13. package/build/src/lib/connect/ws.js.map +1 -1
  14. package/build/src/lib/connect/wx.js.map +1 -1
  15. package/build/src/lib/handlers/publish.js.map +1 -1
  16. package/build/src/lib/shared.d.ts +5 -4
  17. package/build/src/lib/unique-message-id-provider.d.ts +3 -2
  18. package/build/src/lib/unique-message-id-provider.js.map +1 -1
  19. package/build/src/mqtt.d.ts +4 -2
  20. package/build/src/mqtt.js +18 -2
  21. package/build/src/mqtt.js.map +1 -1
  22. package/build/tsconfig.build.tsbuildinfo +1 -1
  23. package/dist/mqtt.js +127 -19
  24. package/dist/mqtt.min.js +4 -4
  25. package/doc/subscribe.txt +1 -1
  26. package/package.json +1 -1
  27. package/src/lib/client.ts +211 -176
  28. package/src/lib/connect/ali.ts +2 -2
  29. package/src/lib/connect/index.ts +66 -5
  30. package/src/lib/connect/tcp.ts +1 -1
  31. package/src/lib/connect/tls.ts +1 -3
  32. package/src/lib/connect/ws.ts +4 -5
  33. package/src/lib/connect/wx.ts +2 -2
  34. package/src/lib/default-message-id-provider.ts +2 -2
  35. package/src/lib/handlers/publish.ts +2 -2
  36. package/src/lib/shared.ts +4 -4
  37. package/src/lib/unique-message-id-provider.ts +3 -2
  38. package/src/mqtt.ts +4 -1
package/README.md CHANGED
@@ -10,11 +10,8 @@
10
10
  MQTT.js is a client library for the [MQTT](http://mqtt.org/) protocol, written
11
11
  in JavaScript for node.js and the browser.
12
12
 
13
- > MQTT [5.0.0 BETA](https://www.npmjs.com/package/mqtt/v/beta) is now available! Try it out and give us [feedback](https://github.com/mqttjs/MQTT.js/issues/1639): `npm i mqtt@beta`
14
-
15
13
  ## Table of Contents
16
14
 
17
- - [**MQTT.js vNext**](#vnext)
18
15
  - [Upgrade notes](#notes)
19
16
  - [Installation](#install)
20
17
  - [Example](#example)
@@ -34,17 +31,11 @@ MQTT.js is an OPEN Open Source Project, see the [Contributing](#contributing) se
34
31
  [![JavaScript Style
35
32
  Guide](https://cdn.rawgit.com/feross/standard/master/badge.svg)](https://github.com/feross/standard)
36
33
 
37
- <a name="vnext"></a>
38
-
39
- ## Next major version of MQTT.js
40
-
41
- 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)
42
-
43
34
  <a name="notes"></a>
44
35
 
45
36
  ## Important notes for existing users
46
37
 
47
- **v5.0.0** (**BETA** 06/2023)
38
+ **v5.0.0** (07/2023)
48
39
 
49
40
  - Removes support for all end of life node versions (v12 and v14), and now supports node v18 and v20.
50
41
  - Completely rewritten in Typescript 🚀.
@@ -122,7 +113,7 @@ client.on("message", (topic, message) => {
122
113
 
123
114
  output:
124
115
 
125
- ```
116
+ ```sh
126
117
  Hello mqtt
127
118
  ```
128
119
 
@@ -135,8 +126,6 @@ You can also use a test instance: test.mosquitto.org.
135
126
  If you do not want to install a separate broker, you can try using the
136
127
  [Aedes](https://github.com/moscajs/aedes).
137
128
 
138
- to use MQTT.js in the browser see the [browserify](#browserify) section
139
-
140
129
  <a name="import_styles"></a>
141
130
 
142
131
  ## Import styles
@@ -164,12 +153,6 @@ import { connect } from "mqtt"; // import connect from mqtt
164
153
  let client = connect("mqtt://test.mosquitto.org"); // create a client
165
154
  ```
166
155
 
167
- <a name="promises"></a>
168
-
169
- ## Promise support
170
-
171
- 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.
172
-
173
156
  <a name="cli"></a>
174
157
 
175
158
  ## Command Line Tools
@@ -184,13 +167,13 @@ npm install mqtt -g
184
167
 
185
168
  Then, on one terminal
186
169
 
187
- ```
170
+ ```sh
188
171
  mqtt sub -t 'hello' -h 'test.mosquitto.org' -v
189
172
  ```
190
173
 
191
174
  On another
192
175
 
193
- ```
176
+ ```sh
194
177
  mqtt pub -t 'hello' -h 'test.mosquitto.org' -m 'from MQTT.js'
195
178
  ```
196
179
 
@@ -205,7 +188,6 @@ MQTT.js uses the [debug](https://www.npmjs.com/package/debug#cmd) package for de
205
188
  ```ps
206
189
  # (example using PowerShell, the VS Code default)
207
190
  $env:DEBUG='mqttjs*'
208
-
209
191
  ```
210
192
 
211
193
  <a name="reconnecting"></a>
@@ -232,7 +214,7 @@ either of the connection url or the client options at the time of a reconnect.
232
214
 
233
215
  Example (update clientId & username on each reconnect):
234
216
 
235
- ```
217
+ ```js
236
218
  const transformWsUrl = (url, options, client) => {
237
219
  client.options.username = `token=${this.get_current_auth_token()}`;
238
220
  client.options.clientId = `${this.get_updated_clientId()}`;
@@ -275,7 +257,7 @@ If the client sets the option `autoUseTopicAlias:true` then MQTT.js uses existin
275
257
 
276
258
  example scenario:
277
259
 
278
- ```
260
+ ```bash
279
261
  1. PUBLISH topic:'t1', ta:1 (register)
280
262
  2. PUBLISH topic:'t1' -> topic:'', ta:1 (auto use existing map entry)
281
263
  3. PUBLISH topic:'t2', ta:1 (register overwrite)
@@ -294,7 +276,7 @@ If no topic alias exists, then assign a new vacant topic alias automatically. If
294
276
 
295
277
  example scenario:
296
278
 
297
- ```
279
+ ```bash
298
280
  The broker returns CONNACK (TopicAliasMaximum:3)
299
281
  1. PUBLISH topic:'t1' -> 't1', ta:1 (auto assign t1:1 and register)
300
282
  2. PUBLISH topic:'t1' -> '' , ta:1 (auto use existing map entry)
@@ -310,12 +292,17 @@ Also user can manually register topic-alias pair using PUBLISH topic:'some', ta:
310
292
  ## API
311
293
 
312
294
  - [`mqtt.connect()`](#connect)
295
+ - [`mqtt.connectAsync()`](#connect-async)
313
296
  - [`mqtt.Client()`](#client)
314
297
  - [`mqtt.Client#connect()`](#client-connect)
315
298
  - [`mqtt.Client#publish()`](#publish)
299
+ - [`mqtt.Client#publishAsync()`](#publish-async)
316
300
  - [`mqtt.Client#subscribe()`](#subscribe)
301
+ - [`mqtt.Client#subscribeAsync()`](#subscribe-async)
317
302
  - [`mqtt.Client#unsubscribe()`](#unsubscribe)
303
+ - [`mqtt.Client#unsubscribeAsync()`](#unsubscribe-async)
318
304
  - [`mqtt.Client#end()`](#end)
305
+ - [`mqtt.Client#endAsync()`](#end-async)
319
306
  - [`mqtt.Client#removeOutgoingMessage()`](#removeOutgoingMessage)
320
307
  - [`mqtt.Client#reconnect()`](#reconnect)
321
308
  - [`mqtt.Client#handleMessage()`](#handleMessage)
@@ -350,6 +337,12 @@ at every connect.
350
337
  For all MQTT-related options, see the [Client](#client)
351
338
  constructor.
352
339
 
340
+ <a name="connect-async"></a>
341
+
342
+ ### connectAsync([url], options)
343
+
344
+ Async [`connect`](#connect). Returns a `Promise` that resolves to a `mqtt.Client` instance.
345
+
353
346
  ---
354
347
 
355
348
  <a name="client"></a>
@@ -574,6 +567,12 @@ Publish a message to a topic
574
567
  - `callback` - `function (err)`, fired when the QoS handling completes,
575
568
  or at the next tick if QoS 0. An error occurs if client is disconnecting.
576
569
 
570
+ <a name="publish-async"></a>
571
+
572
+ ### mqtt.Client#publishAsync(topic, message, [options])
573
+
574
+ Async [`publish`](#publish). Returns a `Promise<void>`.
575
+
577
576
  ---
578
577
 
579
578
  <a name="subscribe"></a>
@@ -601,6 +600,12 @@ Subscribe to a topic or topics
601
600
  - `topic` is a subscribed to topic
602
601
  - `qos` is the granted QoS level on it
603
602
 
603
+ <a name="subscribe-async"></a>
604
+
605
+ ### mqtt.Client#subscribeAsync(topic/topic array/topic object, [options])
606
+
607
+ Async [`subscribe`](#subscribe). Returns a `Promise<granted[]>`.
608
+
604
609
  ---
605
610
 
606
611
  <a name="unsubscribe"></a>
@@ -615,6 +620,12 @@ Unsubscribe from a topic or topics
615
620
  - `userProperties`: The User Property is allowed to appear multiple times to represent multiple name, value pairs `object`
616
621
  - `callback` - `function (err)`, fired on unsuback. An error occurs if client is disconnecting.
617
622
 
623
+ <a name="unsubscribe-async"></a>
624
+
625
+ ### mqtt.Client#unsubscribeAsync(topic/topic array, [options])
626
+
627
+ Async [`unsubscribe`](#unsubscribe). Returns a `Promise<void>`.
628
+
618
629
  ---
619
630
 
620
631
  <a name="end"></a>
@@ -636,6 +647,12 @@ Close the client, accepts the following options:
636
647
  - `callback`: will be called when the client is closed. This parameter is
637
648
  optional.
638
649
 
650
+ <a name="end-async"></a>
651
+
652
+ ### mqtt.Client#endAsync([force], [options])
653
+
654
+ Async [`end`](#end). Returns a `Promise<void>`.
655
+
639
656
  ---
640
657
 
641
658
  <a name="removeOutgoingMessage"></a>
@@ -756,6 +773,12 @@ Closes the Store.
756
773
 
757
774
  ## Browser
758
775
 
776
+ MQTT.js is bundled using [browserify](http://browserify.org/). You can find the browser build in the `dist` folder.
777
+
778
+ ```js
779
+ import mqtt from 'mqtt/dist/mqtt.min'
780
+ ```
781
+
759
782
  <a name="cdn"></a>
760
783
 
761
784
  ### Via CDN
@@ -764,104 +787,86 @@ The MQTT.js bundle is available through <http://unpkg.com>, specifically
764
787
  at <https://unpkg.com/mqtt/dist/mqtt.min.js>.
765
788
  See <http://unpkg.com> for the full documentation on version ranges.
766
789
 
767
- <a name="browserify"></a>
768
-
769
- ### Browserify
770
-
771
- 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.
772
-
773
- ```bash
774
- mkdir tmpdir
775
- cd tmpdir
776
- npm install mqtt
777
- npm install browserify
778
- npm install tinyify
779
- cd node_modules/mqtt/
780
- npm install .
781
- npx browserify mqtt.js -s mqtt >browserMqtt.js // use script tag
782
- # show size for compressed browser transfer
783
- gzip <browserMqtt.js | wc -c
784
- ```
785
-
786
790
  **Be sure to only use this bundle with `ws` or `wss` URLs in the browser. Others URL types will likey fail**
787
791
 
788
792
  <a name="webpack"></a>
789
793
 
790
794
  ### Webpack
791
795
 
792
- 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.
796
+ If you are using webpack simply import MQTT.js as you would any other module.
793
797
 
794
- ```javascript
795
- npm install -g webpack // install webpack
798
+ ```js
799
+ import mqtt from 'mqtt'
796
800
 
797
- cd node_modules/mqtt
798
- npm install . // install dev dependencies
799
- webpack mqtt.js ./browserMqtt.js --output-library mqtt
801
+ const client = mqtt.connect('ws://test.mosquitto.org:8080')
800
802
  ```
801
803
 
802
- you can then use mqtt.js in the browser with the same api than node's one.
803
-
804
- ```html
805
- <html>
806
- <head>
807
- <title>test Ws mqtt.js</title>
808
- </head>
809
- <body>
810
- <script src="./browserMqtt.js"></script>
811
- <script>
812
- const client = mqtt.connect(); // you add a ws:// url here
813
- client.subscribe("mqtt/demo");
814
-
815
- client.on("message", function (topic, payload) {
816
- alert([topic, payload].join(": "));
817
- client.end();
818
- });
819
-
820
- client.publish("mqtt/demo", "hello world!");
821
- </script>
822
- </body>
823
- </html>
824
- ```
804
+ If you get errors when building your app with webpack v5, it's because starting from v5, webpack doesn't polyfill Node.js core modules anymore. You can fix this by adding the following to your webpack config:
825
805
 
826
- ### React
806
+ ```js
807
+ const NodePolyfillPlugin = require("node-polyfill-webpack-plugin")
827
808
 
809
+ module.exports = {
810
+ // Other rules...
811
+ plugins: [
812
+ new NodePolyfillPlugin()
813
+ ]
814
+ }
828
815
  ```
829
- npm install -g webpack // Install webpack globally
830
- npm install mqtt // Install MQTT library
831
- cd node_modules/mqtt
832
- npm install . // Install dev deps at current dir
833
- webpack mqtt.js --output-library mqtt // Build
834
816
 
835
- // now you can import the library with ES6 import, commonJS not tested
817
+ Otherwise just add the missing polyfills manually:
818
+
819
+ ```js
820
+
821
+ module.exports = {
822
+ // Other rules...
823
+ resolve: {
824
+ fallback: {
825
+ "buffer": require.resolve("buffer/"),
826
+ "stream": require.resolve("stream-browserify"),
827
+ "process": require.resolve("process/browser"),
828
+ "path": require.resolve("path-browserify"),
829
+ "fs": false
830
+ }
831
+ }
832
+ }
836
833
  ```
837
834
 
838
- ```javascript
839
- import React from 'react';
840
- import mqtt from 'mqtt';
835
+ <a name="vite"></a>
841
836
 
842
- export default () => {
843
- const [connectionStatus, setConnectionStatus] = React.useState(false);
844
- const [messages, setMessages] = React.useState([]);
837
+ ### Vite
845
838
 
846
- useEffect(() => {
847
- const client = mqtt.connect(SOME_URL);
848
- client.on('connect', () => setConnectionStatus(true));
849
- client.on('message', (topic, payload, packet) => {
850
- setMessages(messages.concat(payload.toString()));
851
- });
852
- }, []);
853
-
854
- return (
855
- <>
856
- {messages.map((message) => (
857
- <h2>{message}</h2>
858
- )
859
- </>
860
- )
861
- }
839
+ If you are using vite simply import MQTT.js as you would any other module. In order to use MQTT.js with vite, you need to add the following to your vite config:
840
+
841
+ ```js
842
+ // other imports
843
+ import { NodeGlobalsPolyfillPlugin } from '@esbuild-plugins/node-globals-polyfill'
844
+
845
+
846
+ export default defineConfig({
847
+ // Other rules...
848
+ optimizeDeps: {
849
+ esbuildOptions: {
850
+ // Node.js global to browser globalThis
851
+ define: {
852
+ global: 'globalThis'
853
+ },
854
+ // Enable esbuild polyfill plugins
855
+ plugins: [
856
+ NodeGlobalsPolyfillPlugin({
857
+ buffer: true
858
+ })
859
+ ]
860
+ }
861
+ }
862
+ });
862
863
  ```
863
864
 
864
- 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)).
865
+ This requires the `@esbuild-plugins/node-globals-polyfill` package to be installed:
866
+
867
+ ```bash
868
+ npm install --save-dev @esbuild-plugins/node-globals-polyfill
869
+ ```
865
870
 
866
871
  <a name="qos"></a>
867
872
 
@@ -879,25 +884,13 @@ About data consumption, obviously, QoS 2 > QoS 1 > QoS 0, if that's a concern to
879
884
 
880
885
  ## Usage with TypeScript
881
886
 
882
- This repo bundles TypeScript definition files for use in TypeScript projects and to support tools that can read `.d.ts` files.
887
+ Starting from v5 this project is written in TypeScript and the type definitions are included in the package.
883
888
 
884
- ### Pre-requisites
889
+ Example:
885
890
 
886
- Before you can begin using these TypeScript definitions with your project, you need to make sure your project meets these requirements:
887
-
888
- - TypeScript >= 2.1
889
- - Set tsconfig.json: `{"compilerOptions" : {"moduleResolution" : "node"}, ...}`
890
- - Includes the TypeScript definitions for Node and [ws](https://www.npmjs.com/package/ws). These types are used as
891
- 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
892
- safety.
893
- Use npm to install them by typing the following into a terminal window:
894
- `npm install --save-dev @types/node @types/ws`
895
-
896
- ### TypeScript example
897
-
898
- ```
899
- import * as mqtt from "mqtt"
900
- let client : mqtt.MqttClient = mqtt.connect('mqtt://test.mosquitto.org')
891
+ ```ts
892
+ import { connect } from "mqtt"
893
+ const client = connect('mqtt://test.mosquitto.org')
901
894
  ```
902
895
 
903
896
  <a name="weapp-alipay"></a>
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "mqtt",
3
3
  "description": "A library for the MQTT protocol",
4
- "version": "5.0.0-beta.4",
4
+ "version": "5.0.1",
5
5
  "contributors": [
6
6
  "Adam Rudd <adamvrr@gmail.com>",
7
7
  "Matteo Collina <matteo.collina@gmail.com> (https://github.com/mcollina)",
@@ -1,9 +1,9 @@
1
1
  /// <reference types="node" />
2
2
  /// <reference types="node" />
3
- import { IAuthPacket, IConnackPacket, IDisconnectPacket, IPublishPacket, Packet, QoS, UserProperties } from 'mqtt-packet';
3
+ import { IAuthPacket, IConnackPacket, IDisconnectPacket, IPublishPacket, ISubscribePacket, Packet, QoS, IConnectPacket } from 'mqtt-packet';
4
4
  import { IMessageIdProvider } from './default-message-id-provider';
5
5
  import { DuplexOptions } from 'readable-stream';
6
- import Store from './store';
6
+ import Store, { IStore } from './store';
7
7
  import { ClientOptions } from 'ws';
8
8
  import { ClientRequestArgs } from 'http';
9
9
  import { DoneCallback, ErrorWithReasonCode, IStream, StreamBuilder, VoidCallback } from './shared';
@@ -20,13 +20,13 @@ export interface ISecureClientOptions {
20
20
  rejectUnauthorized?: boolean;
21
21
  ALPNProtocols?: string[] | Buffer[] | Uint8Array[] | Buffer | Uint8Array;
22
22
  }
23
- export type AckHandler = (topic: string, message: Buffer, packet: any, cb: (error?: Error, code?: number) => void) => void;
23
+ export type AckHandler = (topic: string, message: Buffer, packet: any, cb: (error: Error | number, code?: number) => void) => void;
24
24
  export interface IClientOptions extends ISecureClientOptions {
25
25
  encoding?: BufferEncoding;
26
26
  browserBufferSize?: number;
27
27
  binary?: boolean;
28
28
  my?: any;
29
- manualConnect?: any;
29
+ manualConnect?: boolean;
30
30
  authPacket?: Partial<IAuthPacket>;
31
31
  writeCache?: boolean;
32
32
  servername?: string;
@@ -40,17 +40,10 @@ export interface IClientOptions extends ISecureClientOptions {
40
40
  path?: string;
41
41
  protocol?: MqttProtocol;
42
42
  wsOptions?: ClientOptions | ClientRequestArgs | DuplexOptions;
43
- keepalive?: number;
44
- clientId?: string;
45
- protocolId?: string;
46
- protocolVersion?: number;
47
- clean?: boolean;
48
43
  reconnectPeriod?: number;
49
44
  connectTimeout?: number;
50
- username?: string;
51
- password?: Buffer | string;
52
- incomingStore?: Store;
53
- outgoingStore?: Store;
45
+ incomingStore?: IStore;
46
+ outgoingStore?: IStore;
54
47
  queueQoSZero?: boolean;
55
48
  log?: (...args: any[]) => void;
56
49
  autoUseTopicAlias?: boolean;
@@ -62,97 +55,48 @@ export interface IClientOptions extends ISecureClientOptions {
62
55
  protocol?: 'wss' | 'ws' | 'mqtt' | 'mqtts' | 'tcp' | 'ssl' | 'wx' | 'wxs';
63
56
  }>;
64
57
  resubscribe?: boolean;
65
- will?: {
66
- topic: string;
67
- payload: Buffer | string;
68
- qos: QoS;
69
- retain: boolean;
70
- properties?: {
71
- willDelayInterval?: number;
72
- payloadFormatIndicator?: boolean;
73
- messageExpiryInterval?: number;
74
- contentType?: string;
75
- responseTopic?: string;
76
- correlationData?: Buffer;
77
- userProperties?: UserProperties;
78
- };
79
- authPacket?: any;
80
- manualConnect?: boolean;
81
- };
82
58
  transformWsUrl?: (url: string, options: IClientOptions, client: MqttClient) => string;
83
- properties?: {
84
- sessionExpiryInterval?: number;
85
- receiveMaximum?: number;
86
- maximumPacketSize?: number;
87
- topicAliasMaximum?: number;
88
- requestResponseInformation?: boolean;
89
- requestProblemInformation?: boolean;
90
- userProperties?: UserProperties;
91
- authenticationMethod?: string;
92
- authenticationData?: Buffer;
93
- };
94
59
  messageIdProvider?: IMessageIdProvider;
95
60
  browserBufferTimeout?: number;
96
61
  objectMode?: boolean;
62
+ clientId?: string;
63
+ protocolVersion?: IConnectPacket['protocolVersion'];
64
+ protocolId?: IConnectPacket['protocolId'];
65
+ clean?: boolean;
66
+ keepalive?: number;
67
+ username?: string;
68
+ password?: Buffer | string;
69
+ will?: IConnectPacket['will'];
70
+ properties?: IConnectPacket['properties'];
97
71
  }
98
72
  export interface IClientPublishOptions {
99
73
  qos?: QoS;
100
74
  retain?: boolean;
101
75
  dup?: boolean;
102
- properties?: {
103
- payloadFormatIndicator?: boolean;
104
- messageExpiryInterval?: number;
105
- topicAlias?: number;
106
- responseTopic?: string;
107
- correlationData?: Buffer;
108
- userProperties?: UserProperties;
109
- subscriptionIdentifier?: number;
110
- contentType?: string;
111
- };
76
+ properties?: IPublishPacket['properties'];
112
77
  cbStorePut?: StorePutCallback;
113
78
  }
114
- export interface IClientSubscribeOptions {
115
- qos: QoS;
116
- nl?: boolean;
117
- rap?: boolean;
118
- rh?: number;
119
- properties?: {
120
- subscriptionIdentifier?: number;
121
- userProperties?: UserProperties;
122
- };
123
- }
124
- export interface IClientSubscribeProperties {
125
- properties?: {
126
- subscriptionIdentifier?: number;
127
- userProperties?: UserProperties;
128
- };
129
- }
130
79
  export interface IClientReconnectOptions {
131
80
  incomingStore?: Store;
132
81
  outgoingStore?: Store;
133
82
  }
134
- export interface ISubscriptionGrant {
135
- topic: string;
136
- qos: QoS | number;
137
- nl?: boolean;
138
- rap?: boolean;
139
- rh?: number;
83
+ export interface IClientSubscribeProperties {
84
+ properties?: ISubscribePacket['properties'];
140
85
  }
141
- export interface ISubscriptionRequest extends IClientSubscribeProperties {
142
- topic: string;
86
+ export interface IClientSubscribeOptions extends IClientSubscribeProperties {
143
87
  qos: QoS;
144
88
  nl?: boolean;
145
89
  rap?: boolean;
146
90
  rh?: number;
147
91
  }
148
- export interface ISubscriptioOptions extends IClientSubscribeProperties {
149
- qos: QoS;
150
- nl?: boolean;
151
- rap?: boolean;
152
- rh?: number;
92
+ export interface ISubscriptionRequest extends IClientSubscribeOptions {
93
+ topic: string;
94
+ }
95
+ export interface ISubscriptionGrant extends Omit<ISubscriptionRequest, 'qos' | 'properties'> {
96
+ qos: QoS | 128;
153
97
  }
154
98
  export type ISubscriptionMap = {
155
- [topic: string]: ISubscriptioOptions;
99
+ [topic: string]: IClientSubscribeOptions;
156
100
  } & {
157
101
  resubscribe?: boolean;
158
102
  };
@@ -183,8 +127,8 @@ export default class MqttClient extends TypedEventEmitter<MqttClientEventCallbac
183
127
  disconnecting: boolean;
184
128
  disconnected: boolean;
185
129
  reconnecting: boolean;
186
- incomingStore: Store;
187
- outgoingStore: Store;
130
+ incomingStore: IStore;
131
+ outgoingStore: IStore;
188
132
  options: IClientOptions;
189
133
  queueQoSZero: boolean;
190
134
  _reconnectCount: number;
@@ -225,19 +169,29 @@ export default class MqttClient extends TypedEventEmitter<MqttClientEventCallbac
225
169
  publish(topic: string, message: string | Buffer): MqttClient;
226
170
  publish(topic: string, message: string | Buffer, callback?: DoneCallback): MqttClient;
227
171
  publish(topic: string, message: string | Buffer, opts?: IClientPublishOptions, callback?: DoneCallback): MqttClient;
172
+ publishAsync(topic: string, message: string | Buffer): Promise<void>;
173
+ publishAsync(topic: string, message: string | Buffer, opts?: IClientPublishOptions): Promise<void>;
228
174
  subscribe(topicObject: string | string[] | ISubscriptionMap): MqttClient;
229
175
  subscribe(topicObject: string | string[] | ISubscriptionMap, callback?: ClientSubscribeCallback): MqttClient;
230
176
  subscribe(topicObject: string | string[] | ISubscriptionMap, opts?: IClientSubscribeOptions | IClientSubscribeProperties): MqttClient;
231
177
  subscribe(topicObject: string | string[] | ISubscriptionMap, opts?: IClientSubscribeOptions | IClientSubscribeProperties, callback?: ClientSubscribeCallback): MqttClient;
178
+ subscribeAsync(topicObject: string | string[] | ISubscriptionMap): Promise<ISubscriptionGrant[]>;
179
+ subscribeAsync(topicObject: string | string[] | ISubscriptionMap, opts?: IClientSubscribeOptions | IClientSubscribeProperties): Promise<ISubscriptionGrant[]>;
232
180
  unsubscribe(topic: string | string[]): MqttClient;
233
181
  unsubscribe(topic: string | string[], opts?: IClientSubscribeOptions): MqttClient;
234
182
  unsubscribe(topic: string | string[], callback?: PacketCallback): MqttClient;
235
183
  unsubscribe(topic: string | string[], opts?: IClientSubscribeOptions, callback?: PacketCallback): MqttClient;
184
+ unsubscribeAsync(topic: string | string[]): Promise<void>;
185
+ unsubscribeAsync(topic: string | string[], opts?: IClientSubscribeOptions): Promise<void>;
236
186
  end(cb?: DoneCallback): MqttClient;
237
187
  end(force?: boolean): MqttClient;
238
188
  end(opts?: Partial<IDisconnectPacket>, cb?: DoneCallback): MqttClient;
239
189
  end(force?: boolean, cb?: DoneCallback): MqttClient;
240
190
  end(force?: boolean, opts?: Partial<IDisconnectPacket>, cb?: DoneCallback): MqttClient;
191
+ endAsync(): Promise<void>;
192
+ endAsync(force?: boolean): Promise<void>;
193
+ endAsync(opts?: Partial<IDisconnectPacket>): Promise<void>;
194
+ endAsync(force?: boolean, opts?: Partial<IDisconnectPacket>): Promise<void>;
241
195
  removeOutgoingMessage(messageId: number): MqttClient;
242
196
  reconnect(opts?: Pick<IClientOptions, 'incomingStore' | 'outgoingStore'>): MqttClient;
243
197
  private _flushVolatile;