# All files / websockets/utils socket-gateway.decorator.ts

100% Statements 10/10
100% Branches 4/4
100% Functions 2/2
100% Lines 10/10

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    1x

    1x

    7x

    7x

    7x
    7x
    7x
    7x
    7x
    7x

     import { GatewayMetadata } from '../interfaces';
    import {
      PORT_METADATA,
      GATEWAY_METADATA,
      GATEWAY_OPTIONS,
      GATEWAY_MIDDLEWARES,
    } from '../constants';

    /**
     * Defines the Gateway. The gateway is able to inject dependencies through constructor.
     * Those dependencies should belong to the same module. Gateway is listening on the specified port.
     */
    export function WebSocketGateway(port?: number);
    export function WebSocketGateway(options?: GatewayMetadata | any);
    export function WebSocketGateway(port?: number, options?: GatewayMetadata | any);
    export function WebSocketGateway(
      portOrOptions?: number | GatewayMetadata | any,
      options?: GatewayMetadata | any,
    ): ClassDecorator {
      const isPortInt = Number.isInteger(portOrOptions as number);
      // tslint:disable-next-line:prefer-const
      let [port, opt] = isPortInt
        ? [portOrOptions, options]
        : [0, portOrOptions];

      opt = opt || {};
      return (target: object) => {
        Reflect.defineMetadata(GATEWAY_METADATA, true, target);
        Reflect.defineMetadata(PORT_METADATA, port, target);
        Reflect.defineMetadata(GATEWAY_OPTIONS, opt, target);
        Reflect.defineMetadata(GATEWAY_MIDDLEWARES, opt.middleware, target);
      };
    }