Kind: Interface
Source: packages/websockets/context/ws-context-creator.ts
Part of: Websockets
WsHandlerMetadata describes the reflected metadata required to create and invoke a WebSocket handler. It captures the handler's argument count and parameter types, and provides a module-aware function for retrieving WebSocket parameter metadata.
Properties
| Property | Type |
|---|---|
argsLength | number |
paramtypes | any[] |
getParamsMetadata | (moduleKey: string) => WsParamProperties[] |
Diagram
mermaidgraph LR A[WebSocket Gateway Handler] --> B[WsHandlerMetadata] B --> C[argsLength: number] B --> D[paramtypes: any[]] B --> E[getParamsMetadata(moduleKey)] E --> F[WsParamProperties[]] F --> G[WsContextCreator]
Usage
tsimport type { WsHandlerMetadata } from '@nestjs/websockets';
const handlerMetadata: WsHandlerMetadata = {
argsLength: 2,
paramtypes: [Object, Object],
getParamsMetadata: (moduleKey) => {
if (moduleKey !== 'chat-module') {
return [];
}
return [
{
index: 0,
data: undefined,
pipes: [],
factory: /* WebSocket parameter factory */,
},
];
},
};
// Pass metadata to the WebSocket context creation flow.
const paramsMetadata = handlerMetadata.getParamsMetadata('chat-module');
AI Coding Instructions
- Preserve
argsLengthso generated handler argument arrays match the original method signature. - Keep
paramtypesaligned with the reflected parameter types for the gateway handler method. - Implement
getParamsMetadataas module-aware; metadata may differ based on the resolvedmoduleKey. - Return an empty
WsParamProperties[]when no parameter decorators or metadata apply. - Integrate this metadata with
WsContextCreatorwhen constructing pipes, extracting socket payloads, or resolving decorated parameters.
Relationships
- IMPORTS →
CUSTOM_ROUTE_ARGS_METADATA - IMPORTS →
PARAMTYPES_METADATA - IMPORTS →
ContextType - IMPORTS →
Controller - IMPORTS →
PipeTransform - IMPORTS →
isEmpty - IMPORTS →
FORBIDDEN_MESSAGE - IMPORTS →
GuardsConsumer - IMPORTS →
GuardsContextCreator - IMPORTS →
ContextUtils - IMPORTS →
ParamProperties - IMPORTS →
ExecutionContextHost - IMPORTS →
HandlerMetadataStorage - IMPORTS →
ParamsMetadata - IMPORTS →
InterceptorsConsumer - IMPORTS →
InterceptorsContextCreator - IMPORTS →
PipesConsumer - IMPORTS →
PipesContextCreator
Was this page helpful?