@apocaliss92/nodedreame 1.11.0 → 1.11.1

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/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  // src/support/version.ts
2
2
  var LIBRARY_NAME = "nodedreame";
3
- var LIBRARY_VERSION = "1.11.0";
3
+ var LIBRARY_VERSION = "1.11.1";
4
4
 
5
5
  // src/transport/errors.ts
6
6
  var DreameError = class extends Error {
@@ -616,6 +616,7 @@ var DreamePush = class extends TypedEmitter {
616
616
  #region;
617
617
  #connect;
618
618
  #backoffMs;
619
+ #keepaliveSeconds;
619
620
  #rejectUnauthorized;
620
621
  #topic;
621
622
  #client = null;
@@ -636,6 +637,7 @@ var DreamePush = class extends TypedEmitter {
636
637
  this.#region = input.region;
637
638
  this.#connect = input.connect ?? defaultConnect;
638
639
  this.#backoffMs = input.reconnectBackoffMs ?? 5e3;
640
+ this.#keepaliveSeconds = input.keepaliveSeconds ?? 60;
639
641
  this.#rejectUnauthorized = input.rejectUnauthorized ?? false;
640
642
  this.#topic = buildStatusTopic(this.#device, this.#session.uid, this.#region);
641
643
  this.#onClose = () => {
@@ -693,6 +695,7 @@ var DreamePush = class extends TypedEmitter {
693
695
  reconnectPeriod: 0,
694
696
  // we drive reconnect ourselves
695
697
  connectTimeout: 15e3,
698
+ keepalive: this.#keepaliveSeconds,
696
699
  rejectUnauthorized: this.#rejectUnauthorized,
697
700
  clean: true
698
701
  });
@@ -700,25 +703,37 @@ var DreamePush = class extends TypedEmitter {
700
703
  client.on("message", (_topic, payload) => this.#handleMessage(payload));
701
704
  client.on("error", (err) => this.emit("error", err));
702
705
  client.on("close", this.#onClose);
703
- await new Promise((resolve, reject) => {
704
- const onConnect = () => {
705
- client.removeListener("error", onError);
706
- client.subscribe(this.#topic, { qos: 0 }, (err) => {
707
- if (err) {
708
- reject(new DreameTransportError(`mqtt subscribe failed: ${err.message}`, err));
709
- return;
710
- }
711
- this.emit("connect");
712
- resolve();
713
- });
714
- };
715
- const onError = (err) => {
716
- client.removeListener("connect", onConnect);
717
- reject(new DreameTransportError(`mqtt connect failed: ${err.message}`, err));
718
- };
719
- client.once("connect", onConnect);
720
- client.once("error", onError);
721
- });
706
+ try {
707
+ await new Promise((resolve, reject) => {
708
+ const onConnect = () => {
709
+ client.removeListener("error", onError);
710
+ client.subscribe(this.#topic, { qos: 0 }, (err) => {
711
+ if (err) {
712
+ reject(new DreameTransportError(`mqtt subscribe failed: ${err.message}`, err));
713
+ return;
714
+ }
715
+ this.emit("connect");
716
+ resolve();
717
+ });
718
+ };
719
+ const onError = (err) => {
720
+ client.removeListener("connect", onConnect);
721
+ reject(new DreameTransportError(`mqtt connect failed: ${err.message}`, err));
722
+ };
723
+ client.once("connect", onConnect);
724
+ client.once("error", onError);
725
+ });
726
+ } catch (err) {
727
+ client.removeListener("close", this.#onClose);
728
+ try {
729
+ client.end(true, {}, () => void 0);
730
+ } catch {
731
+ }
732
+ if (this.#client === client) {
733
+ this.#client = null;
734
+ }
735
+ throw err;
736
+ }
722
737
  }
723
738
  #scheduleReconnect() {
724
739
  if (this.#closed || this.#reconnectTimer) {