Skip to content

Commit 39937f8

Browse files
refactor: minor cleanups
1 parent 43c1c1c commit 39937f8

File tree

2 files changed

+21
-26
lines changed

2 files changed

+21
-26
lines changed

lib/socket.ts

+11-16
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,24 @@ export interface SendOptions {
1212
compress?: boolean;
1313
}
1414

15+
type ReadyState = "opening" | "open" | "closing" | "closed";
16+
1517
export class Socket extends EventEmitter {
1618
public readonly protocol: number;
1719
// TODO for the next major release: do not keep the reference to the first HTTP request, as it stays in memory
1820
public readonly request: IncomingMessage;
1921
public readonly remoteAddress: string;
2022

21-
public _readyState: string;
23+
public _readyState: ReadyState = "opening";
2224
public transport: Transport;
2325

2426
private server: Server;
25-
private upgrading: boolean;
26-
private upgraded: boolean;
27-
private writeBuffer: Packet[];
28-
private packetsFn: Array<() => void>;
29-
private sentCallbackFn: any[];
30-
private cleanupFn: any[];
27+
private upgrading = false;
28+
private upgraded = false;
29+
private writeBuffer: Packet[] = [];
30+
private packetsFn: Array<() => void> = [];
31+
private sentCallbackFn: any[] = [];
32+
private cleanupFn: any[] = [];
3133
private pingTimeoutTimer;
3234
private pingIntervalTimer;
3335

@@ -43,7 +45,7 @@ export class Socket extends EventEmitter {
4345
return this._readyState;
4446
}
4547

46-
set readyState(state) {
48+
set readyState(state: ReadyState) {
4749
debug("readyState updated from %s to %s", this._readyState, state);
4850
this._readyState = state;
4951
}
@@ -57,13 +59,6 @@ export class Socket extends EventEmitter {
5759
super();
5860
this.id = id;
5961
this.server = server;
60-
this.upgrading = false;
61-
this.upgraded = false;
62-
this.readyState = "opening";
63-
this.writeBuffer = [];
64-
this.packetsFn = [];
65-
this.sentCallbackFn = [];
66-
this.cleanupFn = [];
6762
this.request = req;
6863
this.protocol = protocol;
6964

@@ -179,7 +174,7 @@ export class Socket extends EventEmitter {
179174
/**
180175
* Called upon transport error.
181176
*
182-
* @param {Error} error object
177+
* @param {Error} err - error object
183178
* @api private
184179
*/
185180
private onError(err) {

lib/transport.ts

+10-10
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,15 @@ const debug = debugModule("engine:transport");
1515

1616
function noop() {}
1717

18+
type ReadyState = "open" | "closing" | "closed";
19+
1820
export abstract class Transport extends EventEmitter {
1921
public sid: string;
20-
public writable: boolean;
22+
public writable = false;
2123
public protocol: number;
2224

23-
protected _readyState: string;
24-
protected discarded: boolean;
25+
protected _readyState: ReadyState = "open";
26+
protected discarded = false;
2527
protected parser: any;
2628
protected req: IncomingMessage & { cleanup: Function };
2729
protected supportsBinary: boolean;
@@ -30,7 +32,7 @@ export abstract class Transport extends EventEmitter {
3032
return this._readyState;
3133
}
3234

33-
set readyState(state) {
35+
set readyState(state: ReadyState) {
3436
debug(
3537
"readyState updated from %s to %s (%s)",
3638
this._readyState,
@@ -43,13 +45,11 @@ export abstract class Transport extends EventEmitter {
4345
/**
4446
* Transport constructor.
4547
*
46-
* @param {http.IncomingMessage} request
48+
* @param {http.IncomingMessage} req
4749
* @api public
4850
*/
4951
constructor(req) {
5052
super();
51-
this.readyState = "open";
52-
this.discarded = false;
5353
this.protocol = req._query.EIO === "4" ? 4 : 3; // 3rd revision by default
5454
this.parser = this.protocol === 4 ? parser_v4 : parser_v3;
5555
this.supportsBinary = !(req._query && req._query.b64);
@@ -67,7 +67,7 @@ export abstract class Transport extends EventEmitter {
6767
/**
6868
* Called with an incoming HTTP request.
6969
*
70-
* @param {http.IncomingMessage} request
70+
* @param {http.IncomingMessage} req
7171
* @api protected
7272
*/
7373
protected onRequest(req) {
@@ -90,8 +90,8 @@ export abstract class Transport extends EventEmitter {
9090
/**
9191
* Called with a transport error.
9292
*
93-
* @param {String} message error
94-
* @param {Object} error description
93+
* @param {String} msg - message error
94+
* @param {Object} desc - error description
9595
* @api protected
9696
*/
9797
protected onError(msg: string, desc?) {

0 commit comments

Comments
 (0)