mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2024-11-21 09:36:35 +00:00
chore: HeartBeat
This commit is contained in:
parent
3269061db4
commit
b5d24d751d
@ -1,5 +1,4 @@
|
||||
import type { NodeIQQNTWrapperSession, WrapperNodeApi } from "@/core/wrapper/wrapper";
|
||||
import { randomUUID } from "node:crypto";
|
||||
import EventEmitter from "node:events";
|
||||
|
||||
export type ListenerClassBase = Record<string, string>;
|
||||
|
@ -9,6 +9,9 @@ export class OB11ActiveHttpAdapter implements IOB11NetworkAdapter {
|
||||
constructor(url: string) {
|
||||
this.url = url;
|
||||
}
|
||||
registerHeartBeat() {
|
||||
//HttpPost心跳
|
||||
}
|
||||
|
||||
registerAction<T extends BaseAction<P, R>, P, R>(action: T) {
|
||||
this.actionMap.set(action.actionName, action);
|
||||
@ -22,13 +25,13 @@ export class OB11ActiveHttpAdapter implements IOB11NetworkAdapter {
|
||||
},
|
||||
body: JSON.stringify(event)
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
console.log('Event sent successfully:', data);
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Failed to send event:', error);
|
||||
});
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
console.log('Event sent successfully:', data);
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Failed to send event:', error);
|
||||
});
|
||||
}
|
||||
|
||||
async open() {
|
||||
|
@ -18,6 +18,10 @@ export class OB11ActiveWebSocketAdapter implements IOB11NetworkAdapter {
|
||||
this.reconnectIntervalInMillis = reconnectIntervalInMillis;
|
||||
}
|
||||
|
||||
registerHeartBeat() {
|
||||
//WS反向心跳
|
||||
}
|
||||
|
||||
registerAction<T extends BaseAction<P, R>, P, R>(action: T) {
|
||||
this.actionMap.set(action.actionName, action);
|
||||
}
|
||||
|
@ -7,3 +7,22 @@ export interface IOB11NetworkAdapter {
|
||||
open(): void | Promise<void>;
|
||||
close(): void | Promise<void>;
|
||||
}
|
||||
export class OB11NetworkManager {
|
||||
private adapters: IOB11NetworkAdapter[] = [];
|
||||
|
||||
registerAdapter(adapter: IOB11NetworkAdapter) {
|
||||
this.adapters.push(adapter);
|
||||
}
|
||||
|
||||
async open() {
|
||||
await Promise.all(this.adapters.map(adapter => adapter.open()));
|
||||
}
|
||||
|
||||
async close() {
|
||||
await Promise.all(this.adapters.map(adapter => adapter.close()));
|
||||
}
|
||||
}
|
||||
export * from './active-http';
|
||||
export * from './active-websocket';
|
||||
export * from './passive-http';
|
||||
export * from './passive-websocket';
|
@ -19,7 +19,9 @@ export class OB11PassiveHttpAdapter implements IOB11NetworkAdapter {
|
||||
registerAction<T extends BaseAction<P, R>, P, R>(action: T) {
|
||||
this.actionMap.set(action.actionName, action);
|
||||
}
|
||||
|
||||
registerHeartBeat() {
|
||||
//空心跳
|
||||
}
|
||||
onEvent<T extends OB11BaseEvent>(event: T) {
|
||||
// 事件处理逻辑可以在这里实现
|
||||
}
|
||||
|
@ -48,7 +48,9 @@ export class OB11PassiveWebSocketAdapter implements IOB11NetworkAdapter {
|
||||
registerAction<T extends BaseAction<P, R>, P, R>(action: T) {
|
||||
this.actionMap.set(action.actionName, action);
|
||||
}
|
||||
|
||||
registerHeartBeat() {
|
||||
//WS正向心跳
|
||||
}
|
||||
onEvent<T extends OB11BaseEvent>(event: T) {
|
||||
this.wsClientsMutex.runExclusive(async () => {
|
||||
this.wsClients.forEach((wsClient) => {
|
||||
|
Loading…
x
Reference in New Issue
Block a user