mqtt 5.4.0 → 5.5.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/dist/mqtt.js CHANGED
@@ -17538,9 +17538,9 @@ var mqtt = (() => {
17538
17538
  }
17539
17539
  });
17540
17540
 
17541
- // build/lib/timers.js
17542
- var require_timers = __commonJS({
17543
- "build/lib/timers.js"(exports5) {
17541
+ // build/lib/get-timer.js
17542
+ var require_get_timer = __commonJS({
17543
+ "build/lib/get-timer.js"(exports5) {
17544
17544
  "use strict";
17545
17545
  init_buffer2();
17546
17546
  init_process2();
@@ -17580,11 +17580,29 @@ var mqtt = (() => {
17580
17580
  Object.defineProperty(exports5, "__esModule", { value: true });
17581
17581
  var is_browser_1 = __importStar(require_is_browser());
17582
17582
  var worker_timers_1 = require_bundle3();
17583
- var timers = {
17584
- set: is_browser_1.default && !is_browser_1.isWebWorker ? worker_timers_1.setTimeout : (func, time) => setTimeout(func, time),
17585
- clear: is_browser_1.default && !is_browser_1.isWebWorker ? worker_timers_1.clearTimeout : (timer) => clearTimeout(timer)
17583
+ var workerTimer = {
17584
+ set: worker_timers_1.setTimeout,
17585
+ clear: worker_timers_1.clearTimeout
17586
17586
  };
17587
- exports5.default = timers;
17587
+ var nativeTimer = {
17588
+ set: (func, time) => setTimeout(func, time),
17589
+ clear: (timerId) => clearTimeout(timerId)
17590
+ };
17591
+ var getTimer = (variant) => {
17592
+ switch (variant) {
17593
+ case "native": {
17594
+ return nativeTimer;
17595
+ }
17596
+ case "worker": {
17597
+ return workerTimer;
17598
+ }
17599
+ case "auto":
17600
+ default: {
17601
+ return is_browser_1.default && !is_browser_1.isWebWorker ? workerTimer : nativeTimer;
17602
+ }
17603
+ }
17604
+ };
17605
+ exports5.default = getTimer;
17588
17606
  }
17589
17607
  });
17590
17608
 
@@ -17599,24 +17617,25 @@ var mqtt = (() => {
17599
17617
  return mod && mod.__esModule ? mod : { "default": mod };
17600
17618
  };
17601
17619
  Object.defineProperty(exports5, "__esModule", { value: true });
17602
- var timers_1 = __importDefault(require_timers());
17620
+ var get_timer_1 = __importDefault(require_get_timer());
17603
17621
  var PingTimer = class {
17604
- constructor(keepalive, checkPing) {
17622
+ constructor(keepalive, checkPing, variant) {
17605
17623
  this.keepalive = keepalive * 1e3;
17606
17624
  this.checkPing = checkPing;
17625
+ this.timer = (0, get_timer_1.default)(variant);
17607
17626
  this.reschedule();
17608
17627
  }
17609
17628
  clear() {
17610
- if (this.timer) {
17611
- timers_1.default.clear(this.timer);
17612
- this.timer = null;
17629
+ if (this.timerId) {
17630
+ this.timer.clear(this.timerId);
17631
+ this.timerId = null;
17613
17632
  }
17614
17633
  }
17615
17634
  reschedule() {
17616
17635
  this.clear();
17617
- this.timer = timers_1.default.set(() => {
17636
+ this.timerId = this.timer.set(() => {
17618
17637
  this.checkPing();
17619
- if (this.timer) {
17638
+ if (this.timerId) {
17620
17639
  this.reschedule();
17621
17640
  }
17622
17641
  }, this.keepalive);
@@ -17697,7 +17716,8 @@ var mqtt = (() => {
17697
17716
  connectTimeout: 30 * 1e3,
17698
17717
  clean: true,
17699
17718
  resubscribe: true,
17700
- writeCache: true
17719
+ writeCache: true,
17720
+ timerVariant: "auto"
17701
17721
  };
17702
17722
  var MqttClient = class _MqttClient extends TypedEmitter_1.TypedEventEmitter {
17703
17723
  static defaultId() {
@@ -17715,7 +17735,7 @@ var mqtt = (() => {
17715
17735
  }
17716
17736
  this.log = this.options.log || (0, debug_1.default)("mqttjs:client");
17717
17737
  this.noop = this._noop.bind(this);
17718
- this.log("MqttClient :: version:", "5.4.0");
17738
+ this.log("MqttClient :: version:", _MqttClient.VERSION);
17719
17739
  if (is_browser_1.isWebWorker) {
17720
17740
  this.log("MqttClient :: environment", "webworker");
17721
17741
  } else {
@@ -18605,7 +18625,7 @@ var mqtt = (() => {
18605
18625
  this.pingResp = true;
18606
18626
  this.pingTimer = new PingTimer_1.default(this.options.keepalive, () => {
18607
18627
  this._checkPing();
18608
- });
18628
+ }, this.options.timerVariant);
18609
18629
  }
18610
18630
  }
18611
18631
  _shiftPingInterval() {
@@ -18767,6 +18787,7 @@ var mqtt = (() => {
18767
18787
  });
18768
18788
  }
18769
18789
  };
18790
+ MqttClient.VERSION = "5.5.0";
18770
18791
  exports5.default = MqttClient;
18771
18792
  }
18772
18793
  });
@@ -20786,6 +20807,11 @@ var mqtt = (() => {
20786
20807
  this.writeQueue = [];
20787
20808
  this.proxy.end(callback);
20788
20809
  }
20810
+ _destroy(err, callback) {
20811
+ this.writeQueue = [];
20812
+ this.proxy.destroy(err);
20813
+ callback(err);
20814
+ }
20789
20815
  socketReady() {
20790
20816
  this.emit("connect");
20791
20817
  this.isSocketOpen = true;