Closed Emeryx closed 3 months ago
That's the expected behavior. If you feel that our documentation is misleading, please create a PR here https://github.com/nestjs/docs.nestjs.com/edit/master/content/websockets/gateways.md - contributions are more than welcome
Is there an existing issue for this?
Current behavior
When using a WebSocket gateway in NestJS, the handleConnection method is reserved for lifecycle handling. However, there is no clear documentation indicating this reservation. If a user defines their own handleConnection method, it gets called on every connection, regardless of the @SubscribeMessage decorator.
This is also relevant to methods named handleDisconnect, Which I assume activate when the client disconnects, Though I only tried handleConnection.
Minimum reproduction code
https://stackblitz.com/edit/typescript-gvcfjr?file=events.gateway.ts
Steps to reproduce
Expected behavior
A clear warning should be provided if handleConnection is defined, indicating its reserved nature for WebSocket lifecycle management. Alternatively, the documentation should clearly state the reservation of the handleConnection method to prevent such conflicts.
Package
Other package
No response
NestJS version
10.0.0
Packages versions
Node.js version
No response
In which operating systems have you tested?
Other
No response