{
  "version": 3,
  "sources": ["../src/Transport.ts"],
  "sourcesContent": ["import * as http from 'http';\nimport * as https from 'https';\nimport * as net from 'net';\n\nimport { Schema, StateView } from '@colyseus/schema';\nimport { EventEmitter } from 'events';\nimport { spliceOne } from './utils/Utils.js';\n\nexport abstract class Transport {\n    public protocol?: string;\n    public server?: net.Server | http.Server | https.Server;\n\n    public abstract listen(port?: number, hostname?: string, backlog?: number, listeningListener?: Function): this;\n    public abstract shutdown(): void;\n\n    public abstract simulateLatency(milliseconds: number): void;\n}\n\nexport type AuthContext = {\n  token?: string,\n  headers: http.IncomingHttpHeaders,\n  ip: string | string[];\n  // FIXME: each transport may have its own specific properties.\n  // \"req\" only applies to WebSocketTransport.\n  req?: http.IncomingMessage;\n};\n\nexport interface ISendOptions {\n  afterNextPatch?: boolean;\n}\n\nexport enum ClientState { JOINING, JOINED, RECONNECTED, LEAVING, CLOSED }\n\n/**\n * The client instance from the server-side is responsible for the transport layer between the server and the client.\n * It should not be confused with the Client from the client-side SDK, as they have completely different purposes!\n * You operate on client instances from `this.clients`, `Room#onJoin()`, `Room#onLeave()` and `Room#onMessage()`.\n *\n * - This is the raw WebSocket connection coming from the `ws` package. There are more methods available which aren't\n *  encouraged to use along with Colyseus.\n */\nexport interface Client<UserData=any, AuthData=any> {\n  ref: EventEmitter;\n\n  /**\n   * @deprecated use `sessionId` instead.\n   */\n  id: string;\n\n  /**\n   * Unique id per session.\n   */\n  sessionId: string; // TODO: remove sessionId on version 1.0.0\n\n  /**\n   * Connection state\n   */\n  state: ClientState;\n\n  /**\n   * Optional: when using `@view()` decorator in your state properties, this will be the view instance for this client.\n   */\n  view?: StateView;\n\n  /**\n   * User-defined data can be attached to the Client instance through this variable.\n   * - Can be used to store custom data about the client's connection. userData is not synchronized with the client,\n   * and should be used only to keep player-specific with its connection.\n   */\n  userData?: UserData;\n\n  /**\n   * auth data provided by your `onAuth`\n   */\n  auth?: AuthData;\n\n  /**\n   * Reconnection token used to re-join the room after onLeave + allowReconnection().\n   *\n   * IMPORTANT:\n   *    This is not the full reconnection token the client provides for the server.\n   *    The format provided by .reconnect() from the client-side must follow: \"${roomId}:${reconnectionToken}\"\n   */\n  reconnectionToken: string;\n\n  raw(data: Uint8Array | Buffer, options?: ISendOptions, cb?: (err?: Error) => void): void;\n  enqueueRaw(data: Uint8Array | Buffer, options?: ISendOptions): void;\n\n  /**\n   * Send a type of message to the client. Messages are encoded with MsgPack and can hold any\n   * JSON-serializable data structure.\n   *\n   * @param type String or Number identifier the client SDK will use to receive this message\n   * @param message Message payload. (automatically encoded with msgpack.)\n   * @param options\n   */\n  send(type: string | number, message?: any, options?: ISendOptions): void;\n  send(message: Schema, options?: ISendOptions): void;\n\n  /**\n   * Send raw bytes to this specific client.\n   *\n   * @param type String or Number identifier the client SDK will use to receive this message\n   * @param bytes Raw byte array payload\n   * @param options\n   */\n  sendBytes(type: string | number, bytes: Buffer | Uint8Array, options?: ISendOptions): void;\n\n  /**\n   * Disconnect this client from the room.\n   *\n   * @param code Custom close code. Default value is 1000.\n   * @param data\n   * @see {@link https://docs.colyseus.io/colyseus/server/room/#leavecode-number}\n   */\n  leave(code?: number, data?: string): void;\n\n  /**\n   * @deprecated Use .leave() instead.\n   */\n  close(code?: number, data?: string): void;\n\n  /**\n   * Triggers `onError` with specified code to the client-side.\n   *\n   * @param code\n   * @param message\n   */\n  error(code: number, message?: string): void;\n}\n\n/**\n * Private properties of the Client instance.\n * Only accessible internally by the framework, should not be encouraged/auto-completed for the user.\n *\n * TODO: refactor this.\n * @private\n */\nexport interface ClientPrivate {\n  readyState: number; // TODO: remove readyState on version 1.0.0. Use only \"state\" instead.\n  _enqueuedMessages?: any[];\n  _afterNextPatchQueue: Array<[string | Client, IArguments]>;\n  _joinedAt: number; // \"elapsedTime\" when the client joined the room.\n}\n\nexport class ClientArray<UserData = any, AuthData = any> extends Array<Client<UserData, AuthData>> {\n  public getById(sessionId: string): Client<UserData, AuthData> | undefined {\n    return this.find((client) => client.sessionId === sessionId);\n  }\n\n  public delete(client: Client<UserData, AuthData>): boolean {\n    return spliceOne(this, this.indexOf(client));\n  }\n}"],
  "mappings": ";AAMA,SAAS,iBAAiB;AAEnB,IAAe,YAAf,MAAyB;AAQhC;AAeO,IAAK,cAAL,kBAAKA,iBAAL;AAAmB,EAAAA,0BAAA;AAAS,EAAAA,0BAAA;AAAQ,EAAAA,0BAAA;AAAa,EAAAA,0BAAA;AAAS,EAAAA,0BAAA;AAArD,SAAAA;AAAA,GAAA;AAkHL,IAAM,cAAN,cAA0D,MAAkC;AAAA,EAC1F,QAAQ,WAA2D;AACxE,WAAO,KAAK,KAAK,CAAC,WAAW,OAAO,cAAc,SAAS;AAAA,EAC7D;AAAA,EAEO,OAAO,QAA6C;AACzD,WAAO,UAAU,MAAM,KAAK,QAAQ,MAAM,CAAC;AAAA,EAC7C;AACF;",
  "names": ["ClientState"]
}
