mqtt 5.5.5 → 5.5.6

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.5.5",
4
+ "version": "5.5.6",
5
5
  "contributors": [
6
6
  "Adam Rudd <adamvrr@gmail.com>",
7
7
  "Matteo Collina <matteo.collina@gmail.com> (https://github.com/mcollina)",
@@ -2,7 +2,6 @@ import { StreamBuilder } from '../shared'
2
2
 
3
3
  import net from 'net'
4
4
  import _debug from 'debug'
5
- import { Duplex } from 'readable-stream'
6
5
 
7
6
  const debug = _debug('mqttjs:tcp')
8
7
  /*
@@ -28,9 +28,7 @@ function buildUrl(opts: IClientOptions, client: MqttClient) {
28
28
 
29
29
  function setDefaultOpts(opts: IClientOptions) {
30
30
  const options = opts
31
- if (!opts.hostname) {
32
- options.hostname = 'localhost'
33
- }
31
+
34
32
  if (!opts.port) {
35
33
  if (opts.protocol === 'wss') {
36
34
  options.port = 443
@@ -38,6 +36,7 @@ function setDefaultOpts(opts: IClientOptions) {
38
36
  options.port = 80
39
37
  }
40
38
  }
39
+
41
40
  if (!opts.path) {
42
41
  options.path = '/'
43
42
  }
@@ -141,6 +140,9 @@ function createBrowserWebSocket(client: MqttClient, opts: IClientOptions) {
141
140
  const streamBuilder: StreamBuilder = (client, opts) => {
142
141
  debug('streamBuilder')
143
142
  const options = setDefaultOpts(opts)
143
+
144
+ options.hostname = options.hostname || options.host || 'localhost'
145
+
144
146
  const url = buildUrl(options, client)
145
147
  const socket = createWebSocket(client, url, options)
146
148
  const webSocketStream = Ws.createWebSocketStream(
@@ -26,7 +26,7 @@ const handle: PacketHandler = (client, packet, done) => {
26
26
  client.pingResp = Date.now()
27
27
 
28
28
  // do not shift on pingresp otherwise we would skip the pingreq sending
29
- if (packet.cmd !== 'pingresp') {
29
+ if (!['pingresp', 'publish'].includes(packet.cmd)) {
30
30
  client['_shiftPingInterval']()
31
31
  }
32
32
 
@@ -1,5 +1,28 @@
1
- const isStandardBrowserEnv = () =>
2
- typeof window !== 'undefined' && typeof window.document !== 'undefined'
1
+ const isStandardBrowserEnv = () => {
2
+ // window is only defined when it is a browser
3
+ if (typeof window !== 'undefined') {
4
+ // Is the process an electron application
5
+ // check if we are in electron `renderer`
6
+ const electronRenderCheck =
7
+ navigator?.userAgent?.toLowerCase().indexOf(' electron/') > -1
8
+ if (electronRenderCheck && process?.versions) {
9
+ const electronMainCheck = Object.prototype.hasOwnProperty.call(
10
+ process.versions,
11
+ 'electron',
12
+ )
13
+ // Both electron checks are only true if the following webPreferences are set in the main electron BrowserWindow()
14
+ // webPreferences: {
15
+ // sandbox: false,
16
+ // nodeIntegration: true
17
+ // contextIsolation: false
18
+ // }
19
+ return !electronMainCheck
20
+ }
21
+ return typeof window.document !== 'undefined'
22
+ }
23
+ // return false if nothing is detected
24
+ return false
25
+ }
3
26
 
4
27
  const isWebWorkerEnv = () =>
5
28
  Boolean(