mqtt 4.2.6 → 4.3.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.
package/mqtt.js CHANGED
@@ -5,9 +5,11 @@
5
5
  * See LICENSE for more information
6
6
  */
7
7
 
8
- var MqttClient = require('./lib/client')
9
- var connect = require('./lib/connect')
10
- var Store = require('./lib/store')
8
+ const MqttClient = require('./lib/client')
9
+ const connect = require('./lib/connect')
10
+ const Store = require('./lib/store')
11
+ const DefaultMessageIdProvider = require('./lib/default-message-id-provider')
12
+ const UniqueMessageIdProvider = require('./lib/unique-message-id-provider')
11
13
 
12
14
  module.exports.connect = connect
13
15
 
@@ -15,3 +17,5 @@ module.exports.connect = connect
15
17
  module.exports.MqttClient = MqttClient
16
18
  module.exports.Client = MqttClient
17
19
  module.exports.Store = Store
20
+ module.exports.DefaultMessageIdProvider = DefaultMessageIdProvider
21
+ module.exports.UniqueMessageIdProvider = UniqueMessageIdProvider
package/package.json CHANGED
@@ -1,108 +1,122 @@
1
- {
2
- "name": "mqtt",
3
- "description": "A library for the MQTT protocol",
4
- "version": "4.2.6",
5
- "contributors": [
6
- "Adam Rudd <adamvrr@gmail.com>",
7
- "Matteo Collina <matteo.collina@gmail.com> (https://github.com/mcollina)",
8
- "Siarhei Buntsevich <scarry0506@gmail.com> (https://github.com/scarry1992)",
9
- "Yoseph Maguire <yomaguir@microsoft.com> (https://github.com/YoDaMa)"
10
- ],
11
- "keywords": [
12
- "mqtt",
13
- "publish/subscribe",
14
- "publish",
15
- "subscribe"
16
- ],
17
- "license": "MIT",
18
- "repository": {
19
- "type": "git",
20
- "url": "git://github.com/mqttjs/MQTT.js.git"
21
- },
22
- "main": "mqtt.js",
23
- "types": "types/index.d.ts",
24
- "scripts": {
25
- "test": "node_modules/.bin/nyc --reporter=lcov --reporter=text ./node_modules/mocha/bin/_mocha",
26
- "pretest": "standard | snazzy",
27
- "tslint": "tslint types/**/*.d.ts",
28
- "typescript-compile-test": "tsc -p test/typescript/tsconfig.json",
29
- "typescript-compile-execute": "node test/typescript/*.js",
30
- "typescript-test": "npm run typescript-compile-test && npm run typescript-compile-execute",
31
- "browser-build": "rimraf dist/ && mkdirp dist/ && browserify mqtt.js --standalone mqtt > dist/mqtt.js && uglifyjs dist/mqtt.js --compress --mangle --output dist/mqtt.min.js",
32
- "prepare": "npm run browser-build",
33
- "browser-test": "airtap --server test/browser/server.js --local --open test/browser/test.js",
34
- "sauce-test": "airtap --server test/browser/server.js -- test/browser/test.js",
35
- "ci": "npm run tslint && npm run typescript-compile-test && npm run test && codecov"
36
- },
37
- "pre-commit": [
38
- "pretest",
39
- "tslint"
40
- ],
41
- "bin": {
42
- "mqtt_pub": "./bin/pub.js",
43
- "mqtt_sub": "./bin/sub.js",
44
- "mqtt": "./bin/mqtt.js"
45
- },
46
- "files": [
47
- "dist/",
48
- "CONTRIBUTING.md",
49
- "doc",
50
- "lib",
51
- "bin",
52
- "types",
53
- "mqtt.js"
54
- ],
55
- "engines": {
56
- "node": ">=10.0.0"
57
- },
58
- "browser": {
59
- "./mqtt.js": "./lib/connect/index.js",
60
- "fs": false,
61
- "tls": false,
62
- "net": false
63
- },
64
- "dependencies": {
65
- "commist": "^1.0.0",
66
- "concat-stream": "^2.0.0",
67
- "debug": "^4.1.1",
68
- "help-me": "^1.0.1",
69
- "inherits": "^2.0.3",
70
- "minimist": "^1.2.5",
71
- "mqtt-packet": "^6.6.0",
72
- "pump": "^3.0.0",
73
- "readable-stream": "^3.6.0",
74
- "reinterval": "^1.1.0",
75
- "split2": "^3.1.0",
76
- "ws": "^7.3.1",
77
- "xtend": "^4.0.2"
78
- },
79
- "devDependencies": {
80
- "@types/node": "^10.0.0",
81
- "airtap": "^3.0.0",
82
- "browserify": "^16.5.0",
83
- "chai": "^4.2.0",
84
- "codecov": "^3.0.4",
85
- "end-of-stream": "^1.4.1",
86
- "global": "^4.3.2",
87
- "aedes": "^0.42.5",
88
- "mkdirp": "^0.5.1",
89
- "mocha": "^4.1.0",
90
- "mqtt-connection": "^4.0.0",
91
- "nyc": "^15.0.1",
92
- "pre-commit": "^1.2.2",
93
- "rimraf": "^3.0.2",
94
- "should": "^13.2.1",
95
- "sinon": "^9.0.0",
96
- "snazzy": "^8.0.0",
97
- "standard": "^11.0.1",
98
- "tslint": "^5.11.0",
99
- "tslint-config-standard": "^8.0.1",
100
- "typescript": "^3.2.2",
101
- "uglify-es": "^3.3.9"
102
- },
103
- "standard": {
104
- "env": [
105
- "mocha"
106
- ]
107
- }
108
- }
1
+ {
2
+ "name": "mqtt",
3
+ "description": "A library for the MQTT protocol",
4
+ "version": "4.3.1",
5
+ "contributors": [
6
+ "Adam Rudd <adamvrr@gmail.com>",
7
+ "Matteo Collina <matteo.collina@gmail.com> (https://github.com/mcollina)",
8
+ "Siarhei Buntsevich <scarry0506@gmail.com> (https://github.com/scarry1992)",
9
+ "Yoseph Maguire <yomaguir@microsoft.com> (https://github.com/YoDaMa)"
10
+ ],
11
+ "keywords": [
12
+ "mqtt",
13
+ "publish/subscribe",
14
+ "publish",
15
+ "subscribe"
16
+ ],
17
+ "license": "MIT",
18
+ "repository": {
19
+ "type": "git",
20
+ "url": "git://github.com/mqttjs/MQTT.js.git"
21
+ },
22
+ "main": "mqtt.js",
23
+ "types": "types/index.d.ts",
24
+ "scripts": {
25
+ "test": "node_modules/.bin/nyc --reporter=lcov --reporter=text ./node_modules/mocha/bin/_mocha --exit",
26
+ "pretest": "standard | snazzy",
27
+ "tslint": "tslint types/**/*.d.ts",
28
+ "typescript-compile-test": "tsc -p test/typescript/tsconfig.json",
29
+ "typescript-compile-execute": "node test/typescript/*.js",
30
+ "typescript-test": "npm run typescript-compile-test && npm run typescript-compile-execute",
31
+ "browser-build": "rimraf dist/ && mkdirp dist/ && browserify mqtt.js --standalone mqtt > dist/mqtt.js && uglifyjs dist/mqtt.js --compress --mangle --output dist/mqtt.min.js",
32
+ "prepare": "npm run browser-build",
33
+ "browser-test": "airtap --server test/browser/server.js --local --open test/browser/test.js",
34
+ "sauce-test": "airtap --server test/browser/server.js -- test/browser/test.js",
35
+ "ci": "npm run tslint && npm run typescript-compile-test && npm run test && codecov"
36
+ },
37
+ "pre-commit": [
38
+ "pretest",
39
+ "tslint"
40
+ ],
41
+ "bin": {
42
+ "mqtt_pub": "./bin/pub.js",
43
+ "mqtt_sub": "./bin/sub.js",
44
+ "mqtt": "./bin/mqtt.js"
45
+ },
46
+ "files": [
47
+ "dist/",
48
+ "CONTRIBUTING.md",
49
+ "doc",
50
+ "lib",
51
+ "bin",
52
+ "types",
53
+ "mqtt.js"
54
+ ],
55
+ "engines": {
56
+ "node": ">=10.0.0"
57
+ },
58
+ "browser": {
59
+ "./mqtt.js": "./lib/connect/index.js",
60
+ "fs": false,
61
+ "tls": false,
62
+ "net": false
63
+ },
64
+ "dependencies": {
65
+ "collections": "^5.1.12",
66
+ "commist": "^1.0.0",
67
+ "concat-stream": "^2.0.0",
68
+ "debug": "^4.1.1",
69
+ "duplexify": "^4.1.1",
70
+ "help-me": "^3.0.0",
71
+ "inherits": "^2.0.3",
72
+ "minimist": "^1.2.5",
73
+ "mqtt-packet": "^6.8.0",
74
+ "number-allocator": "^1.0.7",
75
+ "pump": "^3.0.0",
76
+ "readable-stream": "^3.6.0",
77
+ "reinterval": "^1.1.0",
78
+ "rfdc": "^1.3.0",
79
+ "split2": "^3.1.0",
80
+ "ws": "^7.5.5",
81
+ "xtend": "^4.0.2"
82
+ },
83
+ "devDependencies": {
84
+ "@types/node": "^10.0.0",
85
+ "@types/ws": "^7.4.7",
86
+ "aedes": "^0.42.5",
87
+ "airtap": "^4.0.4",
88
+ "browserify": "^16.5.0",
89
+ "chai": "^4.2.0",
90
+ "codecov": "^3.0.4",
91
+ "end-of-stream": "^1.4.1",
92
+ "global": "^4.3.2",
93
+ "mkdirp": "^0.5.1",
94
+ "mocha": "^9.1.3",
95
+ "mqtt-connection": "^4.0.0",
96
+ "nyc": "^15.0.1",
97
+ "pre-commit": "^1.2.2",
98
+ "rimraf": "^3.0.2",
99
+ "should": "^13.2.1",
100
+ "sinon": "^9.0.0",
101
+ "snazzy": "^9.0.0",
102
+ "standard": "^16.0.4",
103
+ "tslint": "^5.11.0",
104
+ "tslint-config-standard": "^8.0.1",
105
+ "typescript": "^3.2.2",
106
+ "uglify-es": "^3.3.9"
107
+ },
108
+ "standard": {
109
+ "env": [
110
+ "mocha"
111
+ ],
112
+ "globals": [
113
+ "expect",
114
+ "test",
115
+ "describe",
116
+ "it",
117
+ "beforeEach",
118
+ "beforeAll",
119
+ "afterAll"
120
+ ]
121
+ }
122
+ }
package/types/index.d.ts CHANGED
@@ -23,5 +23,8 @@ export {
23
23
  IPingreqPacket,
24
24
  IPingrespPacket,
25
25
  IDisconnectPacket,
26
- Packet
26
+ Packet,
27
+ UserProperties
27
28
  } from 'mqtt-packet'
