Skip to content

Commit

Permalink
refactor: minor cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
darrachequesne committed Nov 9, 2023
1 parent 43c1c1c commit 39937f8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 26 deletions.
27 changes: 11 additions & 16 deletions lib/socket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
}
Expand All @@ -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;

Expand Down Expand Up @@ -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) {
Expand Down
20 changes: 10 additions & 10 deletions lib/transport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
Expand All @@ -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);
Expand All @@ -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) {
Expand All @@ -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?) {
Expand Down

0 comments on commit 39937f8

Please sign in to comment.