dsh-message-gateway 0.1.5 → 0.1.7
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 +18 -7
- package/lib/index.js.map +2 -2
- package/package.json +10 -10
package/lib/index.js
CHANGED
|
@@ -589,26 +589,37 @@ var QQBridge = class {
|
|
|
589
589
|
this.status = { state, detail, connectedAt: state === "connected" ? Date.now() : this.status.connectedAt };
|
|
590
590
|
this.callbacks.onStatus(this.status);
|
|
591
591
|
}
|
|
592
|
-
/** 启动:先取 access_token,再取 WSS
|
|
592
|
+
/** 启动:先取 access_token,再取 WSS 接入点,最后连网关;失败自动重试(退避)。 */
|
|
593
593
|
start() {
|
|
594
594
|
if (!this.stopped && this.ws !== null) return;
|
|
595
595
|
this.stopped = false;
|
|
596
596
|
this.setStatus("connecting", "access token");
|
|
597
|
-
void this.
|
|
597
|
+
void this.tryStart();
|
|
598
|
+
}
|
|
599
|
+
async tryStart() {
|
|
600
|
+
while (!this.stopped && this.ws === null) {
|
|
601
|
+
const token = await this.getAccessToken();
|
|
598
602
|
if (this.stopped) return;
|
|
599
603
|
if (token === null) {
|
|
600
|
-
|
|
601
|
-
|
|
604
|
+
const delay = Math.min(3e3 * 2 ** this.reconnectAttempts, 6e4);
|
|
605
|
+
this.reconnectAttempts += 1;
|
|
606
|
+
this.setStatus("connecting", `token retry ${delay}ms`);
|
|
607
|
+
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
608
|
+
continue;
|
|
602
609
|
}
|
|
603
610
|
this.setStatus("connecting", "gateway");
|
|
604
611
|
const url = await this.getGatewayUrl();
|
|
605
612
|
if (this.stopped) return;
|
|
606
613
|
if (url === null) {
|
|
607
|
-
|
|
608
|
-
|
|
614
|
+
const delay = Math.min(3e3 * 2 ** this.reconnectAttempts, 6e4);
|
|
615
|
+
this.reconnectAttempts += 1;
|
|
616
|
+
this.setStatus("connecting", `gateway retry ${delay}ms`);
|
|
617
|
+
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
618
|
+
continue;
|
|
609
619
|
}
|
|
610
620
|
this.connect(url);
|
|
611
|
-
|
|
621
|
+
return;
|
|
622
|
+
}
|
|
612
623
|
}
|
|
613
624
|
async getAccessToken() {
|
|
614
625
|
const controller = new AbortController();
|