mqtt 4.3.2 → 4.3.6

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/lib/client.js CHANGED
@@ -175,7 +175,7 @@ function sendPacket (client, packet, cb) {
175
175
  debug('sendPacket :: writing to stream')
176
176
  const result = mqttPacket.writeToStream(packet, client.stream, client.options)
177
177
  debug('sendPacket :: writeToStream result %s', result)
178
- if (!result && cb) {
178
+ if (!result && cb && cb !== nop) {
179
179
  debug('sendPacket :: handle events on `drain` once through callback.')
180
180
  client.stream.once('drain', cb)
181
181
  } else if (cb) {
@@ -190,6 +190,8 @@ function flush (queue) {
190
190
  Object.keys(queue).forEach(function (messageId) {
191
191
  if (typeof queue[messageId].cb === 'function') {
192
192
  queue[messageId].cb(new Error('Connection closed'))
193
+ // This is suspicious. Why do we only delete this if we have a callbck?
194
+ // If this is by-design, then adding no as callback would cause this to get deleted unintentionally.
193
195
  delete queue[messageId]
194
196
  }
195
197
  })
@@ -569,7 +571,7 @@ MqttClient.prototype._handlePacket = function (packet, done) {
569
571
 
570
572
  MqttClient.prototype._checkDisconnecting = function (callback) {
571
573
  if (this.disconnecting) {
572
- if (callback) {
574
+ if (callback && callback !== nop) {
573
575
  callback(new Error('client disconnecting'))
574
576
  } else {
575
577
  this.emit('error', new Error('client disconnecting'))
@@ -660,7 +662,7 @@ MqttClient.prototype.publish = function (topic, message, opts, callback) {
660
662
  return true
661
663
  }
662
664
 
663
- if (this._storeProcessing || this._storeProcessingQueue.length > 0) {
665
+ if (this._storeProcessing || this._storeProcessingQueue.length > 0 || !publishProc()) {
664
666
  this._storeProcessingQueue.push(
665
667
  {
666
668
  invoke: publishProc,
@@ -668,8 +670,6 @@ MqttClient.prototype.publish = function (topic, message, opts, callback) {
668
670
  callback: callback
669
671
  }
670
672
  )
671
- } else {
672
- publishProc()
673
673
  }
674
674
  return this
675
675
  }
@@ -842,15 +842,13 @@ MqttClient.prototype.subscribe = function () {
842
842
  return true
843
843
  }
844
844
 
845
- if (this._storeProcessing || this._storeProcessingQueue.length > 0) {
845
+ if (this._storeProcessing || this._storeProcessingQueue.length > 0 || !subscribeProc()) {
846
846
  this._storeProcessingQueue.push(
847
847
  {
848
848
  invoke: subscribeProc,
849
849
  callback: callback
850
850
  }
851
851
  )
852
- } else {
853
- subscribeProc()
854
852
  }
855
853
 
856
854
  return this
@@ -935,15 +933,13 @@ MqttClient.prototype.unsubscribe = function () {
935
933
  return true
936
934
  }
937
935
 
938
- if (this._storeProcessing || this._storeProcessingQueue.length > 0) {
936
+ if (this._storeProcessing || this._storeProcessingQueue.length > 0 || !unsubscribeProc()) {
939
937
  this._storeProcessingQueue.push(
940
938
  {
941
939
  invoke: unsubscribeProc,
942
940
  callback: callback
943
941
  }
944
942
  )
945
- } else {
946
- unsubscribeProc()
947
943
  }
948
944
 
949
945
  return this
@@ -1587,7 +1583,7 @@ MqttClient.prototype._handleAck = function (packet) {
1587
1583
  const that = this
1588
1584
  let err
1589
1585
 
1590
- if (!cb) {
1586
+ if (!cb || cb === nop) {
1591
1587
  debug('_handleAck :: Server sent an ack in error. Ignoring.')
1592
1588
  // Server sent an ack in error, ignore it.
1593
1589
  return
@@ -1,5 +1,6 @@
1
1
  'use strict'
2
2
 
3
+ const { Buffer } = require('buffer')
3
4
  const Transform = require('readable-stream').Transform
4
5
  const duplexify = require('duplexify')
5
6
 
package/lib/connect/ws.js CHANGED
@@ -1,5 +1,6 @@
1
1
  'use strict'
2
2
 
3
+ const { Buffer } = require('buffer')
3
4
  const WS = require('ws')
4
5
  const debug = require('debug')('mqttjs:ws')
5
6
  const duplexify = require('duplexify')
package/lib/connect/wx.js CHANGED
@@ -1,5 +1,6 @@
1
1
  'use strict'
2
2
 
3
+ const { Buffer } = require('buffer')
3
4
  const Transform = require('readable-stream').Transform
4
5
  const duplexify = require('duplexify')
5
6
 
@@ -3,7 +3,7 @@
3
3
  /**
4
4
  * Module dependencies
5
5
  */
6
- const LruMap = require('collections/lru-map')
6
+ const LruMap = require('lru-cache')
7
7
  const NumberAllocator = require('number-allocator').NumberAllocator
8
8
 
9
9
  /**
@@ -17,7 +17,7 @@ function TopicAliasSend (max) {
17
17
  }
18
18
 
19
19
  if (max > 0) {
20
- this.aliasToTopic = new LruMap()
20
+ this.aliasToTopic = new LruMap({ max: max })
21
21
  this.topicToAlias = {}
22
22
  this.numberAllocator = new NumberAllocator(1, max)
23
23
  this.max = max
@@ -37,9 +37,9 @@ TopicAliasSend.prototype.put = function (topic, alias) {
37
37
  }
38
38
  const entry = this.aliasToTopic.get(alias)
39
39
  if (entry) {
40
- delete this.topicToAlias[entry.topic]
40
+ delete this.topicToAlias[entry]
41
41
  }
42
- this.aliasToTopic.set(alias, { topic: topic, alias: alias })
42
+ this.aliasToTopic.set(alias, topic)
43
43
  this.topicToAlias[topic] = alias
44
44
  this.numberAllocator.use(alias)
45
45
  this.length = this.aliasToTopic.length
@@ -52,9 +52,7 @@ TopicAliasSend.prototype.put = function (topic, alias) {
52
52
  * @returns {String} - if mapped topic exists return topic, otherwise return undefined
53
53
  */
54
54
  TopicAliasSend.prototype.getTopicByAlias = function (alias) {
55
- const entry = this.aliasToTopic.get(alias)
56
- if (typeof entry === 'undefined') return entry
57
- return entry.topic
55
+ return this.aliasToTopic.get(alias)
58
56
  }
59
57
 
60
58
  /**
@@ -74,7 +72,7 @@ TopicAliasSend.prototype.getAliasByTopic = function (topic) {
74
72
  * Clear all entries
75
73
  */
76
74
  TopicAliasSend.prototype.clear = function () {
77
- this.aliasToTopic.clear()
75
+ this.aliasToTopic.reset()
78
76
  this.topicToAlias = {}
79
77
  this.numberAllocator.clear()
80
78
  this.length = 0
@@ -87,7 +85,7 @@ TopicAliasSend.prototype.clear = function () {
87
85
  TopicAliasSend.prototype.getLruAlias = function () {
88
86
  const alias = this.numberAllocator.firstVacant()
89
87
  if (alias) return alias
90
- return this.aliasToTopic.min().alias
88
+ return this.aliasToTopic.keys()[this.aliasToTopic.length - 1]
91
89
  }
92
90
 
93
91
  module.exports = TopicAliasSend
package/package.json CHANGED
@@ -1,122 +1,113 @@
1
- {
2
- "name": "mqtt",
3
- "description": "A library for the MQTT protocol",
4
- "version": "4.3.2",
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.13",
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.8",
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
- }
1
+ {
2
+ "name": "mqtt",
3
+ "description": "A library for the MQTT protocol",
4
+ "version": "4.3.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
+ "pretest": "standard | snazzy",
26
+ "typescript-compile-test": "tsc -p test/typescript/tsconfig.json",
27
+ "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 && uglifyjs dist/mqtt.js --compress --mangle --output dist/mqtt.min.js",
29
+ "prepare": "npm run browser-build",
30
+ "unit-test:node": "node_modules/.bin/nyc --reporter=lcov --reporter=text ./node_modules/mocha/bin/_mocha --exit",
31
+ "unit-test:browser": "airtap --server test/browser/server.js test/browser/test.js",
32
+ "test:node": "npm run unit-test:node && codecov",
33
+ "test:browser": "npm run browser-build && npm run unit-test:browser",
34
+ "test:typescript": "npm run typescript-compile-test && npm run typescript-compile-execute",
35
+ "test": "npm run test:node && npm run test:typescript"
36
+ },
37
+ "pre-commit": [
38
+ "pretest"
39
+ ],
40
+ "bin": {
41
+ "mqtt_pub": "./bin/pub.js",
42
+ "mqtt_sub": "./bin/sub.js",
43
+ "mqtt": "./bin/mqtt.js"
44
+ },
45
+ "files": [
46
+ "dist/",
47
+ "CONTRIBUTING.md",
48
+ "doc",
49
+ "lib",
50
+ "bin",
51
+ "types",
52
+ "mqtt.js"
53
+ ],
54
+ "engines": {
55
+ "node": ">=10.0.0"
56
+ },
57
+ "browser": {
58
+ "./mqtt.js": "./lib/connect/index.js",
59
+ "fs": false,
60
+ "tls": false,
61
+ "net": false
62
+ },
63
+ "dependencies": {
64
+ "commist": "^1.0.0",
65
+ "concat-stream": "^2.0.0",
66
+ "debug": "^4.1.1",
67
+ "duplexify": "^4.1.1",
68
+ "help-me": "^3.0.0",
69
+ "inherits": "^2.0.3",
70
+ "lru-cache": "^6.0.0",
71
+ "minimist": "^1.2.5",
72
+ "mqtt-packet": "^6.8.0",
73
+ "number-allocator": "^1.0.9",
74
+ "pump": "^3.0.0",
75
+ "readable-stream": "^3.6.0",
76
+ "reinterval": "^1.1.0",
77
+ "rfdc": "^1.3.0",
78
+ "split2": "^3.1.0",
79
+ "ws": "^7.5.5",
80
+ "xtend": "^4.0.2"
81
+ },
82
+ "devDependencies": {
83
+ "@types/node": "^10.0.0",
84
+ "@types/tape": "^4.13.2",
85
+ "@types/ws": "^7.4.7",
86
+ "aedes": "^0.46.2",
87
+ "airtap": "^4.0.4",
88
+ "browserify": "^16.5.0",
89
+ "chai": "^4.2.0",
90
+ "chokidar": "^3.5.3",
91
+ "codecov": "^3.0.4",
92
+ "end-of-stream": "^1.4.1",
93
+ "global": "^4.3.2",
94
+ "mkdirp": "^0.5.1",
95
+ "mocha": "^9.2.0",
96
+ "mqtt-connection": "^4.0.0",
97
+ "nyc": "^15.0.1",
98
+ "pre-commit": "^1.2.2",
99
+ "rimraf": "^3.0.2",
100
+ "should": "^13.2.1",
101
+ "sinon": "^9.0.0",
102
+ "snazzy": "^9.0.0",
103
+ "standard": "^16.0.4",
104
+ "tape": "^5.5.2",
105
+ "typescript": "^4.5.5",
106
+ "uglify-es": "^3.3.9"
107
+ },
108
+ "standard": {
109
+ "env": [
110
+ "mocha"
111
+ ]
112
+ }
113
+ }
@@ -1,10 +1,19 @@
1
1
  import { IClientOptions, MqttClient } from '../client'
2
+
2
3
  /**
3
4
  * connect - connect to an MQTT broker.
4
5
  *
5
- * @param {String} [brokerUrl] - url of the broker, optional
6
6
  * @param {Object} opts - see MqttClient#constructor
7
7
  */
8
- declare function connect (brokerUrl?: string | any, opts?: IClientOptions): MqttClient
8
+ declare function connect (opts: IClientOptions): MqttClient
9
+
10
+ /**
11
+ * connect - connect to an MQTT broker.
12
+ *
13
+ * @param {String} brokerUrl - url of the broker
14
+ * @param {Object} opts - see MqttClient#constructor
15
+ */
16
+ declare function connect (brokerUrl: string, opts?: IClientOptions): MqttClient
17
+
9
18
  export { connect }
10
19
  export { MqttClient }
package/CHANGELOG.md DELETED
@@ -1,75 +0,0 @@
1
- # Release History
2
-
3
- ## 4.3.2
4
-
5
- ### PR
6
-
7
- fix(dependencies): update collections (#1386)
8
-
9
- ## 4.3.1
10
-
11
- ### PR
12
-
13
- fix(dependencies): remove babel-eslint and snazzy (#1383)
14
-
15
- ## 4.3.0
16
-
17
- ### PR
18
-
19
- refined topic alias support (#1301)
20
-
21
- fix security vulnerability in ws stream (#1307)
22
-
23
- skip TLS SNI if host is IP address (#1311)
24
-
25
- update readme about vNext discussions (#1328)
26
-
27
- update readme sample (#1331)
28
-
29
- add support for ALPN TLS extension (#1332)
30
-
31
- align onConnectCallback with specs expecting connack packet (#1333)
32
-
33
- fix resubscribe messageId allocate twice (#1337)
34
-
35
- rework examples to be a bit more specific (#1352)
36
-
37
- readme typo fixed (#1353)
38
-
39
- fix(typescript): use correct version of @types/ws (#1358)
40
-
41
- fix(type): fix push properties types (#1359)
42
-
43
- fix: audit dev dependencies (#1374)
44
-
45
- fix(type): add properties type for IClientSubscribeOptions (#1378)
46
-
47
- feat(client): auth handler for enhanced auth (#1380)
48
-
49
- ## 4.2.8
50
-
51
- ### PR
52
-
53
- Fix ws vulnerability and typescript bug (#1292)
54
-
55
- ## 4.2.7
56
-
57
- ### PR
58
-
59
- #1287 - Fix production vulnerabilities (#1289)
60
-
61
- #1215 - Add missing 'duplexify' dependency (#1266)
62
-
63
- Improve type definition for 'wsOptions' (#1256)
64
-
65
- Improve Typescript Declaratiosn for userProperties (#1249)
66
-
67
- #1235 - Call the end on the WebSocket stream when WebSocket close event is emitted. (#1239)
68
-
69
- #1201 - Uncaught TypeError: net.createConnection is not a function. (#1236)
70
-
71
- Improve Documentation for Browserify (#1224)
72
-
73
- ## v4.2.6 and Below
74
-
75
- The release history has beend documented in the GitHub releases and tags historically.