Skip to content

Commit

Permalink
refactor: minor changes to reconnection (#74)
Browse files Browse the repository at this point in the history
  • Loading branch information
moliva authored Feb 26, 2020
1 parent 090708a commit 6432cbe
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion comms/peer/src/Peer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ export class Peer implements IPeer {
const { reconnectionAttempts, backoffMs } = this.config;

for (let i = 1; i <= reconnectionAttempts!; ++i) {
this.log(LogLevel.INFO, `attempt `, i);
this.log(LogLevel.DEBUG, `Connection attempt `, i);
// To avoid synced retries, we use a random delay
await delay(backoffMs! + Math.floor(Math.random() * backoffMs!));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,9 @@ export class PeerJSServerConnection extends EventEmitter {
// If we haven't explicitly disconnected, emit error and disconnect.
if (!this.disconnected) {
this.emitError(PeerErrorType.Network, "Lost connection to server.");
this.disconnect();
this.disconnect().catch(() => {
// do nothing
});
}
});

Expand Down Expand Up @@ -300,7 +302,9 @@ export class PeerJSServerConnection extends EventEmitter {

this.emitError(type, message);

this.disconnect();
this.disconnect().catch(() => {
// do nothing
});
}

/** Emits a typed error message. */
Expand Down Expand Up @@ -352,6 +356,7 @@ export class PeerJSServerConnection extends EventEmitter {
} else if (!this.disconnected && !this.open) {
// Do nothing. We're still connecting the first time.
logger.error("In a hurry? We're still trying to make the initial connection!");
reject(new Error("Still making initial connection"));
} else {
reject(new Error("Peer " + this.id + " cannot reconnect because it is not disconnected from the server!"));
}
Expand Down

0 comments on commit 6432cbe

Please sign in to comment.