Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 9951393

Browse files
Merge pull request #3314 from chsjen492/docs/websocketserver-decorator
docs(websockets): clarify @WebSocketServer() with namespace
2 parents 36f5d77 + 7e76a85 commit 9951393

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)

AltStyle によって変換されたページ (->オリジナル) /