feat: add showConnected option and refactor WebSocket connection handling

This commit is contained in:
2025-12-21 04:13:38 +08:00
parent 7975863af3
commit b6c613d601
4 changed files with 14 additions and 7 deletions

View File

@@ -16,6 +16,7 @@ export type ServerOpts<T = {}> = {
handle?: (msg?: { path: string; key?: string;[key: string]: any }, ctx?: { req: http.IncomingMessage; res: http.ServerResponse }) => any;
cors?: Cors;
io?: boolean;
showConnected?: boolean;
} & T;
export interface ServerType {
@@ -40,11 +41,12 @@ export interface ServerType {
on(listener: OnListener): void;
onWebSocket({ ws, message, pathname, token, id }: OnWebSocketOptions): void;
onWsClose(ws: WS): void;
sendConnected(ws: WS): void;
}
export type OnWebSocketOptions = { ws: WS; message: string | Buffer; pathname: string, token?: string, id?: string }
export type OnWebSocketFn = (options: OnWebSocketOptions) => Promise<void> | void;
export type WS = {
export type WS<T = {}> = {
send: (data: any) => void;
close: (code?: number, reason?: string) => void;
data?: {
@@ -56,7 +58,7 @@ export type WS = {
* 鉴权后的获取的信息
*/
userApp?: string;
}
} & T;
}
export type Listener = {
id?: string;