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/README.md +8 -0
- package/build/lib/PingTimer.d.ts +3 -1
- package/build/lib/PingTimer.js +12 -3
- package/build/lib/PingTimer.js.map +1 -1
- package/build/lib/client.d.ts +1 -1
- package/build/lib/client.js +5 -5
- package/build/lib/client.js.map +1 -1
- package/build/lib/connect/index.js +3 -0
- package/build/lib/connect/index.js.map +1 -1
- package/build/lib/connect/tcp.js +2 -2
- package/build/lib/connect/tcp.js.map +1 -1
- package/build/lib/shared.d.ts +1 -0
- package/build/lib/shared.js +2 -1
- package/build/lib/shared.js.map +1 -1
- package/build/tsconfig.build.tsbuildinfo +1 -1
- package/dist/mqtt.esm.js +5 -5
- package/dist/mqtt.js +35 -15
- package/dist/mqtt.min.js +5 -5
- package/package.json +1 -1
- package/src/lib/PingTimer.ts +20 -6
- package/src/lib/client.ts +6 -5
- package/src/lib/connect/index.ts +5 -0
- package/src/lib/connect/tcp.ts +2 -2
- package/src/lib/shared.ts +3 -0
package/package.json
CHANGED
package/src/lib/PingTimer.ts
CHANGED
|
@@ -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
|
|
35
|
-
|
|
36
|
-
|
|
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 =
|
|
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 ::
|
|
662
|
+
this.log('close :: destroy ping timer')
|
|
662
663
|
if (this.pingTimer) {
|
|
663
|
-
this.pingTimer.
|
|
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 ::
|
|
1786
|
-
this.pingTimer.
|
|
1786
|
+
this.log('_cleanUp :: destroy pingTimer')
|
|
1787
|
+
this.pingTimer.destroy()
|
|
1787
1788
|
this.pingTimer = null
|
|
1788
1789
|
}
|
|
1789
1790
|
|
package/src/lib/connect/index.ts
CHANGED
|
@@ -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> = {}
|
package/src/lib/connect/tcp.ts
CHANGED
|
@@ -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
|