mqtt 5.3.5 → 5.4.0
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 +6 -6
- package/build/lib/PingTimer.d.ts +0 -2
- package/build/lib/PingTimer.js +5 -30
- package/build/lib/PingTimer.js.map +1 -1
- package/build/lib/client.js +10 -0
- package/build/lib/client.js.map +1 -1
- package/build/lib/timers.d.ts +6 -0
- package/build/lib/timers.js +35 -0
- package/build/lib/timers.js.map +1 -0
- package/build/mqtt.d.ts +2 -1
- package/build/mqtt.js +3 -1
- package/build/mqtt.js.map +1 -1
- package/build/tsconfig.build.tsbuildinfo +1 -1
- package/dist/mqtt.esm.js +5 -5
- package/dist/mqtt.js +190 -148
- package/dist/mqtt.min.js +5 -5
- package/package.json +3 -3
- package/src/lib/PingTimer.ts +3 -14
- package/src/lib/client.ts +14 -0
- package/src/lib/timers.ts +15 -0
- package/src/mqtt.ts +2 -0
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.
|
|
4
|
+
"version": "5.4.0",
|
|
5
5
|
"contributors": [
|
|
6
6
|
"Adam Rudd <adamvrr@gmail.com>",
|
|
7
7
|
"Matteo Collina <matteo.collina@gmail.com> (https://github.com/mcollina)",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
".": {
|
|
40
40
|
"browser": {
|
|
41
41
|
"import": "./dist/mqtt.esm.js",
|
|
42
|
-
"default": "./dist/
|
|
42
|
+
"default": "./dist/mqtt.min.js"
|
|
43
43
|
},
|
|
44
44
|
"default": "./build/index.js"
|
|
45
45
|
},
|
|
@@ -123,7 +123,7 @@
|
|
|
123
123
|
"reinterval": "^1.1.0",
|
|
124
124
|
"rfdc": "^1.3.0",
|
|
125
125
|
"split2": "^4.2.0",
|
|
126
|
-
"worker-timers": "^7.
|
|
126
|
+
"worker-timers": "^7.1.4",
|
|
127
127
|
"ws": "^8.14.2"
|
|
128
128
|
},
|
|
129
129
|
"devDependencies": {
|
package/src/lib/PingTimer.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import isBrowser, { isWebWorker } from './is-browser'
|
|
1
|
+
import timers from './timers'
|
|
3
2
|
|
|
4
3
|
export default class PingTimer {
|
|
5
4
|
private keepalive: number
|
|
@@ -8,16 +7,6 @@ export default class PingTimer {
|
|
|
8
7
|
|
|
9
8
|
private checkPing: () => void
|
|
10
9
|
|
|
11
|
-
// dont directly assign globals to class props otherwise this throws in web workers: Uncaught TypeError: Illegal invocation
|
|
12
|
-
// See: https://stackoverflow.com/questions/9677985/uncaught-typeerror-illegal-invocation-in-chrome
|
|
13
|
-
private _setTimeout: typeof setT =
|
|
14
|
-
isBrowser && !isWebWorker
|
|
15
|
-
? setT
|
|
16
|
-
: (func, time) => setTimeout(func, time)
|
|
17
|
-
|
|
18
|
-
private _clearTimeout: typeof clearT =
|
|
19
|
-
isBrowser && !isWebWorker ? clearT : (timer) => clearTimeout(timer)
|
|
20
|
-
|
|
21
10
|
constructor(keepalive: number, checkPing: () => void) {
|
|
22
11
|
this.keepalive = keepalive * 1000
|
|
23
12
|
this.checkPing = checkPing
|
|
@@ -26,14 +15,14 @@ export default class PingTimer {
|
|
|
26
15
|
|
|
27
16
|
clear() {
|
|
28
17
|
if (this.timer) {
|
|
29
|
-
|
|
18
|
+
timers.clear(this.timer)
|
|
30
19
|
this.timer = null
|
|
31
20
|
}
|
|
32
21
|
}
|
|
33
22
|
|
|
34
23
|
reschedule() {
|
|
35
24
|
this.clear()
|
|
36
|
-
this.timer =
|
|
25
|
+
this.timer = timers.set(() => {
|
|
37
26
|
this.checkPing()
|
|
38
27
|
// prevent possible race condition where the timer is destroyed on _cleauUp
|
|
39
28
|
// and recreated here
|
package/src/lib/client.ts
CHANGED
|
@@ -38,6 +38,7 @@ import {
|
|
|
38
38
|
import TopicAliasSend from './topic-alias-send'
|
|
39
39
|
import { TypedEventEmitter } from './TypedEmitter'
|
|
40
40
|
import PingTimer from './PingTimer'
|
|
41
|
+
import isBrowser, { isWebWorker } from './is-browser'
|
|
41
42
|
|
|
42
43
|
const setImmediate =
|
|
43
44
|
globalThis.setImmediate ||
|
|
@@ -488,6 +489,17 @@ export default class MqttClient extends TypedEventEmitter<MqttClientEventCallbac
|
|
|
488
489
|
this.log = this.options.log || _debug('mqttjs:client')
|
|
489
490
|
this.noop = this._noop.bind(this)
|
|
490
491
|
|
|
492
|
+
this.log('MqttClient :: version:', process.env.npm_package_version)
|
|
493
|
+
|
|
494
|
+
if (isWebWorker) {
|
|
495
|
+
this.log('MqttClient :: environment', 'webworker')
|
|
496
|
+
} else {
|
|
497
|
+
this.log(
|
|
498
|
+
'MqttClient :: environment',
|
|
499
|
+
isBrowser ? 'browser' : 'node',
|
|
500
|
+
)
|
|
501
|
+
}
|
|
502
|
+
|
|
491
503
|
this.log('MqttClient :: options.protocol', options.protocol)
|
|
492
504
|
this.log(
|
|
493
505
|
'MqttClient :: options.protocolVersion',
|
|
@@ -850,6 +862,7 @@ export default class MqttClient extends TypedEventEmitter<MqttClientEventCallbac
|
|
|
850
862
|
this.log(
|
|
851
863
|
'!!connectTimeout hit!! Calling _cleanUp with force `true`',
|
|
852
864
|
)
|
|
865
|
+
this.emit('error', new Error('connack timeout'))
|
|
853
866
|
this._cleanUp(true)
|
|
854
867
|
}, this.options.connectTimeout)
|
|
855
868
|
|
|
@@ -2099,6 +2112,7 @@ export default class MqttClient extends TypedEventEmitter<MqttClientEventCallbac
|
|
|
2099
2112
|
this._sendPacket({ cmd: 'pingreq' })
|
|
2100
2113
|
} else {
|
|
2101
2114
|
// do a forced cleanup since socket will be in bad shape
|
|
2115
|
+
this.emit('error', new Error('Keepalive timeout'))
|
|
2102
2116
|
this.log('_checkPing :: calling _cleanUp with force true')
|
|
2103
2117
|
this._cleanUp(true)
|
|
2104
2118
|
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import isBrowser, { isWebWorker } from './is-browser'
|
|
2
|
+
import { clearTimeout as clearT, setTimeout as setT } from 'worker-timers'
|
|
3
|
+
|
|
4
|
+
// dont directly assign globals to class props otherwise this throws in web workers: Uncaught TypeError: Illegal invocation
|
|
5
|
+
// See: https://stackoverflow.com/questions/9677985/uncaught-typeerror-illegal-invocation-in-chrome
|
|
6
|
+
|
|
7
|
+
const timers: { set: typeof setT; clear: typeof clearT } = {
|
|
8
|
+
set:
|
|
9
|
+
isBrowser && !isWebWorker
|
|
10
|
+
? setT
|
|
11
|
+
: (func, time) => setTimeout(func, time),
|
|
12
|
+
clear: isBrowser && !isWebWorker ? clearT : (timer) => clearTimeout(timer),
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export default timers
|
package/src/mqtt.ts
CHANGED
|
@@ -9,6 +9,7 @@ import DefaultMessageIdProvider from './lib/default-message-id-provider'
|
|
|
9
9
|
import UniqueMessageIdProvider from './lib/unique-message-id-provider'
|
|
10
10
|
import Store, { IStore } from './lib/store'
|
|
11
11
|
import connect, { connectAsync } from './lib/connect'
|
|
12
|
+
import PingTimer from './lib/PingTimer'
|
|
12
13
|
|
|
13
14
|
export const Client = MqttClient
|
|
14
15
|
export {
|
|
@@ -19,6 +20,7 @@ export {
|
|
|
19
20
|
DefaultMessageIdProvider,
|
|
20
21
|
UniqueMessageIdProvider,
|
|
21
22
|
IStore,
|
|
23
|
+
PingTimer,
|
|
22
24
|
}
|
|
23
25
|
export * from './lib/client'
|
|
24
26
|
export * from './lib/shared'
|