From f1b2c8b1cf997f7173e7c01b45248b0497d87479 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=89=8B=E7=93=9C=E4=B8=80=E5=8D=81=E9=9B=AA?= Date: Fri, 15 Nov 2024 15:24:44 +0800 Subject: [PATCH] fix --- src/onebot/network/active-websocket.ts | 13 ++++++++----- src/onebot/network/passive-websocket.ts | 5 ++++- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/onebot/network/active-websocket.ts b/src/onebot/network/active-websocket.ts index 31c4ed20..fc9f5bdb 100644 --- a/src/onebot/network/active-websocket.ts +++ b/src/onebot/network/active-websocket.ts @@ -36,11 +36,14 @@ export class OB11ActiveWebSocketAdapter implements IOB11NetworkAdapter { if (this.connection) { return; } - this.heartbeatRef = setInterval(() => { - if (this.connection && this.connection.readyState === WebSocket.OPEN) { - this.connection.send(JSON.stringify(new OB11HeartbeatEvent(this.core, this.heartbeatIntervalInMillis, this.core.selfInfo.online ?? true, true))); - } - }, this.heartbeatIntervalInMillis); + if (this.heartbeatIntervalInMillis > 0) { + this.heartbeatRef = setInterval(() => { + if (this.connection && this.connection.readyState === WebSocket.OPEN) { + this.connection.send(JSON.stringify(new OB11HeartbeatEvent(this.core, this.heartbeatIntervalInMillis, this.core.selfInfo.online ?? true, true))); + } + }, this.heartbeatIntervalInMillis); + } + await this.tryConnect(); } diff --git a/src/onebot/network/passive-websocket.ts b/src/onebot/network/passive-websocket.ts index 7edc299a..276abbdd 100644 --- a/src/onebot/network/passive-websocket.ts +++ b/src/onebot/network/passive-websocket.ts @@ -115,7 +115,10 @@ export class OB11PassiveWebSocketAdapter implements IOB11NetworkAdapter { this.logger.log('[OneBot] [WebSocket Server] Server Started', typeof (addressInfo) === 'string' ? addressInfo : addressInfo?.address + ':' + addressInfo?.port); this.isOpen = true; - this.registerHeartBeat(); + if (this.heartbeatInterval > 0) { + this.registerHeartBeat(); + } + } async close() {