mqtt 5.5.3 → 5.5.5

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/dist/mqtt.js CHANGED
@@ -12634,7 +12634,7 @@ var mqtt = (() => {
12634
12634
  // package-json:../../package.json
12635
12635
  var require_package = __commonJS({
12636
12636
  "package-json:../../package.json"(exports5, module) {
12637
- module.exports = { version: "5.5.3" };
12637
+ module.exports = { version: "5.5.5" };
12638
12638
  }
12639
12639
  });
12640
12640
 
@@ -17191,6 +17191,10 @@ var mqtt = (() => {
17191
17191
  });
17192
17192
  return client;
17193
17193
  }
17194
+ client.pingResp = Date.now();
17195
+ if (packet.cmd !== "pingresp") {
17196
+ client["_shiftPingInterval"]();
17197
+ }
17194
17198
  client.log("_handlePacket :: emitting packetreceive");
17195
17199
  client.emit("packetreceive", packet);
17196
17200
  switch (packet.cmd) {
@@ -17217,7 +17221,6 @@ var mqtt = (() => {
17217
17221
  done();
17218
17222
  break;
17219
17223
  case "pingresp":
17220
- client.pingResp = true;
17221
17224
  done();
17222
17225
  break;
17223
17226
  case "disconnect":
@@ -17719,7 +17722,7 @@ var mqtt = (() => {
17719
17722
  var TypedEmitter_1 = require_TypedEmitter();
17720
17723
  var PingTimer_1 = __importDefault(require_PingTimer());
17721
17724
  var is_browser_1 = __importStar(require_is_browser());
17722
- var setImmediate = globalThis.setImmediate || ((...args) => {
17725
+ var setImmediate2 = globalThis.setImmediate || ((...args) => {
17723
17726
  const callback = args.shift();
17724
17727
  (0, shared_1.nextTick)(() => {
17725
17728
  callback(...args);
@@ -17838,11 +17841,7 @@ var mqtt = (() => {
17838
17841
  this.connected = false;
17839
17842
  this.log("close :: clearing connackTimer");
17840
17843
  clearTimeout(this.connackTimer);
17841
- this.log("close :: destroy ping timer");
17842
- if (this.pingTimer) {
17843
- this.pingTimer.destroy();
17844
- this.pingTimer = null;
17845
- }
17844
+ this._destroyPingTimer();
17846
17845
  if (this.topicAliasRecv) {
17847
17846
  this.topicAliasRecv.clear();
17848
17847
  }
@@ -18069,7 +18068,7 @@ var mqtt = (() => {
18069
18068
  }
18070
18069
  const invalidTopic = validations.validateTopics(topicsList);
18071
18070
  if (invalidTopic !== null) {
18072
- setImmediate(callback, new Error(`Invalid topic ${invalidTopic}`));
18071
+ setImmediate2(callback, new Error(`Invalid topic ${invalidTopic}`));
18073
18072
  return this;
18074
18073
  }
18075
18074
  if (this._checkDisconnecting(callback)) {
@@ -18196,7 +18195,7 @@ var mqtt = (() => {
18196
18195
  callback = callback || this.noop;
18197
18196
  const invalidTopic = validations.validateTopics(topic);
18198
18197
  if (invalidTopic !== null) {
18199
- setImmediate(callback, new Error(`Invalid topic ${invalidTopic}`));
18198
+ setImmediate2(callback, new Error(`Invalid topic ${invalidTopic}`));
18200
18199
  return this;
18201
18200
  }
18202
18201
  if (this._checkDisconnecting(callback)) {
@@ -18459,7 +18458,7 @@ var mqtt = (() => {
18459
18458
  this.log("_cleanUp :: (%s) :: call _sendPacket with disconnect packet", this.options.clientId);
18460
18459
  this._sendPacket(packet, () => {
18461
18460
  this.log("_cleanUp :: (%s) :: destroying stream", this.options.clientId);
18462
- setImmediate(() => {
18461
+ setImmediate2(() => {
18463
18462
  this.stream.end(() => {
18464
18463
  this.log("_cleanUp :: (%s) :: stream destroyed", this.options.clientId);
18465
18464
  });
@@ -18471,11 +18470,7 @@ var mqtt = (() => {
18471
18470
  this._clearReconnect();
18472
18471
  this._setupReconnect();
18473
18472
  }
18474
- if (this.pingTimer) {
18475
- this.log("_cleanUp :: destroy pingTimer");
18476
- this.pingTimer.destroy();
18477
- this.pingTimer = null;
18478
- }
18473
+ this._destroyPingTimer();
18479
18474
  if (done && !this.connected) {
18480
18475
  this.log("_cleanUp :: (%s) :: removing stream `done` callback `close` listener", this.options.clientId);
18481
18476
  this.stream.removeListener("close", done);
@@ -18554,7 +18549,6 @@ var mqtt = (() => {
18554
18549
  this.log("_writePacket :: packet: %O", packet);
18555
18550
  this.log("_writePacket :: emitting `packetsend`");
18556
18551
  this.emit("packetsend", packet);
18557
- this._shiftPingInterval();
18558
18552
  this.log("_writePacket :: writing to stream");
18559
18553
  const result = mqtt_packet_1.default.writeToStream(packet, this.stream, this.options);
18560
18554
  this.log("_writePacket :: writeToStream result %s", result);
@@ -18640,29 +18634,44 @@ var mqtt = (() => {
18640
18634
  _setupPingTimer() {
18641
18635
  this.log("_setupPingTimer :: keepalive %d (seconds)", this.options.keepalive);
18642
18636
  if (!this.pingTimer && this.options.keepalive) {
18643
- this.pingResp = true;
18644
18637
  this.pingTimer = new PingTimer_1.default(this.options.keepalive, () => {
18645
18638
  this._checkPing();
18646
18639
  }, this.options.timerVariant);
18640
+ this.pingResp = Date.now();
18641
+ }
18642
+ }
18643
+ _destroyPingTimer() {
18644
+ if (this.pingTimer) {
18645
+ this.log("_destroyPingTimer :: destroying ping timer");
18646
+ this.pingTimer.destroy();
18647
+ this.pingTimer = null;
18647
18648
  }
18648
18649
  }
18649
18650
  _shiftPingInterval() {
18650
18651
  if (this.pingTimer && this.options.keepalive && this.options.reschedulePings) {
18651
- this.pingTimer.reschedule();
18652
+ this._reschedulePing();
18652
18653
  }
18653
18654
  }
18655
+ _reschedulePing() {
18656
+ this.log("_reschedulePing :: rescheduling ping");
18657
+ this.pingTimer.reschedule();
18658
+ }
18654
18659
  _checkPing() {
18655
18660
  this.log("_checkPing :: checking ping...");
18656
- if (this.pingResp) {
18657
- this.log("_checkPing :: ping response received. Clearing flag and sending `pingreq`");
18658
- this.pingResp = false;
18659
- this._sendPacket({ cmd: "pingreq" });
18661
+ const timeSincePing = Date.now() - this.pingResp - 100;
18662
+ if (timeSincePing <= this.options.keepalive * 1e3) {
18663
+ this.log("_checkPing :: ping response received in time");
18664
+ this._sendPing();
18660
18665
  } else {
18661
18666
  this.emit("error", new Error("Keepalive timeout"));
18662
18667
  this.log("_checkPing :: calling _cleanUp with force true");
18663
18668
  this._cleanUp(true);
18664
18669
  }
18665
18670
  }
18671
+ _sendPing() {
18672
+ this.log("_sendPing :: sending pingreq");
18673
+ this._sendPacket({ cmd: "pingreq" });
18674
+ }
18666
18675
  _resubscribe() {
18667
18676
  this.log("_resubscribe");
18668
18677
  const _resubscribeTopicsKeys = Object.keys(this._resubscribeTopics);
@@ -20704,10 +20713,10 @@ var mqtt = (() => {
20704
20713
  var buildStream = (client, opts) => {
20705
20714
  opts.port = opts.port || 1883;
20706
20715
  opts.hostname = opts.hostname || opts.host || "localhost";
20707
- const { port } = opts;
20716
+ const { port, path: path2 } = opts;
20708
20717
  const host = opts.hostname;
20709
20718
  debug("port %d and host %s", port, host);
20710
- return net_1.default.createConnection(port, host);
20719
+ return net_1.default.createConnection({ port, host, path: path2 });
20711
20720
  };
20712
20721
  exports5.default = buildStream;
20713
20722
  }
@@ -21330,6 +21339,9 @@ var mqtt = (() => {
21330
21339
  var url_1 = __importDefault((init_url(), __toCommonJS(url_exports)));
21331
21340
  var client_1 = __importDefault(require_client());
21332
21341
  var is_browser_1 = __importDefault(require_is_browser());
21342
+ if (typeof (process_exports === null || process_exports === void 0 ? void 0 : process_exports.nextTick) !== "function") {
21343
+ process_exports.nextTick = setImmediate;
21344
+ }
21333
21345
  var debug = (0, debug_1.default)("mqttjs");
21334
21346
  var protocols = {};
21335
21347
  if (!is_browser_1.default) {