This commit is contained in:
手瓜一十雪
2024-12-17 15:55:18 +08:00
parent 6089046721
commit f3ed8c7dff

View File

@@ -17,7 +17,6 @@ export class OB11PassiveWebSocketAdapter extends IOB11NetworkAdapter<WebsocketSe
wsServer: WebSocketServer; wsServer: WebSocketServer;
wsClients: WebSocket[] = []; wsClients: WebSocket[] = [];
wsClientsMutex = new Mutex(); wsClientsMutex = new Mutex();
heartbeatInterval: number = 0;
private heartbeatIntervalId: NodeJS.Timeout | null = null; private heartbeatIntervalId: NodeJS.Timeout | null = null;
wsClientWithEvent: WebSocket[] = []; wsClientWithEvent: WebSocket[] = [];
@@ -100,7 +99,7 @@ export class OB11PassiveWebSocketAdapter extends IOB11NetworkAdapter<WebsocketSe
this.logger.log('[OneBot] [WebSocket Server] Server Started', typeof (addressInfo) === 'string' ? addressInfo : addressInfo?.address + ':' + addressInfo?.port); this.logger.log('[OneBot] [WebSocket Server] Server Started', typeof (addressInfo) === 'string' ? addressInfo : addressInfo?.address + ':' + addressInfo?.port);
this.isEnable = true; this.isEnable = true;
if (this.heartbeatInterval > 0) { if (this.config.heartInterval > 0) {
this.registerHeartBeat(); this.registerHeartBeat();
} }
@@ -134,11 +133,11 @@ export class OB11PassiveWebSocketAdapter extends IOB11NetworkAdapter<WebsocketSe
this.wsClientsMutex.runExclusive(async () => { this.wsClientsMutex.runExclusive(async () => {
this.wsClientWithEvent.forEach((wsClient) => { this.wsClientWithEvent.forEach((wsClient) => {
if (wsClient.readyState === WebSocket.OPEN) { if (wsClient.readyState === WebSocket.OPEN) {
wsClient.send(JSON.stringify(new OB11HeartbeatEvent(this.core, this.heartbeatInterval, this.core.selfInfo.online ?? true, true))); wsClient.send(JSON.stringify(new OB11HeartbeatEvent(this.core, this.config.heartInterval, this.core.selfInfo.online ?? true, true)));
} }
}); });
}); });
}, this.heartbeatInterval); }, this.config.heartInterval);
} }
private authorize(token: string | undefined, wsClient: WebSocket, wsReq: IncomingMessage) { private authorize(token: string | undefined, wsClient: WebSocket, wsReq: IncomingMessage) {
@@ -185,7 +184,7 @@ export class OB11PassiveWebSocketAdapter extends IOB11NetworkAdapter<WebsocketSe
const wasEnabled = this.isEnable; const wasEnabled = this.isEnable;
const oldPort = this.config.port; const oldPort = this.config.port;
const oldHost = this.config.host; const oldHost = this.config.host;
const oldHeartbeatInterval = this.heartbeatInterval; const oldHeartbeatInterval = this.config.heartInterval;
this.config = newConfig; this.config = newConfig;
if (newConfig.enable && !wasEnabled) { if (newConfig.enable && !wasEnabled) {
@@ -214,7 +213,6 @@ export class OB11PassiveWebSocketAdapter extends IOB11NetworkAdapter<WebsocketSe
clearInterval(this.heartbeatIntervalId); clearInterval(this.heartbeatIntervalId);
this.heartbeatIntervalId = null; this.heartbeatIntervalId = null;
} }
this.heartbeatInterval = newConfig.heartInterval;
if (newConfig.heartInterval > 0 && this.isEnable) { if (newConfig.heartInterval > 0 && this.isEnable) {
this.registerHeartBeat(); this.registerHeartBeat();
} }