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 +12 -5
- package/lib/index.js.map +2 -2
- package/package.json +1 -1
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
|
-
|
|
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.
|
|
688
|
-
if (this.stopped ||
|
|
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
|
-
},
|
|
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)
|
|
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
|
}
|