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/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.3.2",
4
+ "version": "5.3.3",
5
5
  "contributors": [
6
6
  "Adam Rudd <adamvrr@gmail.com>",
7
7
  "Matteo Collina <matteo.collina@gmail.com> (https://github.com/mcollina)",
@@ -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
- private setTimeout = isBrowser ? setT : setTimeout
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 clearTimeout = isBrowser ? clearT : clearTimeout
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.setTimeout(() => {
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.clearTimeout(this.timer)
36
+ this._clearTimeout(this.timer)
31
37
  this.timer = null
32
38
  }
33
39
  }
@@ -15,4 +15,6 @@ const isReactNativeEnv = () =>
15
15
  const isBrowser =
16
16
  isStandardBrowserEnv() || isWebWorkerEnv() || isReactNativeEnv()
17
17
 
18
+ export const isWebWorker = isWebWorkerEnv()
19
+
18
20
  export default isBrowser