napcat-node-ts-sdk
Version:
napcat SDK for Node
42 lines (41 loc) • 1.24 kB
TypeScript
import type { AllHandlers, EventHandleMap, EventKey, NCWebsocketOptions, WSSendParam, WSSendReturn } from './Interfaces';
export declare class NCWebsocketBase {
#private;
constructor(NCWebsocketOptions: NCWebsocketOptions, debug?: boolean);
/**
* await connect() 等待 ws 连接
*/
connect(): Promise<void>;
disconnect(): void;
reconnect(): Promise<void>;
/**
* 发送API请求
* @param method API 端点
* @param params 请求参数
*/
send<T extends keyof WSSendParam>(method: T, params: WSSendParam[T]): Promise<WSSendReturn[T]>;
/**
* 注册监听方法
* @param event
* @param handle
*/
on<T extends EventKey>(event: T, handle: EventHandleMap[T]): this;
/**
* 只执行一次
* @param event
* @param handle
*/
once<T extends EventKey>(event: T, handle: EventHandleMap[T]): this;
/**
* 解除监听方法
* @param event
* @param handle
*/
off<T extends keyof AllHandlers>(event: T, handle: EventHandleMap[T]): this;
/**
* 手动模拟触发某个事件
* @param type
* @param context
*/
emit<T extends keyof AllHandlers>(type: T, context: AllHandlers[T]): this;
}