mqtt 5.7.2 → 5.8.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.7.2",
4
+ "version": "5.8.0",
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 {
@@ -106,7 +106,10 @@ function connect(
106
106
 
107
107
  if (opts.unixSocket) {
108
108
  opts.protocol = opts.protocol.replace('+unix', '') as MqttProtocol
109
- } else if (!opts.protocol?.startsWith('ws')) {
109
+ } else if (
110
+ !opts.protocol?.startsWith('ws') &&
111
+ !opts.protocol?.startsWith('wx')
112
+ ) {
110
113
  // consider path only with ws protocol or unix socket
111
114
  // url.parse could return path (for example when url ends with a `/`)
112
115
  // that could break the connection. See https://github.com/mqttjs/MQTT.js/pull/1874
@@ -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'