Skip to content

support disconnect reason to handleDisconnect argsΒ #15437

@yizumi1012xxx

Description

@yizumi1012xxx

Is there an existing issue that is already proposing this?

  • I have searched the existing issues

Is your feature request related to a problem? Please describe it

I use @nestjs/websocket.
https://docs.nestjs.com/websockets/gateways

To add disconnect event handler, OnGatewayDisconnect lifecycle hook is useful.
But this hook is not able to get disconnect reason.

Describe the solution you'd like

My code is below. (handleDisconnect can not get disconnect reason.)

export class EventsGateway implements OnGatewayConnection<Socket> {
  async handleConnection(socket: Socket) {
    // add disconnect handler manually.
    socket.on('disconnect', async reason => {
      await this._handleDisconnect(socket, reason)
    })
  }

  async _handleDisconnect(socket: Socket, reason: DisconnectReason) {
    // handle disconnect
  }
}

Expect code is below. (handleDisconnect can get disconnect reason.)

export class EventsGateway implements OnGatewayConnection<Socket>, OnGatewayDisconnect <Socket> {
  async handleConnection(socket: Socket) {
    // handle connect
  }

  async handleDisconnect(socket: Socket, reason: DisconnectReason) {
    // handle disconnect
  }
}

Teachability, documentation, adoption, migration strategy

n/a

What is the motivation / use case for changing the behavior?

n/a

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions