mqtt 5.3.2 → 5.3.3
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/build/lib/PingTimer.d.ts +2 -2
- package/build/lib/PingTimer.js +29 -7
- package/build/lib/PingTimer.js.map +1 -1
- package/build/lib/is-browser.d.ts +1 -0
- package/build/lib/is-browser.js +2 -0
- package/build/lib/is-browser.js.map +1 -1
- package/build/tsconfig.build.tsbuildinfo +1 -1
- package/dist/mqtt.esm.js +5 -5
- package/dist/mqtt.js +38 -7
- package/dist/mqtt.min.js +5 -5
- package/package.json +1 -1
- package/src/lib/PingTimer.ts +11 -5
- package/src/lib/is-browser.ts +2 -0
package/package.json
CHANGED
package/src/lib/PingTimer.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { clearTimeout as clearT, setTimeout as setT } from 'worker-timers'
|
|
2
|
-
import isBrowser from './is-browser'
|
|
2
|
+
import isBrowser, { isWebWorker } from './is-browser'
|
|
3
3
|
|
|
4
4
|
export default class PingTimer {
|
|
5
5
|
private keepalive: number
|
|
@@ -8,9 +8,15 @@ export default class PingTimer {
|
|
|
8
8
|
|
|
9
9
|
private checkPing: () => void
|
|
10
10
|
|
|
11
|
-
|
|
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)
|
|
12
17
|
|
|
13
|
-
private
|
|
18
|
+
private _clearTimeout: typeof clearT =
|
|
19
|
+
isBrowser && !isWebWorker ? clearT : (timer) => clearTimeout(timer)
|
|
14
20
|
|
|
15
21
|
constructor(keepalive: number, checkPing: () => void) {
|
|
16
22
|
this.keepalive = keepalive * 1000
|
|
@@ -19,7 +25,7 @@ export default class PingTimer {
|
|
|
19
25
|
}
|
|
20
26
|
|
|
21
27
|
private setup() {
|
|
22
|
-
this.timer = this.
|
|
28
|
+
this.timer = this._setTimeout(() => {
|
|
23
29
|
this.checkPing()
|
|
24
30
|
this.reschedule()
|
|
25
31
|
}, this.keepalive)
|
|
@@ -27,7 +33,7 @@ export default class PingTimer {
|
|
|
27
33
|
|
|
28
34
|
clear() {
|
|
29
35
|
if (this.timer) {
|
|
30
|
-
this.
|
|
36
|
+
this._clearTimeout(this.timer)
|
|
31
37
|
this.timer = null
|
|
32
38
|
}
|
|
33
39
|
}
|