This commit is contained in:
手瓜一十雪 2024-11-15 15:24:44 +08:00
parent 50079e7a96
commit f1b2c8b1cf
2 changed files with 12 additions and 6 deletions

View File

@ -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();
}

View File

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