mqtt 5.3.6 → 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/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.6",
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/index.js"
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.0.78",
126
+ "worker-timers": "^7.1.4",
127
127
  "ws": "^8.14.2"
128
128
  },
129
129
  "devDependencies": {
@@ -1,5 +1,4 @@
1
- import { clearTimeout as clearT, setTimeout as setT } from 'worker-timers'
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
- this._clearTimeout(this.timer)
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 = this._setTimeout(() => {
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',
@@ -2100,6 +2112,7 @@ export default class MqttClient extends TypedEventEmitter<MqttClientEventCallbac
2100
2112
  this._sendPacket({ cmd: 'pingreq' })
2101
2113
  } else {
2102
2114
  // do a forced cleanup since socket will be in bad shape
2115
+ this.emit('error', new Error('Keepalive timeout'))
2103
2116
  this.log('_checkPing :: calling _cleanUp with force true')
2104
2117
  this._cleanUp(true)
2105
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'