@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 +35 -20
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +35 -20
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
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.
|
|
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
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
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) {
|