Skip to content

Reason

@tsed/socketio

Usage

typescript
import { Reason } from "@tsed/socketio";

See /packages/third-parties/socketio/src/types/decorators/reason.ts.

Overview

ts
function Reason(target: unknown, propertyKey: string, index: number): void;

Description

Inject the disconnection reason into the decorated parameter.

This decorator is used in conjunction with the $onDisconnect event handler to handle disconnection reasons in SocketIO services. It allows you to access the reason for the disconnection in your method implementation. For details please refer to the Socket.io documentation.

typescript
@SocketService("/nsp")
export class MyWS {
  public async $onDisconnect(
    @Reason reason: string = ''
  ) {
     // your implementation
  }
}

Released under the MIT License.