'How to get "disconnecting" event Nest SocketIO
I have a problem to get all room that socket client currently in when this client disconnect, by using
async handleDisconnect(client: Socket) {
console.log(client.rooms) // result is {}
}
but Nest-SocketIO only return list rooms as {}. As I known, in socketIO we can use:
socket.on("disconnecting", ()=>{
console.log(socket.rooms // return all room current
}
How can I use this features in NestJS-SOcketIO ? Thanks for all.
Solution 1:[1]
I got this working by attaching event handler on connection.
handleConnection(client: Socket, ...args: any[]) {
this.logger.log(`Client connected: ${client.id}`);
client.on('disconnecting', (reason) => {
this.logger.log(`DISCONNECTING: ${Array.from(client.rooms)}`); // Set { ... }
});
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Phyo Lim |
