allow typing on the callback return value for registerCommand

This commit is contained in:
nvms 2024-09-04 10:49:32 -04:00
parent 8ef12272be
commit 8dbc214e6f
2 changed files with 5 additions and 3 deletions

View File

@ -130,7 +130,9 @@ export type KeepAliveServerOptions = ServerOptions & {
export class KeepAliveServer extends WebSocketServer {
connections: { [id: string]: Connection } = {};
remoteAddressToConnections: { [address: string]: Connection[] } = {};
commands: { [command: string]: (context: WSContext<any>) => Promise<void> } = {};
commands: {
[command: string]: (context: WSContext<any>) => Promise<any> | any;
} = {};
globalMiddlewares: SocketMiddleware[] = [];
middlewares: { [key: string]: SocketMiddleware[] } = {};
rooms: { [roomName: string]: Set<string> } = {};
@ -330,9 +332,9 @@ export class KeepAliveServer extends WebSocketServer {
this.rooms[roomName] = new Set();
}
registerCommand(
registerCommand<T>(
command: string,
callback: SocketMiddleware,
callback: (context: WSContext<any>) => Promise<T> | T,
middlewares: SocketMiddleware[] = [],
) {
this.commands[command] = callback;