Skip to content

Commit

Permalink
Merge pull request #5194 from WalletConnect/refactor/reduce-reconnect…
Browse files Browse the repository at this point in the history
…-timeout

refactor: reduce reconnect timeout
  • Loading branch information
ganchoradkov authored Jul 17, 2024
2 parents a27685c + 3c05414 commit 87150a2
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
4 changes: 1 addition & 3 deletions packages/core/src/constants/relayer.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { ONE_SECOND } from "@walletconnect/time";

export const RELAYER_DEFAULT_PROTOCOL = "irn";

export const RELAYER_DEFAULT_LOGGER = "error";
Expand Down Expand Up @@ -28,7 +26,7 @@ export const RELAYER_PROVIDER_EVENTS = {
error: "error",
};

export const RELAYER_RECONNECT_TIMEOUT = ONE_SECOND;
export const RELAYER_RECONNECT_TIMEOUT = 0.1;

export const RELAYER_STORAGE_OPTIONS = {
database: ":memory:",
Expand Down
7 changes: 6 additions & 1 deletion packages/core/src/controllers/relayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,10 @@ export class Relayer extends IRelayer {
).catch((e) => {
reject(e);
});
await this.subscriber.start();
this.subscriber.start().catch((error) => {
this.logger.error(error);
this.onDisconnectHandler();
});
this.hasExperiencedNetworkDisruption = false;
resolve();
});
Expand Down Expand Up @@ -474,11 +477,13 @@ export class Relayer extends IRelayer {
};

private onConnectHandler = () => {
this.logger.trace("relayer connected");
this.startPingTimeout();
this.events.emit(RELAYER_EVENTS.connect);
};

private onDisconnectHandler = () => {
this.logger.trace("relayer disconnected");
this.onProviderDisconnect();
};

Expand Down
2 changes: 1 addition & 1 deletion packages/core/test/relayer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ describe("Relayer", () => {
const randomSessionIdentifier = relayer.core.crypto.randomSessionIdentifier;
await relayer.provider.connection.close();
expect(relayer.connected).to.be.false;
await relayer.restartTransport();
await throttle(1000);
expect(relayer.connected).to.be.true;
// the identifier should be the same
expect(relayer.core.crypto.randomSessionIdentifier).to.eq(randomSessionIdentifier);
Expand Down

0 comments on commit 87150a2

Please sign in to comment.