mirror of
https://github.com/nvms/prsm.git
synced 2025-12-16 16:10:54 +00:00
allow typing on the callback return value for registerCommand
This commit is contained in:
parent
8ef12272be
commit
8dbc214e6f
Binary file not shown.
@ -130,7 +130,9 @@ export type KeepAliveServerOptions = ServerOptions & {
|
|||||||
export class KeepAliveServer extends WebSocketServer {
|
export class KeepAliveServer extends WebSocketServer {
|
||||||
connections: { [id: string]: Connection } = {};
|
connections: { [id: string]: Connection } = {};
|
||||||
remoteAddressToConnections: { [address: 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[] = [];
|
globalMiddlewares: SocketMiddleware[] = [];
|
||||||
middlewares: { [key: string]: SocketMiddleware[] } = {};
|
middlewares: { [key: string]: SocketMiddleware[] } = {};
|
||||||
rooms: { [roomName: string]: Set<string> } = {};
|
rooms: { [roomName: string]: Set<string> } = {};
|
||||||
@ -330,9 +332,9 @@ export class KeepAliveServer extends WebSocketServer {
|
|||||||
this.rooms[roomName] = new Set();
|
this.rooms[roomName] = new Set();
|
||||||
}
|
}
|
||||||
|
|
||||||
registerCommand(
|
registerCommand<T>(
|
||||||
command: string,
|
command: string,
|
||||||
callback: SocketMiddleware,
|
callback: (context: WSContext<any>) => Promise<T> | T,
|
||||||
middlewares: SocketMiddleware[] = [],
|
middlewares: SocketMiddleware[] = [],
|
||||||
) {
|
) {
|
||||||
this.commands[command] = callback;
|
this.commands[command] = callback;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user