# All files / websockets container.ts

100% Statements 6/6
100% Branches 2/2
100% Functions 5/5
100% Lines 6/6

    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

    1x
    6x

    1x

    1x

    3x

    1x

     import { ObservableSocketServer } from './interfaces';

    export class SocketsContainer {
      private readonly observableServers = new Map<
        string,
        ObservableSocketServer
      >();

      public getAllServers(): Map<string, ObservableSocketServer> {
        return this.observableServers;
      }

      public getServerByPort(port: number): ObservableSocketServer {
        return this.observableServers.get(`${port}`);
      }

      public addServer(
        namespace: string,
        port: number,
        server: ObservableSocketServer,
      ) {
        this.observableServers.set(
          namespace ? `${namespace}:${port}` : `${port}`,
          server,
        );
      }

      public clear() {
        this.observableServers.clear();
      }
    }