ConnectionMapper.ts 525 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);
    // FIXME: Register connection to the map
    return value;
  }

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