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() {