mqtt 5.0.0-beta.1 → 5.0.0-beta.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/lib/client.js CHANGED
@@ -17,10 +17,11 @@ const validations = require('./validations')
17
17
  const xtend = require('xtend')
18
18
  const debug = require('debug')('mqttjs:client')
19
19
  const nextTick = process ? process.nextTick : function (callback) { setTimeout(callback, 0) }
20
- const setImmediate = global.setImmediate || function (callback) {
21
- // works in node v0.8
22
- nextTick(callback)
20
+ const setImmediate = global.setImmediate || function (...args) {
21
+ const callback = args.shift()
22
+ nextTick(callback.bind(null, ...args))
23
23
  }
24
+
24
25
  const defaultConnectOptions = {
25
26
  keepalive: 60,
26
27
  reschedulePings: true,
@@ -29,7 +30,8 @@ const defaultConnectOptions = {
29
30
  reconnectPeriod: 1000,
30
31
  connectTimeout: 30 * 1000,
31
32
  clean: true,
32
- resubscribe: true
33
+ resubscribe: true,
34
+ writeCache: true
33
35
  }
34
36
 
35
37
  const socketErrors = [
@@ -278,6 +280,11 @@ function MqttClient (streamBuilder, options) {
278
280
 
279
281
  this.options.customHandleAcks = (options.protocolVersion === 5 && options.customHandleAcks) ? options.customHandleAcks : function () { arguments[3](0) }
280
282
 
283
+ // Disable pre-generated write cache if requested. Will allocate buffers on-the-fly instead. WARNING: This can affect write performance
284
+ if (!this.options.writeCache) {
285
+ mqttPacket.writeToStream.cacheNumbers = false
286
+ }
287
+
281
288
  this.streamBuilder = streamBuilder
282
289
 
283
290
  this.messageIdProvider = (typeof this.options.messageIdProvider === 'undefined') ? new DefaultMessageIdProvider() : this.options.messageIdProvider
@@ -741,7 +748,7 @@ MqttClient.prototype.subscribe = function () {
741
748
  debug('subscribe: array topic %s', topic)
742
749
  if (!Object.prototype.hasOwnProperty.call(that._resubscribeTopics, topic) ||
743
750
  that._resubscribeTopics[topic].qos < opts.qos ||
744
- resubscribe) {
751
+ resubscribe) {
745
752
  const currentOpts = {
746
753
  topic: topic,
747
754
  qos: opts.qos
@@ -763,7 +770,7 @@ MqttClient.prototype.subscribe = function () {
763
770
  debug('subscribe: object topic %s', k)
764
771
  if (!Object.prototype.hasOwnProperty.call(that._resubscribeTopics, k) ||
765
772
  that._resubscribeTopics[k].qos < obj[k].qos ||
766
- resubscribe) {
773
+ resubscribe) {
767
774
  const currentOpts = {
768
775
  topic: k,
769
776
  qos: obj[k].qos
@@ -1257,7 +1264,7 @@ MqttClient.prototype._sendPacket = function (packet, cb, cbStorePut, noStore) {
1257
1264
  * anyway it will result in -1 evaluation
1258
1265
  */
1259
1266
  case 0:
1260
- /* falls through */
1267
+ /* falls through */
1261
1268
  default:
1262
1269
  sendPacket(this, packet, cb)
1263
1270
  break
@@ -1616,7 +1623,7 @@ MqttClient.prototype._handleAck = function (packet) {
1616
1623
  debug('_handleAck :: packet type', type)
1617
1624
  switch (type) {
1618
1625
  case 'pubcomp':
1619
- // same thing as puback for QoS 2
1626
+ // same thing as puback for QoS 2
1620
1627
  case 'puback': {
1621
1628
  const pubackRC = packet.reasonCode
1622
1629
  // Callback - we're done
@@ -1662,6 +1669,7 @@ MqttClient.prototype._handleAck = function (packet) {
1662
1669
  }
1663
1670
  }
1664
1671
  }
1672
+ delete this.messageIdToTopic[messageId]
1665
1673
  this._invokeStoreProcessingQueue()
1666
1674
  cb(null, packet)
1667
1675
  break
@@ -1678,7 +1686,7 @@ MqttClient.prototype._handleAck = function (packet) {
1678
1686
  }
1679
1687
 
1680
1688
  if (this.disconnecting &&
1681
- Object.keys(this.outgoing).length === 0) {
1689
+ Object.keys(this.outgoing).length === 0) {
1682
1690
  this.emit('outgoingEmpty')
1683
1691
  }
1684
1692
  }
@@ -1747,8 +1755,8 @@ MqttClient.prototype._resubscribe = function () {
1747
1755
  debug('_resubscribe')
1748
1756
  const _resubscribeTopicsKeys = Object.keys(this._resubscribeTopics)
1749
1757
  if (!this._firstConnection &&
1750
- (this.options.clean || (this.options.protocolVersion === 5 && !this.connackPacket.sessionPresent)) &&
1751
- _resubscribeTopicsKeys.length > 0) {
1758
+ (this.options.clean || (this.options.protocolVersion === 5 && !this.connackPacket.sessionPresent)) &&
1759
+ _resubscribeTopicsKeys.length > 0) {
1752
1760
  if (this.options.resubscribe) {
1753
1761
  if (this.options.protocolVersion === 5) {
1754
1762
  debug('_resubscribe: protocolVersion 5')
package/package.json CHANGED
@@ -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.1",
4
+ "version": "5.0.0-beta.2",
5
5
  "contributors": [
6
6
  "Adam Rudd <adamvrr@gmail.com>",
7
7
  "Matteo Collina <matteo.collina@gmail.com> (https://github.com/mcollina)",
@@ -49,9 +49,6 @@
49
49
  "hooks": {
50
50
  "before:init": [
51
51
  "npm run test"
52
- ],
53
- "after:bump": [
54
- "npm run changelog"
55
52
  ]
56
53
  },
57
54
  "npm": {
@@ -126,6 +123,7 @@
126
123
  "mkdirp": "^0.5.1",
127
124
  "mocha": "^9.2.0",
128
125
  "mqtt-connection": "^4.0.0",
126
+ "mqtt-level-store": "^3.1.0",
129
127
  "nyc": "^15.0.1",
130
128
  "pre-commit": "^1.2.2",
131
129
  "release-it": "^15.11.0",
@@ -136,8 +134,7 @@
136
134
  "standard": "^16.0.4",
137
135
  "tape": "^5.5.2",
138
136
  "terser": "^5.14.2",
139
- "typescript": "^4.5.5",
140
- "mqtt-level-store": "^3.1.0"
137
+ "typescript": "^4.5.5"
141
138
  },
142
139
  "standard": {
143
140
  "env": [