@mega-yfue/eufy-sdk 0.6.0-beta.35 → 0.6.0-beta.36

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
@@ -25545,13 +25545,14 @@ var RtcSession = class extends EventEmitter11 {
25545
25545
  closeAnnounced = false;
25546
25546
  sdpHandled = false;
25547
25547
  chain = Promise.resolve();
25548
+ stageReached = "signing";
25549
+ lastPeerState;
25548
25550
  constructor(opts) {
25549
25551
  super();
25550
25552
  this.opts = opts;
25551
25553
  this.logger = opts.logger ?? noopLogger;
25552
25554
  this.signaling = (opts.createSignaling ?? ((o) => new RtcSignalingClient(o)))(opts);
25553
25555
  this.peer = (opts.createPeer ?? ((o) => new RtcPeer(o)))({ logger: this.logger, ...opts.peer });
25554
- const mediaTrack = opts.peer?.mediaTrack === true;
25555
25556
  this.signaling.on("message", (inner) => {
25556
25557
  this.chain = this.chain.then(() => this.onSignaling(inner)).catch((e) => {
25557
25558
  this.emit("error", e instanceof Error ? e : new Error(String(e)));
@@ -25565,6 +25566,7 @@ var RtcSession = class extends EventEmitter11 {
25565
25566
  if (this.connected)
25566
25567
  return;
25567
25568
  this.connected = true;
25569
+ this.stageReached = "connected";
25568
25570
  this.logger.debug(`[rtc] ${this.opts.stationSn} command channel open`);
25569
25571
  this.emit("connected");
25570
25572
  });
@@ -25576,9 +25578,14 @@ var RtcSession = class extends EventEmitter11 {
25576
25578
  this.announceClose();
25577
25579
  });
25578
25580
  this.peer.on("connectionState", (state) => {
25579
- if ((state === "failed" || state === "closed") && (this.connected || mediaTrack)) {
25581
+ this.lastPeerState = state;
25582
+ if (state !== "failed" && state !== "closed")
25583
+ return;
25584
+ if (this.connected || this.mediaTrack) {
25580
25585
  this.connected = false;
25581
25586
  this.announceClose();
25587
+ } else {
25588
+ this.shutdown(new Error(`RTC ${this.opts.stationSn} peer ${state} before the command channel opened`));
25582
25589
  }
25583
25590
  });
25584
25591
  this.peer.on("error", (e) => this.emit("error", e));
@@ -25591,9 +25598,20 @@ var RtcSession = class extends EventEmitter11 {
25591
25598
  this.emit("commandData", frame, linkType);
25592
25599
  });
25593
25600
  }
25601
+ get mediaTrack() {
25602
+ return this.opts.peer?.mediaTrack === true;
25603
+ }
25594
25604
  get isConnected() {
25595
25605
  return this.connected;
25596
25606
  }
25607
+ /** The last bring-up stage this session reached. */
25608
+ get stage() {
25609
+ return this.stageReached;
25610
+ }
25611
+ /** The peer connection's last reported state; `undefined` before it reports one. */
25612
+ get peerState() {
25613
+ return this.lastPeerState;
25614
+ }
25597
25615
  /**
25598
25616
  * Start the sequence; resolves once the call is sent. `connected` fires when the channel opens. A session
25599
25617
  * closed by the time the sign fetch or the auth completes rejects instead of opening the socket or
@@ -25603,11 +25621,14 @@ var RtcSession = class extends EventEmitter11 {
25603
25621
  await this.signaling.fetchSign();
25604
25622
  if (this.closed)
25605
25623
  throw new Error("RTC session closed before the call was placed");
25624
+ this.stageReached = "connecting";
25606
25625
  await this.signaling.connect();
25626
+ this.stageReached = "authenticating";
25607
25627
  await this.waitForAuth();
25608
25628
  if (this.closed)
25609
25629
  throw new Error("RTC session closed before the call was placed");
25610
25630
  this.logger.debug(`[rtc] ${this.opts.stationSn} authenticated \u2014 ${this.opts.signalingMode ?? "scall"}`);
25631
+ this.stageReached = "calling";
25611
25632
  this.signaling.sendCall();
25612
25633
  }
25613
25634
  /** Send one portal packet; false when the command channel isn't open. */
@@ -25703,6 +25724,9 @@ var RtcSession = class extends EventEmitter11 {
25703
25724
  return;
25704
25725
  case "hangup":
25705
25726
  this.logger.debug(`[rtc] ${this.opts.stationSn} hub hung up`);
25727
+ if (!this.connected && this.opts.signalingMode !== "call") {
25728
+ this.shutdown(new Error(`RTC ${this.opts.stationSn} hub hung up before the command channel opened`));
25729
+ }
25706
25730
  return;
25707
25731
  default:
25708
25732
  return;
@@ -25715,6 +25739,7 @@ var RtcSession = class extends EventEmitter11 {
25715
25739
  const status = payload.status;
25716
25740
  if (status === 100 && payload.turn) {
25717
25741
  this.turn = payload.turn;
25742
+ this.stageReached = "relay-granted";
25718
25743
  try {
25719
25744
  await this.peer.init(payload.turn);
25720
25745
  } catch (e) {
@@ -25770,6 +25795,7 @@ var RtcSession = class extends EventEmitter11 {
25770
25795
  }
25771
25796
  const answer = await this.peer.handleRemoteOffer(offer);
25772
25797
  this.signaling.sendInfoSdp(this.opts.signalingMode === "call" ? answer : JSON.stringify(sdpToScallJson(answer)));
25798
+ this.stageReached = "answered";
25773
25799
  this.logger.debug(`[rtc] ${this.opts.stationSn} answered the hub's offer`);
25774
25800
  }
25775
25801
  };
@@ -26248,7 +26274,8 @@ var RtcCommandRouter = class {
26248
26274
  /**
26249
26275
  * One bounded bring-up: the session is up when its command channel opens, and it fails, with the
26250
26276
  * session closed and every listener gone, when `connect()` throws, the session closes first (rejecting
26251
- * with the failure that closed it, when it carries one), or {@link CONNECT_TIMEOUT_MS} passes. A single
26277
+ * with the failure that closed it, when it carries one), or {@link CONNECT_TIMEOUT_MS} passes, naming the
26278
+ * stage the session reached and its peer's last state. A single
26252
26279
  * promise, so an early failure cannot leave a second one rejecting unheard.
26253
26280
  */
26254
26281
  bringUp(sn, session) {
@@ -26274,7 +26301,7 @@ var RtcCommandRouter = class {
26274
26301
  };
26275
26302
  const onConnected = () => finish();
26276
26303
  const onClose = (err) => finish(err ?? new Error(`rtc: ${sn} session closed before the command channel opened`));
26277
- const timer = setTimeout(() => finish(new Error(`rtc: ${sn} did not come up within ${CONNECT_TIMEOUT_MS2}ms`)), CONNECT_TIMEOUT_MS2);
26304
+ const timer = setTimeout(() => finish(new Error(`rtc: ${sn} did not come up within ${CONNECT_TIMEOUT_MS2}ms (stage ${session.stage}, peer ${session.peerState ?? "not started"})`)), CONNECT_TIMEOUT_MS2);
26278
26305
  session.once("connected", onConnected);
26279
26306
  session.once("close", onClose);
26280
26307
  Promise.resolve().then(() => session.connect()).catch((e) => finish(e instanceof Error ? e : new Error(String(e))));