mqtt 4.3.6 → 5.0.0-beta.0
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 +13 -12
- package/dist/mqtt.js +18331 -11588
- package/dist/mqtt.min.js +12 -1
- package/lib/client.js +20 -8
- package/lib/connect/index.js +6 -2
- package/lib/connect/ws.js +2 -2
- package/lib/is-browser.js +11 -0
- package/package.json +46 -13
- package/types/lib/client-options.d.ts +5 -1
- package/types/lib/client.d.ts +2 -2
package/lib/client.js
CHANGED
|
@@ -36,10 +36,11 @@ const socketErrors = [
|
|
|
36
36
|
'ECONNREFUSED',
|
|
37
37
|
'EADDRINUSE',
|
|
38
38
|
'ECONNRESET',
|
|
39
|
-
'ENOTFOUND'
|
|
39
|
+
'ENOTFOUND',
|
|
40
|
+
'ETIMEDOUT'
|
|
40
41
|
]
|
|
41
42
|
|
|
42
|
-
// Other Socket Errors: EADDRINUSE, ECONNRESET, ENOTFOUND.
|
|
43
|
+
// Other Socket Errors: EADDRINUSE, ECONNRESET, ENOTFOUND, ETIMEDOUT.
|
|
43
44
|
|
|
44
45
|
const errors = {
|
|
45
46
|
0: '',
|
|
@@ -269,7 +270,7 @@ function MqttClient (streamBuilder, options) {
|
|
|
269
270
|
debug('MqttClient :: options.keepalive', options.keepalive)
|
|
270
271
|
debug('MqttClient :: options.reconnectPeriod', options.reconnectPeriod)
|
|
271
272
|
debug('MqttClient :: options.rejectUnauthorized', options.rejectUnauthorized)
|
|
272
|
-
debug('MqttClient :: options.topicAliasMaximum', options.topicAliasMaximum)
|
|
273
|
+
debug('MqttClient :: options.properties.topicAliasMaximum', options.properties ? options.properties.topicAliasMaximum : undefined)
|
|
273
274
|
|
|
274
275
|
this.options.clientId = (typeof options.clientId === 'string') ? options.clientId : defaultId()
|
|
275
276
|
|
|
@@ -319,11 +320,11 @@ function MqttClient (streamBuilder, options) {
|
|
|
319
320
|
// True if connection is first time.
|
|
320
321
|
this._firstConnection = true
|
|
321
322
|
|
|
322
|
-
if (options.topicAliasMaximum > 0) {
|
|
323
|
-
if (options.topicAliasMaximum > 0xffff) {
|
|
324
|
-
debug('MqttClient :: options.topicAliasMaximum is out of range')
|
|
323
|
+
if (options.properties && options.properties.topicAliasMaximum > 0) {
|
|
324
|
+
if (options.properties.topicAliasMaximum > 0xffff) {
|
|
325
|
+
debug('MqttClient :: options.properties.topicAliasMaximum is out of range')
|
|
325
326
|
} else {
|
|
326
|
-
this.topicAliasRecv = new TopicAliasRecv(options.topicAliasMaximum)
|
|
327
|
+
this.topicAliasRecv = new TopicAliasRecv(options.properties.topicAliasMaximum)
|
|
327
328
|
}
|
|
328
329
|
}
|
|
329
330
|
|
|
@@ -1583,7 +1584,18 @@ MqttClient.prototype._handleAck = function (packet) {
|
|
|
1583
1584
|
const that = this
|
|
1584
1585
|
let err
|
|
1585
1586
|
|
|
1586
|
-
|
|
1587
|
+
// Checking `!cb` happens to work, but it's not technically "correct".
|
|
1588
|
+
//
|
|
1589
|
+
// Why? This code assumes that "no callback" is the same as that "we're not
|
|
1590
|
+
// waiting for responses" (puback, pubrec, pubcomp, suback, or unsuback).
|
|
1591
|
+
//
|
|
1592
|
+
// It would be better to check `if (!this.outgoing[messageId])` here, but
|
|
1593
|
+
// there's no reason to change it and risk (another) regression.
|
|
1594
|
+
//
|
|
1595
|
+
// The only reason this code works is becaues code in MqttClient.publish,
|
|
1596
|
+
// MqttClinet.subscribe, and MqttClient.unsubscribe ensures that we will
|
|
1597
|
+
// have a callback even if the user doesn't pass one in.)
|
|
1598
|
+
if (!cb) {
|
|
1587
1599
|
debug('_handleAck :: Server sent an ack in error. Ignoring.')
|
|
1588
1600
|
// Server sent an ack in error, ignore it.
|
|
1589
1601
|
return
|
package/lib/connect/index.js
CHANGED
|
@@ -2,14 +2,16 @@
|
|
|
2
2
|
|
|
3
3
|
const MqttClient = require('../client')
|
|
4
4
|
const Store = require('../store')
|
|
5
|
+
const DefaultMessageIdProvider = require('../default-message-id-provider')
|
|
6
|
+
const UniqueMessageIdProvider = require('../unique-message-id-provider')
|
|
7
|
+
const IS_BROWSER = require('../is-browser').IS_BROWSER
|
|
5
8
|
const url = require('url')
|
|
6
9
|
const xtend = require('xtend')
|
|
7
10
|
const debug = require('debug')('mqttjs')
|
|
8
11
|
|
|
9
12
|
const protocols = {}
|
|
10
13
|
|
|
11
|
-
|
|
12
|
-
if ((typeof process !== 'undefined' && process.title !== 'browser') || typeof __webpack_require__ !== 'function') {
|
|
14
|
+
if (!IS_BROWSER) {
|
|
13
15
|
protocols.mqtt = require('./tcp')
|
|
14
16
|
protocols.tcp = require('./tcp')
|
|
15
17
|
protocols.ssl = require('./tls')
|
|
@@ -163,3 +165,5 @@ module.exports = connect
|
|
|
163
165
|
module.exports.connect = connect
|
|
164
166
|
module.exports.MqttClient = MqttClient
|
|
165
167
|
module.exports.Store = Store
|
|
168
|
+
module.exports.DefaultMessageIdProvider = DefaultMessageIdProvider
|
|
169
|
+
module.exports.UniqueMessageIdProvider = UniqueMessageIdProvider
|
package/lib/connect/ws.js
CHANGED
|
@@ -5,6 +5,7 @@ const WS = require('ws')
|
|
|
5
5
|
const debug = require('debug')('mqttjs:ws')
|
|
6
6
|
const duplexify = require('duplexify')
|
|
7
7
|
const Transform = require('readable-stream').Transform
|
|
8
|
+
const IS_BROWSER = require('../is-browser').IS_BROWSER
|
|
8
9
|
|
|
9
10
|
const WSS_OPTIONS = [
|
|
10
11
|
'rejectUnauthorized',
|
|
@@ -14,8 +15,7 @@ const WSS_OPTIONS = [
|
|
|
14
15
|
'pfx',
|
|
15
16
|
'passphrase'
|
|
16
17
|
]
|
|
17
|
-
|
|
18
|
-
const IS_BROWSER = (typeof process !== 'undefined' && process.title === 'browser') || typeof __webpack_require__ === 'function'
|
|
18
|
+
|
|
19
19
|
function buildUrl (opts, client) {
|
|
20
20
|
let url = opts.protocol + '://' + opts.hostname + ':' + opts.port + opts.path
|
|
21
21
|
if (typeof (opts.transformWsUrl) === 'function') {
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
const legacyIsBrowser =
|
|
2
|
+
(typeof process !== 'undefined' && process.title === 'browser') ||
|
|
3
|
+
// eslint-disable-next-line camelcase
|
|
4
|
+
typeof __webpack_require__ === 'function'
|
|
5
|
+
|
|
6
|
+
const isBrowser =
|
|
7
|
+
typeof window !== 'undefined' && typeof document !== 'undefined'
|
|
8
|
+
|
|
9
|
+
module.exports = {
|
|
10
|
+
IS_BROWSER: isBrowser || legacyIsBrowser
|
|
11
|
+
}
|
package/package.json
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mqtt",
|
|
3
3
|
"description": "A library for the MQTT protocol",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "5.0.0-beta.0",
|
|
5
5
|
"contributors": [
|
|
6
6
|
"Adam Rudd <adamvrr@gmail.com>",
|
|
7
7
|
"Matteo Collina <matteo.collina@gmail.com> (https://github.com/mcollina)",
|
|
8
8
|
"Siarhei Buntsevich <scarry0506@gmail.com> (https://github.com/scarry1992)",
|
|
9
|
-
"Yoseph Maguire <yomaguir@microsoft.com> (https://github.com/YoDaMa)"
|
|
9
|
+
"Yoseph Maguire <yomaguir@microsoft.com> (https://github.com/YoDaMa)",
|
|
10
|
+
"Daniel Lando <daniel.sorridi@gmail.com> (https://github.com/robertsLando)"
|
|
10
11
|
],
|
|
11
12
|
"keywords": [
|
|
12
13
|
"mqtt",
|
|
@@ -25,14 +26,43 @@
|
|
|
25
26
|
"pretest": "standard | snazzy",
|
|
26
27
|
"typescript-compile-test": "tsc -p test/typescript/tsconfig.json",
|
|
27
28
|
"typescript-compile-execute": "node test/typescript/broker-connect-subscribe-and-publish.js",
|
|
28
|
-
"browser-build": "rimraf dist/ && mkdirp dist/ && browserify mqtt.js --standalone mqtt > dist/mqtt.js &&
|
|
29
|
+
"browser-build": "rimraf dist/ && mkdirp dist/ && browserify mqtt.js --standalone mqtt > dist/mqtt.js && terser dist/mqtt.js --compress --mangle --output dist/mqtt.min.js",
|
|
29
30
|
"prepare": "npm run browser-build",
|
|
30
31
|
"unit-test:node": "node_modules/.bin/nyc --reporter=lcov --reporter=text ./node_modules/mocha/bin/_mocha --exit",
|
|
31
32
|
"unit-test:browser": "airtap --server test/browser/server.js test/browser/test.js",
|
|
32
33
|
"test:node": "npm run unit-test:node && codecov",
|
|
33
34
|
"test:browser": "npm run browser-build && npm run unit-test:browser",
|
|
34
35
|
"test:typescript": "npm run typescript-compile-test && npm run typescript-compile-execute",
|
|
35
|
-
"test": "npm run test:node && npm run test:typescript"
|
|
36
|
+
"test": "npm run test:node && npm run test:typescript",
|
|
37
|
+
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s && git add CHANGELOG.md",
|
|
38
|
+
"changelog-init": "conventional-changelog -p angular -i CHANGELOG.md -s -r 0",
|
|
39
|
+
"release": "read -p 'GITHUB_TOKEN: ' GITHUB_TOKEN && export GITHUB_TOKEN=$GITHUB_TOKEN && release-it"
|
|
40
|
+
},
|
|
41
|
+
"release-it": {
|
|
42
|
+
"github": {
|
|
43
|
+
"release": true
|
|
44
|
+
},
|
|
45
|
+
"git": {
|
|
46
|
+
"tagName": "v${version}",
|
|
47
|
+
"commitMessage": "chore(release): ${version}"
|
|
48
|
+
},
|
|
49
|
+
"hooks": {
|
|
50
|
+
"before:init": [
|
|
51
|
+
"npm run test"
|
|
52
|
+
],
|
|
53
|
+
"after:bump": [
|
|
54
|
+
"npm run changelog"
|
|
55
|
+
]
|
|
56
|
+
},
|
|
57
|
+
"npm": {
|
|
58
|
+
"publish": true
|
|
59
|
+
},
|
|
60
|
+
"plugins": {
|
|
61
|
+
"@release-it/conventional-changelog": {
|
|
62
|
+
"preset": "angular",
|
|
63
|
+
"infile": "CHANGELOG.md"
|
|
64
|
+
}
|
|
65
|
+
}
|
|
36
66
|
},
|
|
37
67
|
"pre-commit": [
|
|
38
68
|
"pretest"
|
|
@@ -52,7 +82,7 @@
|
|
|
52
82
|
"mqtt.js"
|
|
53
83
|
],
|
|
54
84
|
"engines": {
|
|
55
|
-
"node": ">=
|
|
85
|
+
"node": ">=16.0.0"
|
|
56
86
|
},
|
|
57
87
|
"browser": {
|
|
58
88
|
"./mqtt.js": "./lib/connect/index.js",
|
|
@@ -68,11 +98,11 @@
|
|
|
68
98
|
"help-me": "^3.0.0",
|
|
69
99
|
"inherits": "^2.0.3",
|
|
70
100
|
"lru-cache": "^6.0.0",
|
|
71
|
-
"minimist": "^1.2.
|
|
72
|
-
"mqtt-packet": "^
|
|
73
|
-
"number-allocator": "^1.0.
|
|
101
|
+
"minimist": "^1.2.6",
|
|
102
|
+
"mqtt-packet": "^8.1.2",
|
|
103
|
+
"number-allocator": "^1.0.14",
|
|
74
104
|
"pump": "^3.0.0",
|
|
75
|
-
"readable-stream": "^
|
|
105
|
+
"readable-stream": "^4.1.0",
|
|
76
106
|
"reinterval": "^1.1.0",
|
|
77
107
|
"rfdc": "^1.3.0",
|
|
78
108
|
"split2": "^3.1.0",
|
|
@@ -80,15 +110,17 @@
|
|
|
80
110
|
"xtend": "^4.0.2"
|
|
81
111
|
},
|
|
82
112
|
"devDependencies": {
|
|
83
|
-
"@
|
|
113
|
+
"@release-it/conventional-changelog": "^5.1.1",
|
|
114
|
+
"@types/node": "^12.20.55",
|
|
84
115
|
"@types/tape": "^4.13.2",
|
|
85
116
|
"@types/ws": "^7.4.7",
|
|
86
117
|
"aedes": "^0.46.2",
|
|
87
118
|
"airtap": "^4.0.4",
|
|
88
|
-
"browserify": "^
|
|
119
|
+
"browserify": "^17.0.0",
|
|
89
120
|
"chai": "^4.2.0",
|
|
90
121
|
"chokidar": "^3.5.3",
|
|
91
122
|
"codecov": "^3.0.4",
|
|
123
|
+
"conventional-changelog-cli": "^3.0.0",
|
|
92
124
|
"end-of-stream": "^1.4.1",
|
|
93
125
|
"global": "^4.3.2",
|
|
94
126
|
"mkdirp": "^0.5.1",
|
|
@@ -96,14 +128,15 @@
|
|
|
96
128
|
"mqtt-connection": "^4.0.0",
|
|
97
129
|
"nyc": "^15.0.1",
|
|
98
130
|
"pre-commit": "^1.2.2",
|
|
131
|
+
"release-it": "^15.11.0",
|
|
99
132
|
"rimraf": "^3.0.2",
|
|
100
133
|
"should": "^13.2.1",
|
|
101
134
|
"sinon": "^9.0.0",
|
|
102
135
|
"snazzy": "^9.0.0",
|
|
103
136
|
"standard": "^16.0.4",
|
|
104
137
|
"tape": "^5.5.2",
|
|
105
|
-
"
|
|
106
|
-
"
|
|
138
|
+
"terser": "^5.14.2",
|
|
139
|
+
"typescript": "^4.5.5"
|
|
107
140
|
},
|
|
108
141
|
"standard": {
|
|
109
142
|
"env": [
|
|
@@ -50,7 +50,7 @@ export interface IClientOptions extends ISecureClientOptions {
|
|
|
50
50
|
/**
|
|
51
51
|
* the password required by your broker, if any
|
|
52
52
|
*/
|
|
53
|
-
password?: string
|
|
53
|
+
password?: Buffer | string
|
|
54
54
|
/**
|
|
55
55
|
* a Store for the incoming packets
|
|
56
56
|
*/
|
|
@@ -60,6 +60,10 @@ export interface IClientOptions extends ISecureClientOptions {
|
|
|
60
60
|
*/
|
|
61
61
|
outgoingStore?: Store
|
|
62
62
|
queueQoSZero?: boolean
|
|
63
|
+
|
|
64
|
+
autoUseTopicAlias?: boolean
|
|
65
|
+
autoAssignTopicAlias?: boolean
|
|
66
|
+
|
|
63
67
|
reschedulePings?: boolean
|
|
64
68
|
servers?: Array<{
|
|
65
69
|
host: string
|
package/types/lib/client.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
IClientReconnectOptions
|
|
9
9
|
} from './client-options'
|
|
10
10
|
import { Store } from './store'
|
|
11
|
-
import { IAuthPacket,
|
|
11
|
+
import { IAuthPacket, IPublishPacket, IDisconnectPacket, IConnackPacket, Packet, QoS } from 'mqtt-packet'
|
|
12
12
|
|
|
13
13
|
export interface ISubscriptionGrant {
|
|
14
14
|
/**
|
|
@@ -68,7 +68,7 @@ export interface ISubscriptionMap {
|
|
|
68
68
|
|
|
69
69
|
export declare type OnConnectCallback = (packet: IConnackPacket) => void
|
|
70
70
|
export declare type OnDisconnectCallback = (packet: IDisconnectPacket) => void
|
|
71
|
-
export declare type ClientSubscribeCallback = (err: Error, granted: ISubscriptionGrant[]) => void
|
|
71
|
+
export declare type ClientSubscribeCallback = (err: Error | null, granted: ISubscriptionGrant[]) => void
|
|
72
72
|
export declare type OnMessageCallback = (topic: string, payload: Buffer, packet: IPublishPacket) => void
|
|
73
73
|
export declare type OnPacketCallback = (packet: Packet) => void
|
|
74
74
|
export declare type OnCloseCallback = () => void
|