mqtt 5.7.3 → 5.8.1

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.7.3",
4
+ "version": "5.8.1",
5
5
  "contributors": [
6
6
  "Adam Rudd <adamvrr@gmail.com>",
7
7
  "Matteo Collina <matteo.collina@gmail.com> (https://github.com/mcollina)",
@@ -33,9 +33,14 @@ export default class KeepaliveManager {
33
33
  return this._keepalive
34
34
  }
35
35
 
36
- constructor(client: MqttClient, variant: TimerVariant) {
36
+ constructor(client: MqttClient, variant: TimerVariant | Timer) {
37
37
  this.client = client
38
- this.timer = getTimer(variant)
38
+ this.timer =
39
+ typeof variant === 'object' &&
40
+ 'set' in variant &&
41
+ 'clear' in variant
42
+ ? variant
43
+ : getTimer(variant)
39
44
  this.setKeepalive(client.options.keepalive)
40
45
  }
41
46
 
package/src/lib/client.ts CHANGED
@@ -41,6 +41,7 @@ import TopicAliasSend from './topic-alias-send'
41
41
  import { TypedEventEmitter } from './TypedEmitter'
42
42
  import KeepaliveManager from './KeepaliveManager'
43
43
  import isBrowser, { isWebWorker } from './is-browser'
44
+ import { Timer } from './get-timer'
44
45
 
45
46
  const setImmediate =
46
47
  globalThis.setImmediate ||
@@ -278,8 +279,9 @@ export interface IClientOptions extends ISecureClientOptions {
278
279
  properties?: IConnectPacket['properties']
279
280
  /**
280
281
  * @description 'auto', set to 'native' or 'worker' if you're having issues with 'auto' detection
282
+ * or pass a custom timer object
281
283
  */
282
- timerVariant?: TimerVariant
284
+ timerVariant?: TimerVariant | Timer
283
285
  }
284
286
 
285
287
  export interface IClientPublishOptions {
@@ -730,6 +732,13 @@ export default class MqttClient extends TypedEventEmitter<MqttClientEventCallbac
730
732
  this.log('connect :: calling method to clear reconnect')
731
733
  this._clearReconnect()
732
734
 
735
+ if (this.disconnected && !this.reconnecting) {
736
+ this.incomingStore = this.options.incomingStore || new Store()
737
+ this.outgoingStore = this.options.outgoingStore || new Store()
738
+ this.disconnecting = false
739
+ this.disconnected = false
740
+ }
741
+
733
742
  this.log(
734
743
  'connect :: using streamBuilder provided to client to create stream',
735
744
  )
@@ -1457,6 +1466,11 @@ export default class MqttClient extends TypedEventEmitter<MqttClientEventCallbac
1457
1466
  })
1458
1467
  if (this._deferredReconnect) {
1459
1468
  this._deferredReconnect()
1469
+ } else if (
1470
+ this.options.reconnectPeriod === 0 ||
1471
+ this.options.manualConnect
1472
+ ) {
1473
+ this.disconnecting = false
1460
1474
  }
1461
1475
  }
1462
1476
 
@@ -2095,11 +2109,11 @@ export default class MqttClient extends TypedEventEmitter<MqttClientEventCallbac
2095
2109
  /**
2096
2110
  * Reschedule the ping interval
2097
2111
  */
2098
- public reschedulePing() {
2112
+ public reschedulePing(force = false) {
2099
2113
  if (
2100
2114
  this.keepaliveManager &&
2101
2115
  this.options.keepalive &&
2102
- this.options.reschedulePings
2116
+ (force || this.options.reschedulePings)
2103
2117
  ) {
2104
2118
  this._reschedulePing()
2105
2119
  }
@@ -56,7 +56,7 @@ const handle: PacketHandler = (client, packet, done) => {
56
56
  break
57
57
  case 'pingresp':
58
58
  client.log('_handlePacket :: received pingresp')
59
- client.reschedulePing()
59
+ client.reschedulePing(true)
60
60
  done()
61
61
  break
62
62
  case 'disconnect':
@@ -25,6 +25,9 @@ const isStandardBrowserEnv = () => {
25
25
  return false
26
26
  }
27
27
 
28
+ const isTxikijsEnv = () =>
29
+ typeof navigator !== 'undefined' && navigator.userAgent === 'txiki.js'
30
+
28
31
  const isWebWorkerEnv = () =>
29
32
  Boolean(
30
33
  // eslint-disable-next-line no-restricted-globals
@@ -37,7 +40,10 @@ const isReactNativeEnv = () =>
37
40
  typeof navigator !== 'undefined' && navigator.product === 'ReactNative'
38
41
 
39
42
  const isBrowser =
40
- isStandardBrowserEnv() || isWebWorkerEnv() || isReactNativeEnv()
43
+ isStandardBrowserEnv() ||
44
+ isWebWorkerEnv() ||
45
+ isReactNativeEnv() ||
46
+ isTxikijsEnv()
41
47
 
42
48
  export const isWebWorker = isWebWorkerEnv()
43
49
 
package/src/mqtt.ts CHANGED
@@ -25,3 +25,4 @@ export {
25
25
  export * from './lib/client'
26
26
  export * from './lib/shared'
27
27
  export { ReasonCodes } from './lib/handlers/ack'
28
+ export type { Timer } from './lib/get-timer'