nestjs / nest

A progressive Node.js framework for building efficient, scalable, and enterprise-grade server-side applications with TypeScript/JavaScript 🚀
https://nestjs.com
MIT License
67.69k stars 7.63k forks source link

Sockets. How to catch on disconnect event ? #1235

Closed bcba25 closed 6 years ago

bcba25 commented 6 years ago

I'm submitting a...


[ ] Regression 
[ ] Bug report
[ ] Feature request
[X] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.

Current behavior

There is a function called handleConnection in a WebSocketGateway which allows me to track connected users. But how do I catch those who was disconnected ? I've tried to write something like this:

@SubscribeMessage('disconnect')
    onDisconnect(client, data) {
        console.log('user disconnected');
    }

but this event is never called.

Environment


Nest version: 5.5.0
kamilmysliwiec commented 6 years ago

Hi @hxdef2517, See https://docs.nestjs.com/websockets/gateways Lifecycle hooks section.

lock[bot] commented 5 years ago

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.