29
+ export { IMessageIdProvider } from './lib/message-id-provider'
30
+ export { UniqueMessageIdProvider } from './lib/unique-message-id-provider'
@@ -1,6 +1,9 @@
1
1
  import { MqttClient } from './client'
2
2
  import { Store } from './store'
3
- import { QoS } from 'mqtt-packet'
3
+ import { ClientOptions } from 'ws'
4
+ import { ClientRequestArgs } from 'http'
5
+ import { QoS, UserProperties } from 'mqtt-packet'
6
+ import { IMessageIdProvider } from './message-id-provider'
4
7
 
5
8
  export declare type StorePutCallback = () => void
6
9
 
@@ -11,9 +14,7 @@ export interface IClientOptions extends ISecureClientOptions {
11
14
  path?: string
12
15
  protocol?: 'wss' | 'ws' | 'mqtt' | 'mqtts' | 'tcp' | 'ssl' | 'wx' | 'wxs'
13
16
 
14
- wsOptions?: {
15
- [x: string]: any
16
- }
17
+ wsOptions?: ClientOptions | ClientRequestArgs
17
18
  /**
18
19
  * 10 seconds, set to 0 to disable
19
20
  */
@@ -99,7 +100,7 @@ export interface IClientOptions extends ISecureClientOptions {
99
100
  contentType?: string,
100
101
  responseTopic?: string,
101
102
  correlationData?: Buffer,
102
- userProperties?: Object
103
+ userProperties?: UserProperties
103
104
  }
104
105
  }
