diff --git a/lib/socket.ts b/lib/socket.ts index e7143285..6fc2f0d7 100644 --- a/lib/socket.ts +++ b/lib/socket.ts @@ -12,22 +12,24 @@ export interface SendOptions { compress?: boolean; } +type ReadyState = "opening" | "open" | "closing" | "closed"; + export class Socket extends EventEmitter { public readonly protocol: number; // TODO for the next major release: do not keep the reference to the first HTTP request, as it stays in memory public readonly request: IncomingMessage; public readonly remoteAddress: string; - public _readyState: string; + public _readyState: ReadyState = "opening"; public transport: Transport; private server: Server; - private upgrading: boolean; - private upgraded: boolean; - private writeBuffer: Packet[]; - private packetsFn: Array<() => void>; - private sentCallbackFn: any[]; - private cleanupFn: any[]; + private upgrading = false; + private upgraded = false; + private writeBuffer: Packet[] = []; + private packetsFn: Array<() => void> = []; + private sentCallbackFn: any[] = []; + private cleanupFn: any[] = []; private pingTimeoutTimer; private pingIntervalTimer; @@ -43,7 +45,7 @@ export class Socket extends EventEmitter { return this._readyState; } - set readyState(state) { + set readyState(state: ReadyState) { debug("readyState updated from %s to %s", this._readyState, state); this._readyState = state; } @@ -57,13 +59,6 @@ export class Socket extends EventEmitter { super(); this.id = id; this.server = server; - this.upgrading = false; - this.upgraded = false; - this.readyState = "opening"; - this.writeBuffer = []; - this.packetsFn = []; - this.sentCallbackFn = []; - this.cleanupFn = []; this.request = req; this.protocol = protocol; @@ -179,7 +174,7 @@ export class Socket extends EventEmitter { /** * Called upon transport error. * - * @param {Error} error object + * @param {Error} err - error object * @api private */ private onError(err) { diff --git a/lib/transport.ts b/lib/transport.ts index aa2a0bd3..b0777bca 100644 --- a/lib/transport.ts +++ b/lib/transport.ts @@ -15,13 +15,15 @@ const debug = debugModule("engine:transport"); function noop() {} +type ReadyState = "open" | "closing" | "closed"; + export abstract class Transport extends EventEmitter { public sid: string; - public writable: boolean; + public writable = false; public protocol: number; - protected _readyState: string; - protected discarded: boolean; + protected _readyState: ReadyState = "open"; + protected discarded = false; protected parser: any; protected req: IncomingMessage & { cleanup: Function }; protected supportsBinary: boolean; @@ -30,7 +32,7 @@ export abstract class Transport extends EventEmitter { return this._readyState; } - set readyState(state) { + set readyState(state: ReadyState) { debug( "readyState updated from %s to %s (%s)", this._readyState, @@ -43,13 +45,11 @@ export abstract class Transport extends EventEmitter { /** * Transport constructor. * - * @param {http.IncomingMessage} request + * @param {http.IncomingMessage} req * @api public */ constructor(req) { super(); - this.readyState = "open"; - this.discarded = false; this.protocol = req._query.EIO === "4" ? 4 : 3; // 3rd revision by default this.parser = this.protocol === 4 ? parser_v4 : parser_v3; this.supportsBinary = !(req._query && req._query.b64); @@ -67,7 +67,7 @@ export abstract class Transport extends EventEmitter { /** * Called with an incoming HTTP request. * - * @param {http.IncomingMessage} request + * @param {http.IncomingMessage} req * @api protected */ protected onRequest(req) { @@ -90,8 +90,8 @@ export abstract class Transport extends EventEmitter { /** * Called with a transport error. * - * @param {String} message error - * @param {Object} error description + * @param {String} msg - message error + * @param {Object} desc - error description * @api protected */ protected onError(msg: string, desc?) {