mqtt 5.8.1 → 5.9.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/README.md +8 -7
- package/build/lib/client.d.ts +1 -0
- package/build/lib/client.js.map +1 -1
- package/build/lib/connect/index.d.ts +1 -0
- package/build/lib/connect/index.js +21 -16
- package/build/lib/connect/index.js.map +1 -1
- package/build/lib/connect/ws.d.ts +3 -2
- package/build/lib/connect/ws.js +4 -2
- package/build/lib/connect/ws.js.map +1 -1
- package/build/lib/is-browser.js +1 -5
- package/build/lib/is-browser.js.map +1 -1
- package/build/tsconfig.build.tsbuildinfo +1 -1
- package/dist/mqtt.esm.js +5 -5
- package/dist/mqtt.js +547 -550
- package/dist/mqtt.min.js +5 -5
- package/package.json +1 -1
- package/src/lib/client.ts +4 -0
- package/src/lib/connect/index.ts +31 -19
- package/src/lib/connect/ws.ts +3 -3
- package/src/lib/is-browser.ts +1 -7
package/package.json
CHANGED
package/src/lib/client.ts
CHANGED
|
@@ -282,6 +282,10 @@ export interface IClientOptions extends ISecureClientOptions {
|
|
|
282
282
|
* or pass a custom timer object
|
|
283
283
|
*/
|
|
284
284
|
timerVariant?: TimerVariant | Timer
|
|
285
|
+
/**
|
|
286
|
+
* false, set to true to force the use of native WebSocket if you're having issues with the detection
|
|
287
|
+
*/
|
|
288
|
+
forceNativeWebSocket?: boolean
|
|
285
289
|
}
|
|
286
290
|
|
|
287
291
|
export interface IClientPublishOptions {
|
package/src/lib/connect/index.ts
CHANGED
|
@@ -6,7 +6,7 @@ import MqttClient, {
|
|
|
6
6
|
MqttClientEventCallbacks,
|
|
7
7
|
MqttProtocol,
|
|
8
8
|
} from '../client'
|
|
9
|
-
import
|
|
9
|
+
import isBrowser from '../is-browser'
|
|
10
10
|
import { StreamBuilder } from '../shared'
|
|
11
11
|
|
|
12
12
|
// Handling the process.nextTick is not a function error in react-native applications.
|
|
@@ -16,24 +16,7 @@ if (typeof process?.nextTick !== 'function') {
|
|
|
16
16
|
|
|
17
17
|
const debug = _debug('mqttjs')
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
if (!IS_BROWSER) {
|
|
22
|
-
protocols.mqtt = require('./tcp').default
|
|
23
|
-
protocols.tcp = require('./tcp').default
|
|
24
|
-
protocols.ssl = require('./tls').default
|
|
25
|
-
protocols.tls = protocols.ssl
|
|
26
|
-
protocols.mqtts = require('./tls').default
|
|
27
|
-
} else {
|
|
28
|
-
protocols.wx = require('./wx').default
|
|
29
|
-
protocols.wxs = require('./wx').default
|
|
30
|
-
|
|
31
|
-
protocols.ali = require('./ali').default
|
|
32
|
-
protocols.alis = require('./ali').default
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
protocols.ws = require('./ws').default
|
|
36
|
-
protocols.wss = require('./ws').default
|
|
19
|
+
let protocols: Record<string, StreamBuilder> = null
|
|
37
20
|
|
|
38
21
|
/**
|
|
39
22
|
* Parse the auth attribute and merge username and password in the options object.
|
|
@@ -152,6 +135,30 @@ function connect(
|
|
|
152
135
|
}
|
|
153
136
|
}
|
|
154
137
|
|
|
138
|
+
// only loads the protocols once
|
|
139
|
+
if (!protocols) {
|
|
140
|
+
protocols = {}
|
|
141
|
+
if (!isBrowser && !opts.forceNativeWebSocket) {
|
|
142
|
+
protocols.ws = require('./ws').streamBuilder
|
|
143
|
+
protocols.wss = require('./ws').streamBuilder
|
|
144
|
+
|
|
145
|
+
protocols.mqtt = require('./tcp').default
|
|
146
|
+
protocols.tcp = require('./tcp').default
|
|
147
|
+
protocols.ssl = require('./tls').default
|
|
148
|
+
protocols.tls = protocols.ssl
|
|
149
|
+
protocols.mqtts = require('./tls').default
|
|
150
|
+
} else {
|
|
151
|
+
protocols.ws = require('./ws').browserStreamBuilder
|
|
152
|
+
protocols.wss = require('./ws').browserStreamBuilder
|
|
153
|
+
|
|
154
|
+
protocols.wx = require('./wx').default
|
|
155
|
+
protocols.wxs = require('./wx').default
|
|
156
|
+
|
|
157
|
+
protocols.ali = require('./ali').default
|
|
158
|
+
protocols.alis = require('./ali').default
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
155
162
|
if (!protocols[opts.protocol]) {
|
|
156
163
|
const isSecure = ['mqtts', 'wss'].indexOf(opts.protocol) !== -1
|
|
157
164
|
// returns the first available protocol based on available protocols (that depends on environment)
|
|
@@ -219,6 +226,11 @@ function connectAsync(
|
|
|
219
226
|
brokerUrl: string,
|
|
220
227
|
opts?: IClientOptions,
|
|
221
228
|
): Promise<MqttClient>
|
|
229
|
+
function connectAsync(
|
|
230
|
+
brokerUrl: string,
|
|
231
|
+
opts: IClientOptions,
|
|
232
|
+
allowRetries: boolean,
|
|
233
|
+
): Promise<MqttClient>
|
|
222
234
|
function connectAsync(
|
|
223
235
|
brokerUrl: string | IClientOptions,
|
|
224
236
|
opts?: IClientOptions,
|
package/src/lib/connect/ws.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { Buffer } from 'buffer'
|
|
|
3
3
|
import Ws, { ClientOptions } from 'ws'
|
|
4
4
|
import _debug from 'debug'
|
|
5
5
|
import { DuplexOptions, Transform } from 'readable-stream'
|
|
6
|
-
import
|
|
6
|
+
import isBrowser from '../is-browser'
|
|
7
7
|
import MqttClient, { IClientOptions } from '../client'
|
|
8
8
|
import { BufferedDuplex, writev } from '../BufferedDuplex'
|
|
9
9
|
|
|
@@ -44,7 +44,7 @@ function setDefaultOpts(opts: IClientOptions) {
|
|
|
44
44
|
if (!opts.wsOptions) {
|
|
45
45
|
options.wsOptions = {}
|
|
46
46
|
}
|
|
47
|
-
if (!
|
|
47
|
+
if (!isBrowser && !opts.forceNativeWebSocket && opts.protocol === 'wss') {
|
|
48
48
|
// Add cert/key/ca etc options
|
|
49
49
|
WSS_OPTIONS.forEach((prop) => {
|
|
50
50
|
if (
|
|
@@ -298,4 +298,4 @@ const browserStreamBuilder: StreamBuilder = (client, opts) => {
|
|
|
298
298
|
return stream
|
|
299
299
|
}
|
|
300
300
|
|
|
301
|
-
export
|
|
301
|
+
export { browserStreamBuilder, streamBuilder }
|
package/src/lib/is-browser.ts
CHANGED
|
@@ -25,9 +25,6 @@ const isStandardBrowserEnv = () => {
|
|
|
25
25
|
return false
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
const isTxikijsEnv = () =>
|
|
29
|
-
typeof navigator !== 'undefined' && navigator.userAgent === 'txiki.js'
|
|
30
|
-
|
|
31
28
|
const isWebWorkerEnv = () =>
|
|
32
29
|
Boolean(
|
|
33
30
|
// eslint-disable-next-line no-restricted-globals
|
|
@@ -40,10 +37,7 @@ const isReactNativeEnv = () =>
|
|
|
40
37
|
typeof navigator !== 'undefined' && navigator.product === 'ReactNative'
|
|
41
38
|
|
|
42
39
|
const isBrowser =
|
|
43
|
-
isStandardBrowserEnv() ||
|
|
44
|
-
isWebWorkerEnv() ||
|
|
45
|
-
isReactNativeEnv() ||
|
|
46
|
-
isTxikijsEnv()
|
|
40
|
+
isStandardBrowserEnv() || isWebWorkerEnv() || isReactNativeEnv()
|
|
47
41
|
|
|
48
42
|
export const isWebWorker = isWebWorkerEnv()
|
|
49
43
|
|