You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/websockets/gateways.md
+7-2Lines changed: 7 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -244,10 +244,15 @@ server: Server;
244
244
Also, you can retrieve the corresponding namespace using the `namespace` attribute, as follows:
245
245
246
246
```typescript
247
-
@WebSocketServer({ namespace: 'my-namespace' })
248
-
namespace: Namespace;
247
+
@WebSocketGateway({ namespace: 'my-namespace' })
248
+
exportclassEventsGateway {
249
+
@WebSocketServer()
250
+
namespace:Namespace;
251
+
}
249
252
```
250
253
254
+
`@WebSocketServer()` decorator injects a server instance by referencing the metadata stored by the `@WebSocketGateway()` decorator. If you provide the namespace option to the `@WebSocketGateway()` decorator, `@WebSocketServer()` decorator returns a `Namespace` instance instead of a `Server` instance.
255
+
251
256
> warning **Notice** The `@WebSocketServer()` decorator is imported from the `@nestjs/websockets` package.
252
257
253
258
Nest will automatically assign the server instance to this property once it is ready to use.
0 commit comments