dsh-message-gateway 0.1.4 → 0.1.5

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/lib/index.js CHANGED
@@ -581,6 +581,8 @@ var QQBridge = class {
581
581
  tokenExpiresAt = 0;
582
582
  /** 单聊流式/群聊定稿发送器。 */
583
583
  sender;
584
+ /** 连续重连次数(退避用,READY 后重置)。 */
585
+ reconnectAttempts = 0;
584
586
  recentMsgIds = /* @__PURE__ */ new Set();
585
587
  status = { state: "idle", detail: "", connectedAt: null };
586
588
  setStatus(state, detail = "") {
@@ -681,16 +683,19 @@ var QQBridge = class {
681
683
  this.clearHeartbeat();
682
684
  this.ws = null;
683
685
  if (!this.stopped) {
684
- console.warn("[dsh-message-gateway] qq gateway closed, reconnect in 3s");
686
+ this.setStatus("connecting", "reconnect");
687
+ const delay = Math.min(3e3 * 2 ** this.reconnectAttempts, 6e4);
688
+ this.reconnectAttempts += 1;
689
+ console.warn(`[dsh-message-gateway] qq gateway closed, reconnect in ${delay}ms`);
685
690
  setTimeout(() => {
686
691
  if (this.stopped) return;
687
- void this.ensureToken().then(async (ok) => {
688
- if (this.stopped || !ok) return;
692
+ void this.getAccessToken().then(async (token) => {
693
+ if (this.stopped || token === null) return;
689
694
  const u = await this.getGatewayUrl();
690
695
  if (this.stopped || u === null) return;
691
696
  this.connect(u);
692
697
  });
693
- }, 3e3);
698
+ }, delay);
694
699
  }
695
700
  };
696
701
  }
@@ -715,6 +720,7 @@ var QQBridge = class {
715
720
  }
716
721
  case 0: {
717
722
  if (payload.t === "READY") {
723
+ this.reconnectAttempts = 0;
718
724
  this.setStatus("connected", "qq");
719
725
  console.log("[dsh-message-gateway] qq READY");
720
726
  } else if (payload.t === "C2C_MESSAGE_CREATE") {
@@ -725,7 +731,8 @@ var QQBridge = class {
725
731
  break;
726
732
  }
727
733
  case 9: {
728
- console.warn("[dsh-message-gateway] qq identify rejected (INVALID_SESSION) \u2014 \u8BF7\u786E\u8BA4\u63A7\u5236\u53F0\u4E8B\u4EF6\u8BA2\u9605\u4E3A WebSocket \u957F\u8FDE\u63A5");
734
+ console.warn("[dsh-message-gateway] qq identify rejected (INVALID_SESSION), refreshing token");
735
+ this.accessToken = null;
729
736
  this.ws?.close();
730
737
  break;
731
738
  }