ConnectionMapper.ts 480 Bytes
import { Socket } from "socket.io";
import { Connection } from "./Connection";

export class ConnectionMapper {
  private map: Map<Socket, Connection>;

  constructor() {
    this.map = new Map<Socket, Connection>();
  }

  public get(socket: Socket): Connection {
    var value = this.map.get(socket);
    if (value) {
      return value;
    }

    value = new Connection(socket);
    return value;
  }

  public close(socket: Socket): void {
    this.map.delete(socket);
  }
}