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/README.md CHANGED
@@ -135,8 +135,8 @@ to use MQTT.js in the browser see the [browserify](#browserify) section
135
135
  ### CommonJS (Require)
136
136
 
137
137
  ```js
138
- const mqtt = require("mqtt"); // require mqtt
139
- const client = mqtt.connect("est.mosquitto.org"); // create a client
138
+ const mqtt = require("mqtt") // require mqtt
139
+ const client = mqtt.connect("test.mosquitto.org") // create a client
140
140
  ```
141
141
 
142
142
  ### ES6 Modules (Import)
package/dist/mqtt.js CHANGED
@@ -19,10 +19,11 @@ const validations = require('./validations')
19
19
  const xtend = require('xtend')
20
20
  const debug = require('debug')('mqttjs:client')
21
21
  const nextTick = process ? process.nextTick : function (callback) { setTimeout(callback, 0) }
22
- const setImmediate = global.setImmediate || function (callback) {
23
- // works in node v0.8
24
- nextTick(callback)
22
+ const setImmediate = global.setImmediate || function (...args) {
23
+ const callback = args.shift()
24
+ nextTick(callback.bind(null, ...args))
25
25
  }
26
+
26
27
  const defaultConnectOptions = {
27
28
  keepalive: 60,
28
29
  reschedulePings: true,
@@ -31,7 +32,8 @@ const defaultConnectOptions = {
31
32
  reconnectPeriod: 1000,
32
33
  connectTimeout: 30 * 1000,
33
34
  clean: true,
34
- resubscribe: true
35
+ resubscribe: true,
36
+ writeCache: true
35
37
  }
36
38
 
37
39
  const socketErrors = [
@@ -280,6 +282,11 @@ function MqttClient (streamBuilder, options) {
280
282
 
281
283
  this.options.customHandleAcks = (options.protocolVersion === 5 && options.customHandleAcks) ? options.customHandleAcks : function () { arguments[3](0) }
282
284
 
285
+ // Disable pre-generated write cache if requested. Will allocate buffers on-the-fly instead. WARNING: This can affect write performance
286
+ if (!this.options.writeCache) {
287
+ mqttPacket.writeToStream.cacheNumbers = false
288
+ }
289
+
283
290
  this.streamBuilder = streamBuilder
284
291
 
285
292
  this.messageIdProvider = (typeof this.options.messageIdProvider === 'undefined') ? new DefaultMessageIdProvider() : this.options.messageIdProvider
@@ -743,7 +750,7 @@ MqttClient.prototype.subscribe = function () {
743
750
  debug('subscribe: array topic %s', topic)
744
751
  if (!Object.prototype.hasOwnProperty.call(that._resubscribeTopics, topic) ||
745
752
  that._resubscribeTopics[topic].qos < opts.qos ||
746
- resubscribe) {
753
+ resubscribe) {
747
754
  const currentOpts = {
748
755
  topic: topic,
749
756
  qos: opts.qos
@@ -765,7 +772,7 @@ MqttClient.prototype.subscribe = function () {
765
772
  debug('subscribe: object topic %s', k)
766
773
  if (!Object.prototype.hasOwnProperty.call(that._resubscribeTopics, k) ||
767
774
  that._resubscribeTopics[k].qos < obj[k].qos ||
768
- resubscribe) {
775
+ resubscribe) {
769
776
  const currentOpts = {
770
777
  topic: k,
771
778
  qos: obj[k].qos
@@ -1259,7 +1266,7 @@ MqttClient.prototype._sendPacket = function (packet, cb, cbStorePut, noStore) {
1259
1266
  * anyway it will result in -1 evaluation
1260
1267
  */
1261
1268
  case 0:
1262
- /* falls through */
1269
+ /* falls through */
1263
1270
  default:
1264
1271
  sendPacket(this, packet, cb)
1265
1272
  break
@@ -1618,7 +1625,7 @@ MqttClient.prototype._handleAck = function (packet) {
1618
1625
  debug('_handleAck :: packet type', type)
1619
1626
  switch (type) {
1620
1627
  case 'pubcomp':
1621
- // same thing as puback for QoS 2
1628
+ // same thing as puback for QoS 2
1622
1629
  case 'puback': {
1623
1630
  const pubackRC = packet.reasonCode
1624
1631
  // Callback - we're done
@@ -1664,6 +1671,7 @@ MqttClient.prototype._handleAck = function (packet) {
1664
1671
  }
1665
1672
  }
1666
1673
  }
1674
+ delete this.messageIdToTopic[messageId]
1667
1675
  this._invokeStoreProcessingQueue()
1668
1676
  cb(null, packet)
1669
1677
  break
@@ -1680,7 +1688,7 @@ MqttClient.prototype._handleAck = function (packet) {
1680
1688
  }
1681
1689
 
1682
1690
  if (this.disconnecting &&
1683
- Object.keys(this.outgoing).length === 0) {
1691
+ Object.keys(this.outgoing).length === 0) {
1684
1692
  this.emit('outgoingEmpty')
1685
1693
  }
1686
1694
  }
@@ -1749,8 +1757,8 @@ MqttClient.prototype._resubscribe = function () {
1749
1757
  debug('_resubscribe')
1750
1758
  const _resubscribeTopicsKeys = Object.keys(this._resubscribeTopics)
1751
1759
  if (!this._firstConnection &&
1752
- (this.options.clean || (this.options.protocolVersion === 5 && !this.connackPacket.sessionPresent)) &&
1753
- _resubscribeTopicsKeys.length > 0) {
1760
+ (this.options.clean || (this.options.protocolVersion === 5 && !this.connackPacket.sessionPresent)) &&
1761
+ _resubscribeTopicsKeys.length > 0) {
1754
1762
  if (this.options.resubscribe) {
1755
1763
  if (this.options.protocolVersion === 5) {
1756
1764
  debug('_resubscribe: protocolVersion 5')