mqtt 5.3.2 → 5.3.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.3.2",
4
+ "version": "5.3.4",
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
  }
package/src/lib/client.ts CHANGED
@@ -248,7 +248,7 @@ export interface IClientOptions extends ISecureClientOptions {
248
248
  */
249
249
  clean?: boolean
250
250
  /**
251
- * 10 seconds, set to 0 to disable
251
+ * 60 seconds, set to 0 to disable
252
252
  */
253
253
  keepalive?: number
254
254
  /**
@@ -2260,9 +2260,9 @@ export default class MqttClient extends TypedEventEmitter<MqttClientEventCallbac
2260
2260
  break
2261
2261
  }
2262
2262
  }
2263
+ this.removeListener('close', remove)
2263
2264
  if (allProcessed) {
2264
2265
  clearStoreProcessing()
2265
- this.removeListener('close', remove)
2266
2266
  this._invokeAllStoreProcessingQueue()
2267
2267
  this.emit('connect', packet)
2268
2268
  } else {
@@ -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