fix: ws心跳实现

This commit is contained in:
手瓜一十雪 2024-08-19 20:24:26 +08:00
parent eab930c083
commit d76503995c
2 changed files with 12 additions and 0 deletions

View File

@ -79,6 +79,12 @@ export class OB11ActiveWebSocketAdapter implements IOB11NetworkAdapter {
},
});
this.connection.on('ping', () => {
this.connection?.pong();
});
this.connection.on('pong', () => {
//this.logger.logDebug('[OneBot] [WebSocket Client] 收到pong');
});
this.connection.on('open', () => {
try {
this.connectEvent(this.coreContext);

View File

@ -50,6 +50,12 @@ export class OB11PassiveWebSocketAdapter implements IOB11NetworkAdapter {
wsClient.on('message', (message) => {
this.handleMessage(wsClient, message).then().catch(this.logger.logError);
});
wsClient.on('ping', () => {
wsClient.pong();
});
wsClient.on('pong', () => {
//this.logger.logDebug('[OneBot] [WebSocket Server] Pong received');
});
wsClient.once('close', () => {
this.wsClientsMutex.runExclusive(async () => {
const index = this.wsClients.indexOf(wsClient);