chore: token

This commit is contained in:
手瓜一十雪 2024-08-10 17:07:23 +08:00
parent b5d24d751d
commit 89188958ec
5 changed files with 14 additions and 12 deletions

View File

@ -5,8 +5,10 @@ import { OB11BaseEvent } from '@/onebot/event/OB11BaseEvent';
export class OB11ActiveHttpAdapter implements IOB11NetworkAdapter { export class OB11ActiveHttpAdapter implements IOB11NetworkAdapter {
url: string; url: string;
private actionMap: Map<string, BaseAction<any, any>> = new Map(); private actionMap: Map<string, BaseAction<any, any>> = new Map();
heartbeatInterval: number;
constructor(url: string) { constructor(url: string, heartbeatInterval: number) {
this.heartbeatInterval = heartbeatInterval;
this.url = url; this.url = url;
} }
registerHeartBeat() { registerHeartBeat() {

View File

@ -12,16 +12,18 @@ export class OB11ActiveWebSocketAdapter implements IOB11NetworkAdapter {
private connection: NodeWebSocket | null = null; private connection: NodeWebSocket | null = null;
private actionMap: Map<string, BaseAction<any, any>> = new Map(); private actionMap: Map<string, BaseAction<any, any>> = new Map();
heartbeatInterval: number;
constructor(url: string, reconnectIntervalInMillis: number) { constructor(url: string, reconnectIntervalInMillis: number, heartbeatInterval: number) {
this.url = url; this.url = url;
this.heartbeatInterval = heartbeatInterval;
this.reconnectIntervalInMillis = reconnectIntervalInMillis; this.reconnectIntervalInMillis = reconnectIntervalInMillis;
} }
registerHeartBeat() { registerHeartBeat() {
//WS反向心跳 //WS反向心跳
} }
registerAction<T extends BaseAction<P, R>, P, R>(action: T) { registerAction<T extends BaseAction<P, R>, P, R>(action: T) {
this.actionMap.set(action.actionName, action); this.actionMap.set(action.actionName, action);
} }

View File

@ -13,12 +13,7 @@ export class OB11NetworkManager {
registerAdapter(adapter: IOB11NetworkAdapter) { registerAdapter(adapter: IOB11NetworkAdapter) {
this.adapters.push(adapter); this.adapters.push(adapter);
} }
async closeAll() {
async open() {
await Promise.all(this.adapters.map(adapter => adapter.open()));
}
async close() {
await Promise.all(this.adapters.map(adapter => adapter.close())); await Promise.all(this.adapters.map(adapter => adapter.close()));
} }
} }

View File

@ -11,9 +11,11 @@ export class OB11PassiveHttpAdapter implements IOB11NetworkAdapter {
private hasBeenClosed: boolean = false; private hasBeenClosed: boolean = false;
private actionMap: Map<string, BaseAction<any, any>> = new Map(); private actionMap: Map<string, BaseAction<any, any>> = new Map();
private port: number; private port: number;
token: string;
constructor(port: number) { constructor(port: number,token: string) {
this.port = port; this.port = port;
this.token = token;
} }
registerAction<T extends BaseAction<P, R>, P, R>(action: T) { registerAction<T extends BaseAction<P, R>, P, R>(action: T) {

View File

@ -10,10 +10,11 @@ export class OB11PassiveWebSocketAdapter implements IOB11NetworkAdapter {
wsClientsMutex = new Mutex(); wsClientsMutex = new Mutex();
isOpen: boolean = false; isOpen: boolean = false;
hasBeenClosed: boolean = false; hasBeenClosed: boolean = false;
heartbeatInterval:number = 0;
private actionMap: Map<string, BaseAction<any, any>> = new Map(); private actionMap: Map<string, BaseAction<any, any>> = new Map();
constructor(ip: string, port: number, token: string) { constructor(ip: string, port: number, heartbeatInterval: number, token: string) {
this.heartbeatInterval = heartbeatInterval;
this.wsServer = new WebSocketServer({ port: port, host: ip }); this.wsServer = new WebSocketServer({ port: port, host: ip });
this.wsServer.on('connection', async (wsClient) => { this.wsServer.on('connection', async (wsClient) => {
if (!this.isOpen) { if (!this.isOpen) {