mqtt 5.5.4 → 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.4" };
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":
@@ -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
  }
@@ -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);