mqtt 5.5.2 → 5.5.4

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/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.5.2",
4
+ "version": "5.5.4",
5
5
  "contributors": [
6
6
  "Adam Rudd <adamvrr@gmail.com>",
7
7
  "Matteo Collina <matteo.collina@gmail.com> (https://github.com/mcollina)",
@@ -10,6 +10,8 @@ export default class PingTimer {
10
10
 
11
11
  private checkPing: () => void
12
12
 
13
+ private destroyed = false
14
+
13
15
  constructor(
14
16
  keepalive: number,
15
17
  checkPing: () => void,
@@ -21,22 +23,34 @@ export default class PingTimer {
21
23
  this.reschedule()
22
24
  }
23
25
 
24
- clear() {
26
+ private clear() {
25
27
  if (this.timerId) {
26
28
  this.timer.clear(this.timerId)
27
29
  this.timerId = null
28
30
  }
29
31
  }
30
32
 
33
+ destroy() {
34
+ this.clear()
35
+ this.destroyed = true
36
+ }
37
+
31
38
  reschedule() {
39
+ if (this.destroyed) {
40
+ return
41
+ }
42
+
32
43
  this.clear()
33
44
  this.timerId = this.timer.set(() => {
34
- this.checkPing()
35
- // prevent possible race condition where the timer is destroyed on _cleauUp
36
- // and recreated here
37
- if (this.timerId) {
38
- this.reschedule()
45
+ // this should never happen, but just in case
46
+ if (this.destroyed) {
47
+ return
39
48
  }
49
+
50
+ this.checkPing()
51
+ // this must be called after `checkPing` otherwise in case `destroy`
52
+ // is called in `checkPing` the timer would be rescheduled anyway
53
+ this.reschedule()
40
54
  }, this.keepalive)
41
55
  }
42
56
  }
package/src/lib/client.ts CHANGED
@@ -31,6 +31,7 @@ import {
31
31
  ErrorWithReasonCode,
32
32
  GenericCallback,
33
33
  IStream,
34
+ MQTTJS_VERSION,
34
35
  StreamBuilder,
35
36
  TimerVariant,
36
37
  VoidCallback,
@@ -396,7 +397,7 @@ export interface MqttClientEventCallbacks {
396
397
  * (see Connection#connect)
397
398
  */
398
399
  export default class MqttClient extends TypedEventEmitter<MqttClientEventCallbacks> {
399
- public static VERSION = process.env.npm_package_version
400
+ public static VERSION = MQTTJS_VERSION
400
401
 
401
402
  /** Public fields */
402
403
 
@@ -658,9 +659,9 @@ export default class MqttClient extends TypedEventEmitter<MqttClientEventCallbac
658
659
  this.log('close :: clearing connackTimer')
659
660
  clearTimeout(this.connackTimer)
660
661
 
661
- this.log('close :: clearing ping timer')
662
+ this.log('close :: destroy ping timer')
662
663
  if (this.pingTimer) {
663
- this.pingTimer.clear()
664
+ this.pingTimer.destroy()
664
665
  this.pingTimer = null
665
666
  }
666
667
 
@@ -1782,8 +1783,8 @@ export default class MqttClient extends TypedEventEmitter<MqttClientEventCallbac
1782
1783
  }
1783
1784
 
1784
1785
  if (this.pingTimer) {
1785
- this.log('_cleanUp :: clearing pingTimer')
1786
- this.pingTimer.clear()
1786
+ this.log('_cleanUp :: destroy pingTimer')
1787
+ this.pingTimer.destroy()
1787
1788
  this.pingTimer = null
1788
1789
  }
1789
1790
 
@@ -9,6 +9,11 @@ import MqttClient, {
9
9
  import IS_BROWSER from '../is-browser'
10
10
  import { StreamBuilder } from '../shared'
11
11
 
12
+ // Handling the process.nextTick is not a function error in react-native applications.
13
+ if (typeof process?.nextTick !== 'function') {
14
+ process.nextTick = setImmediate
15
+ }
16
+
12
17
  const debug = _debug('mqttjs')
13
18
 
14
19
  const protocols: Record<string, StreamBuilder> = {}
@@ -13,11 +13,11 @@ const buildStream: StreamBuilder = (client, opts) => {
13
13
  opts.port = opts.port || 1883
14
14
  opts.hostname = opts.hostname || opts.host || 'localhost'
15
15
 
16
- const { port } = opts
16
+ const { port, path } = opts
17
17
  const host = opts.hostname
18
18
 
19
19
  debug('port %d and host %s', port, host)
20
- return net.createConnection(port, host)
20
+ return net.createConnection({ port, host, path })
21
21
  }
22
22
 
23
23
  export default buildStream
package/src/lib/shared.ts CHANGED
@@ -82,3 +82,6 @@ export const nextTick =
82
82
  : (callback: () => void) => {
83
83
  setTimeout(callback, 0)
84
84
  }
85
+
86
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
87
+ export const MQTTJS_VERSION = require('../../package.json').version