@mega-yfue/eufy-sdk 0.3.0-beta.7 → 0.3.0-beta.8

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
@@ -2131,6 +2131,13 @@ function isNotAuthorized(err) {
2131
2131
  var SecureMqtt = class extends EventEmitter {
2132
2132
  kind = "smqtt";
2133
2133
  client;
2134
+ /**
2135
+ * The in-flight or established connect. A client ID is exclusive at the broker, so a second mqtt.js
2136
+ * client under the same ID evicts the first, which reconnects and evicts it back, forever; `connect()`
2137
+ * therefore hands a later caller this same attempt instead of opening a rival. Cleared when the
2138
+ * attempt fails and on `disconnect()`, so a caller can still retry or deliberately reconnect.
2139
+ */
2140
+ connecting;
2134
2141
  o;
2135
2142
  logger;
2136
2143
  constructor(opts) {
@@ -2141,11 +2148,19 @@ var SecureMqtt = class extends EventEmitter {
2141
2148
  get id() {
2142
2149
  return this.o.clientId ?? this.o.credentials.thing_name ?? "";
2143
2150
  }
2151
+ /** Connect, joining the attempt in `connecting` when one is already opening or open. */
2152
+ async connect() {
2153
+ this.connecting ??= this.open().catch((error) => {
2154
+ this.connecting = void 0;
2155
+ throw error;
2156
+ });
2157
+ return await this.connecting;
2158
+ }
2144
2159
  /**
2145
2160
  * Open the broker connection, resolving once it is established. Pinned to a broker instance's IP, or
2146
2161
  * to the plain hostname; only the former needs its own TLS shape, see `./bare-ip-tls.ts`.
2147
2162
  */
2148
- async connect() {
2163
+ async open() {
2149
2164
  const mqtt = await loadMqtt();
2150
2165
  const c = this.o.credentials;
2151
2166
  const port = c.endpoint_port ?? 8883;
@@ -2273,6 +2288,7 @@ var SecureMqtt = class extends EventEmitter {
2273
2288
  await this.client.publishAsync(topic, body, { qos: opts.qos ?? 1 });
2274
2289
  }
2275
2290
  async disconnect() {
2291
+ this.connecting = void 0;
2276
2292
  await this.client?.endAsync(true);
2277
2293
  this.client = void 0;
2278
2294
  }