@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.cjs CHANGED
@@ -84,7 +84,7 @@ module.exports = __toCommonJS(index_exports);
84
84
 
85
85
  // src/support/version.ts
86
86
  var LIBRARY_NAME = "nodedreame";
87
- var LIBRARY_VERSION = "1.11.0";
87
+ var LIBRARY_VERSION = "1.11.1";
88
88
 
89
89
  // src/transport/errors.ts
90
90
  var DreameError = class extends Error {
@@ -700,6 +700,7 @@ var DreamePush = class extends TypedEmitter {
700
700
  #region;
701
701
  #connect;
702
702
  #backoffMs;
703
+ #keepaliveSeconds;
703
704
  #rejectUnauthorized;
704
705
  #topic;
705
706
  #client = null;
@@ -720,6 +721,7 @@ var DreamePush = class extends TypedEmitter {
720
721
  this.#region = input.region;
721
722
  this.#connect = input.connect ?? defaultConnect;
722
723
  this.#backoffMs = input.reconnectBackoffMs ?? 5e3;
724
+ this.#keepaliveSeconds = input.keepaliveSeconds ?? 60;
723
725
  this.#rejectUnauthorized = input.rejectUnauthorized ?? false;
724
726
  this.#topic = buildStatusTopic(this.#device, this.#session.uid, this.#region);
725
727
  this.#onClose = () => {
@@ -777,6 +779,7 @@ var DreamePush = class extends TypedEmitter {
777
779
  reconnectPeriod: 0,
778
780
  // we drive reconnect ourselves
779
781
  connectTimeout: 15e3,
782
+ keepalive: this.#keepaliveSeconds,
780
783
  rejectUnauthorized: this.#rejectUnauthorized,
781
784
  clean: true
782
785
  });
@@ -784,25 +787,37 @@ var DreamePush = class extends TypedEmitter {
784
787
  client.on("message", (_topic, payload) => this.#handleMessage(payload));
785
788
  client.on("error", (err) => this.emit("error", err));
786
789
  client.on("close", this.#onClose);
787
- await new Promise((resolve, reject) => {
788
- const onConnect = () => {
789
- client.removeListener("error", onError);
790
- client.subscribe(this.#topic, { qos: 0 }, (err) => {
791
- if (err) {
792
- reject(new DreameTransportError(`mqtt subscribe failed: ${err.message}`, err));
793
- return;
794
- }
795
- this.emit("connect");
796
- resolve();
797
- });
798
- };
799
- const onError = (err) => {
800
- client.removeListener("connect", onConnect);
801
- reject(new DreameTransportError(`mqtt connect failed: ${err.message}`, err));
802
- };
803
- client.once("connect", onConnect);
804
- client.once("error", onError);
805
- });
790
+ try {
791
+ await new Promise((resolve, reject) => {
792
+ const onConnect = () => {
793
+ client.removeListener("error", onError);
794
+ client.subscribe(this.#topic, { qos: 0 }, (err) => {
795
+ if (err) {
796
+ reject(new DreameTransportError(`mqtt subscribe failed: ${err.message}`, err));
797
+ return;
798
+ }
799
+ this.emit("connect");
800
+ resolve();
801
+ });
802
+ };
803
+ const onError = (err) => {
804
+ client.removeListener("connect", onConnect);
805
+ reject(new DreameTransportError(`mqtt connect failed: ${err.message}`, err));
806
+ };
807
+ client.once("connect", onConnect);
808
+ client.once("error", onError);
809
+ });
810
+ } catch (err) {
811
+ client.removeListener("close", this.#onClose);
812
+ try {
813
+ client.end(true, {}, () => void 0);
814
+ } catch {
815
+ }
816
+ if (this.#client === client) {
817
+ this.#client = null;
818
+ }
819
+ throw err;
820
+ }
806
821
  }
807
822
  #scheduleReconnect() {
808
823
  if (this.#closed || this.#reconnectTimer) {