mqtt 4.3.6 → 4.3.8

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
@@ -32,14 +32,6 @@ const defaultConnectOptions = {
32
32
  resubscribe: true
33
33
  }
34
34
 
35
- const socketErrors = [
36
- 'ECONNREFUSED',
37
- 'EADDRINUSE',
38
- 'ECONNRESET',
39
- 'ENOTFOUND'
40
- ]
41
-
42
- // Other Socket Errors: EADDRINUSE, ECONNRESET, ENOTFOUND.
43
35
 
44
36
  const errors = {
45
37
  0: '',
@@ -454,7 +446,9 @@ MqttClient.prototype._setupStream = function () {
454
446
 
455
447
  function streamErrorHandler (error) {
456
448
  debug('streamErrorHandler :: error', error.message)
457
- if (socketErrors.includes(error.code)) {
449
+ // error.code will only be set on NodeJS env, browse don't allow to detect erros on sockets
450
+ // also emitting errors on browser seems to create issues
451
+ if (error.code) {
458
452
  // handle error
459
453
  debug('streamErrorHandler :: emitting error')
460
454
  that.emit('error', error)
@@ -1583,7 +1577,18 @@ MqttClient.prototype._handleAck = function (packet) {
1583
1577
  const that = this
1584
1578
  let err
1585
1579
 
1586
- if (!cb || cb === nop) {
1580
+ // Checking `!cb` happens to work, but it's not technically "correct".
1581
+ //
1582
+ // Why? This code assumes that "no callback" is the same as that "we're not
1583
+ // waiting for responses" (puback, pubrec, pubcomp, suback, or unsuback).
1584
+ //
1585
+ // It would be better to check `if (!this.outgoing[messageId])` here, but
1586
+ // there's no reason to change it and risk (another) regression.
1587
+ //
1588
+ // The only reason this code works is becaues code in MqttClient.publish,
1589
+ // MqttClinet.subscribe, and MqttClient.unsubscribe ensures that we will
1590
+ // have a callback even if the user doesn't pass one in.)
1591
+ if (!cb) {
1587
1592
  debug('_handleAck :: Server sent an ack in error. Ignoring.')
1588
1593
  // Server sent an ack in error, ignore it.
1589
1594
  return
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": "4.3.6",
4
+ "version": "4.3.8",
5
5
  "contributors": [
6
6
  "Adam Rudd <adamvrr@gmail.com>",
7
7
  "Matteo Collina <matteo.collina@gmail.com> (https://github.com/mcollina)",