Skip to content

Commit

Permalink
refactor: replace the disconnected attribute by a getter
Browse files Browse the repository at this point in the history
  • Loading branch information
darrachequesne committed Apr 23, 2022
1 parent 74e3e60 commit e859018
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions lib/socket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ export class Socket<

public id: string;
public connected: boolean = false;
public disconnected: boolean = true;

public auth: { [key: string]: any } | ((cb: (data: object) => void) => void);
public receiveBuffer: Array<ReadonlyArray<any>> = [];
Expand Down Expand Up @@ -93,6 +92,13 @@ export class Socket<
if (this.io._autoConnect) this.open();
}

/**
* Whether the socket is currently disconnected
*/
public get disconnected(): boolean {
return !this.connected;
}

/**
* Subscribe to open, close and packet events
*
Expand Down Expand Up @@ -287,7 +293,6 @@ export class Socket<
): void {
debug("close (%s)", reason);
this.connected = false;
this.disconnected = true;
delete this.id;
this.emitReserved("disconnect", reason, description);
}
Expand Down Expand Up @@ -319,17 +324,11 @@ export class Socket<
break;

case PacketType.EVENT:
this.onevent(packet);
break;

case PacketType.BINARY_EVENT:
this.onevent(packet);
break;

case PacketType.ACK:
this.onack(packet);
break;

case PacketType.BINARY_ACK:
this.onack(packet);
break;
Expand Down Expand Up @@ -428,7 +427,6 @@ export class Socket<
debug("socket connected with id %s", id);
this.id = id;
this.connected = true;
this.disconnected = false;
this.emitBuffered();
this.emitReserved("connect");
}
Expand Down

0 comments on commit e859018

Please sign in to comment.