I hit this while moving a NestJS gateway from socket.io to UwsAdapter on 2.0.1 (also reproduced on current main).
Two related problems in the adapter:
-
There is no upgrade handler on the uWS route, so the HTTP upgrade request is dropped. The gateway has no way to read the query string or the headers of the connection: auth tokens, user agent, forwarded IPs, none of it is reachable. client.handshake simply doesn't exist anywhere.
-
handleConnection/handleDisconnect receive the raw uWS socket, while message handlers get the wrapped UwsSocketImpl via @ConnectedSocket. They are different objects with separate data, so anything attached to client.data in handleConnection is invisible to the handlers. It also means the first example in docs/websocket/Lifecycle.md crashes at runtime:
handleConnection(client: UwsSocket) {
client.emit('welcome', { message: 'Hello!' }); // TypeError: client.emit is not a function
}
The docs already type the hook parameter as UwsSocket, so I think the implementation just never caught up with them.
Repro is small: register a gateway that sets client.data in handleConnection and reads it back in a @SubscribeMessage handler. The handler sees an empty object. Or run the Lifecycle.md example above and watch it throw.
I have a fix ready with e2e coverage (upgrade request captured into socket.handshake with url/parsed query/headers/remote address, and the hooks getting the same wrapped instance the handlers get). PR follows right after this issue. I read the contributing note about waiting for assignment, but since this is a new report with the patch already written I hope it's fine to attach it directly. Happy to rework or split it if you prefer.
I hit this while moving a NestJS gateway from socket.io to UwsAdapter on 2.0.1 (also reproduced on current main).
Two related problems in the adapter:
There is no
upgradehandler on the uWS route, so the HTTP upgrade request is dropped. The gateway has no way to read the query string or the headers of the connection: auth tokens, user agent, forwarded IPs, none of it is reachable.client.handshakesimply doesn't exist anywhere.handleConnection/handleDisconnectreceive the raw uWS socket, while message handlers get the wrappedUwsSocketImplvia@ConnectedSocket. They are different objects with separatedata, so anything attached toclient.datainhandleConnectionis invisible to the handlers. It also means the first example in docs/websocket/Lifecycle.md crashes at runtime:The docs already type the hook parameter as
UwsSocket, so I think the implementation just never caught up with them.Repro is small: register a gateway that sets
client.datainhandleConnectionand reads it back in a@SubscribeMessagehandler. The handler sees an empty object. Or run the Lifecycle.md example above and watch it throw.I have a fix ready with e2e coverage (upgrade request captured into
socket.handshakewith url/parsed query/headers/remote address, and the hooks getting the same wrapped instance the handlers get). PR follows right after this issue. I read the contributing note about waiting for assignment, but since this is a new report with the patch already written I hope it's fine to attach it directly. Happy to rework or split it if you prefer.