105
106
  transformWsUrl?: (url: string, options: IClientOptions, client: MqttClient) => string,
@@ -110,10 +111,11 @@ export interface IClientOptions extends ISecureClientOptions {
110
111
  topicAliasMaximum?: number,
111
112
  requestResponseInformation?: boolean,
112
113
  requestProblemInformation?: boolean,
113
- userProperties?: Object,
114
+ userProperties?: UserProperties,
114
115
  authenticationMethod?: string,
115
116
  authenticationData?: Buffer
116
- }
117
+ },
118
+ messageIdProvider?: IMessageIdProvider
117
119
  }
118
120
  export interface ISecureClientOptions {
119
121
  /**
@@ -129,6 +131,10 @@ export interface ISecureClientOptions {
129
131
  */
130
132
  ca?: string | string[] | Buffer | Buffer[]
131
133
  rejectUnauthorized?: boolean
134
+ /**
135
+ * optional alpn's
136
+ */
137
+ ALPNProtocols?: string[] | Buffer[] | Uint8Array[] | Buffer | Uint8Array
132
138
  }
133
139
  export interface IClientPublishOptions {
134
140
  /**
@@ -147,12 +153,12 @@ export interface IClientPublishOptions {
147
153
  * MQTT 5.0 properties object
148
154
  */
149
155
  properties?: {
150
- payloadFormatIndicator?: number,
156
+ payloadFormatIndicator?: boolean,
151
157
  messageExpiryInterval?: number,
152
- topicAlias?: string,
158
+ topicAlias?: number,
153
159
  responseTopic?: string,
154
160
  correlationData?: Buffer,
155
- userProperties?: Object,
161
+ userProperties?: UserProperties,
156
162
  subscriptionIdentifier?: number,
157
163
  contentType?: string
158
164
  }
@@ -177,7 +183,14 @@ export interface IClientSubscribeOptions {
177
183
  /*
178
184
  * Retain Handling option
179
185
  * */
180
- rh?: number
186
+ rh?: number,
187
+ /*
188
+ * MQTT 5.0 properies object of subscribe
189
+ * */
190
+ properties?: {
191
+ subscriptionIdentifier?: number,
192
+ userProperties?: UserProperties
193
+ }
181
194
  }
182
195
  export interface IClientReconnectOptions {
183
196
  /**
@@ -8,7 +8,7 @@ import {
8
8
  IClientReconnectOptions
9
9
  } from './client-options'
10
10
  import { Store } from './store'
11
- import { Packet, QoS } from 'mqtt-packet'
11
+ import { IAuthPacket, IConnectPacket, IPublishPacket, IDisconnectPacket, IConnackPacket, Packet, QoS } from 'mqtt-packet'
12
12
 
13
13
  export interface ISubscriptionGrant {
14
14
  /**
@@ -66,13 +66,15 @@ export interface ISubscriptionMap {
66
66
  }
67
67
  }
68
68
 
69
- export declare type OnConnectCallback = (packet: Packet) => void
69
+ export declare type OnConnectCallback = (packet: IConnackPacket) => void
70
+ export declare type OnDisconnectCallback = (packet: IDisconnectPacket) => void
70
71
  export declare type ClientSubscribeCallback = (err: Error, granted: ISubscriptionGrant[]) => void
71
- export declare type OnMessageCallback = (topic: string, payload: Buffer, packet: Packet) => void
72
+ export declare type OnMessageCallback = (topic: string, payload: Buffer, packet: IPublishPacket) => void
72
73
  export declare type OnPacketCallback = (packet: Packet) => void
74
+ export declare type OnCloseCallback = () => void
73
75
  export declare type OnErrorCallback = (error: Error) => void
74
76
  export declare type PacketCallback = (error?: Error, packet?: Packet) => any
75
- export declare type CloseCallback = () => void
77
+ export declare type CloseCallback = (error?: Error) => void
76
78
 
77
79
  export interface IStream extends events.EventEmitter {
78
80
  pipe (to: any): any
@@ -101,13 +103,19 @@ export declare class MqttClient extends events.EventEmitter {
101
103
  public on (event: 'connect', cb: OnConnectCallback): this
102
104
  public on (event: 'message', cb: OnMessageCallback): this
103
105
  public on (event: 'packetsend' | 'packetreceive', cb: OnPacketCallback): this
106
+ public on (event: 'disconnect', cb: OnDisconnectCallback): this
104
107
  public on (event: 'error', cb: OnErrorCallback): this
108
+ public on (event: 'close', cb: OnCloseCallback): this
109
+ public on (event: 'end' | 'reconnect' | 'offline' | 'outgoingEmpty', cb: () => void): this
105
110
  public on (event: string, cb: Function): this
106
111
 
107
112
  public once (event: 'connect', cb: OnConnectCallback): this
108
113
  public once (event: 'message', cb: OnMessageCallback): this
109
114
  public once (event: 'packetsend' | 'packetreceive', cb: OnPacketCallback): this
115
+ public once (event: 'disconnect', cb: OnDisconnectCallback): this
110
116
  public once (event: 'error', cb: OnErrorCallback): this
117
+ public once (event: 'close', cb: OnCloseCallback): this
118
+ public once (event: 'end' | 'reconnect' | 'offline' | 'outgoingEmpty', cb: () => void): this
111
119
  public once (event: string, cb: Function): this
112
120
 
113
121
  /**
@@ -224,6 +232,27 @@ export declare class MqttClient extends events.EventEmitter {
224
232
  */
225
233
  public handleMessage (packet: Packet, callback: PacketCallback): void
226
234
 
235
+ /**
236
+ * Handle auth packages for MQTT 5 enhanced authentication methods such
237
+ * as challenge response authentication.
238
+ *
239
+ * Challenge-response authentication flow would look something like this:
240
+ *
241
+ * --> CONNECT | authMethod = "mathChallenge" -->
242
+ * <-- AUTH | authMethod = "mathChallenge", authData = "12 + 34" <--
243
+ * --> AUTH | authMethod = "mathChallenge", authData = "46" -->
244
+ * <-- CONNACK | reasonCode = SUCCESS <--
245
+ *
246
+ * This form of authentication has several advantages over traditional
247
+ * credential-based approaches. For instance authentication without the direct
248
+ * exchange of authentication secrets.
249
+ *
250
+ * @param packet the auth packet to handle
251
+ * @param callback call when finished
252
+ * @api public
253
+ */
254
+ public handleAuth (packet: IAuthPacket, callback: PacketCallback): void
255
+
227
256
  /**
228
257
  * getLastMessageId
229
258
  */
@@ -0,0 +1,49 @@
1
+ import { IMessageIdProvider } from './message-id-provider'
2
+
3
+ /**
4
+ * DefaultMessageIdProvider
5
+ * This is compatible behavior with the original MQTT.js internal messageId allocation.
6
+ */
7
+ declare class DefaultMessageIdProvider implements IMessageIdProvider {
8
+ /**
9
+ * DefaultMessageIdProvider constructor.
10
+ * Randomize initial messageId
11
+ * @constructor
12
+ */
13
+ constructor ()
14
+
15
+ /**
16
+ * Return the current messageId and increment the current messageId.
17
+ * @return {Number} - messageId
18
+ */
19
+ public allocate (): Number | null
20
+
21
+ /**
22
+ * Get the last allocated messageId.
23
+ * @return {Number} - messageId.
24
+ */
25
+ public getLastAllocated (): Number | null
26
+
27
+ /**
28
+ * Register the messageId.
29
+ * This function actually nothing and always return true.
30
+ * @param {Number} num - The messageId to request use.
31
+ * @return {Boolean} - If `num` was not occupied, then return true, otherwise return false.
32
+ */
33
+ public register (num: Number): Boolean
34
+
35
+ /**
36
+ * Deallocate the messageId.
37
+ * This function actually nothing.
38
+ * @param {Number} num - The messageId to deallocate.
39
+ */
40
+ public deallocate (num: Number): void
41
+
42
+ /**
43
+ * Clear all occupied messageIds.
44
+ * This function actually nothing.
45
+ */
46
+ public clear (): void
47
+ }
48
+
49
+ export { DefaultMessageIdProvider }
@@ -0,0 +1,40 @@
1
+ /**
2
+ * MessageIdProvider
3
+ */
4
+ declare interface IMessageIdProvider {
5
+ /**
6
+ * Allocate the first vacant messageId. The messageId become occupied status.
7
+ * @return {Number} - The first vacant messageId. If all messageIds are occupied, return null.
8
+ */
9
+ allocate (): Number | null
10
+
11
+ /**
12
+ * Get the last allocated messageId.
13
+ * @return {Number} - messageId.
14
+ */
15
+ getLastAllocated (): Number | null
16
+
17
+ /**
18
+ * Register the messageId. The messageId become occupied status.
19
+ * If the messageId has already been occupied, then return false.
20
+ * @param {Number} num - The messageId to request use.
21
+ * @return {Boolean} - If `num` was not occupied, then return true, otherwise return false.
22
+ */
23
+ register (num: Number): Boolean
24
+
25
+ /**
26
+ * Deallocate the messageId. The messageId become vacant status.
27
+ * @param {Number} num - The messageId to deallocate. The messageId must be occupied status.
28
+ * In other words, the messageId must be allocated by allocate() or
29
+ * occupied by register().
30
+ */
31
+ deallocate (num: Number): void
32
+
33
+ /**
34
+ * Clear all occupied messageIds.
35
+ * The all messageIds are set to vacant status.
36
+ */
37
+ clear (): void
38
+ }
39
+
40
+ export { IMessageIdProvider }
@@ -0,0 +1,48 @@
1
+ import { IMessageIdProvider } from './message-id-provider'
2
+
3
+ /**
4
+ * UniqueMessageIdProvider
5
+ */
6
+ declare class UniqueMessageIdProvider implements IMessageIdProvider {
7
+ /**
8
+ * UniqueMessageIdProvider constructor.
9
+ * @constructor
10
+ */
11
+ constructor ()
12
+
13
+ /**
14
+ * Allocate the first vacant messageId. The messageId become occupied status.
15
+ * @return {Number} - The first vacant messageId. If all messageIds are occupied, return null.
16
+ */
17
+ public allocate (): Number | null
18
+
19
+ /**
20
+ * Get the last allocated messageId.
21
+ * @return {Number} - messageId.
22
+ */
23
+ public getLastAllocated (): Number | null
24
+
25
+ /**
26
+ * Register the messageId. The messageId become occupied status.
27
+ * If the messageId has already been occupied, then return false.
28
+ * @param {Number} num - The messageId to request use.
29
+ * @return {Boolean} - If `num` was not occupied, then return true, otherwise return false.
30
+ */
31
+ public register (num: Number): Boolean
32
+
33
+ /**
34
+ * Deallocate the messageId. The messageId become vacant status.
35
+ * @param {Number} num - The messageId to deallocate. The messageId must be occupied status.
36
+ * In other words, the messageId must be allocated by allocate() or
37
+ * occupied by register().
38
+ */
39
+ public deallocate (num: Number): void
40
+
41
+ /**
42
+ * Clear all occupied messageIds.
43
+ * The all messageIds are set to vacant status.
44
+ */
45
+ public clear (): void
46
+ }
47
+
48
+ export { UniqueMessageIdProvider }