Skip to content

Commit 7e76a85

Browse files
committed
docs(websockets): clarify @WebSocketServer() with namespace
1 parent 36f5d77 commit 7e76a85

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

content/websockets/gateways.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,10 +244,15 @@ server: Server;
244244
Also, you can retrieve the corresponding namespace using the `namespace` attribute, as follows:
245245

246246
```typescript
247-
@WebSocketServer({ namespace: 'my-namespace' })
248-
namespace: Namespace;
247+
@WebSocketGateway({ namespace: 'my-namespace' })
248+
export class EventsGateway {
249+
@WebSocketServer()
250+
namespace: Namespace;
251+
}
249252
```
250253

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+
251256
> warning **Notice** The `@WebSocketServer()` decorator is imported from the `@nestjs/websockets` package.
252257
253258
Nest will automatically assign the server instance to this property once it is ready to use.

0 commit comments

Comments
 (0)