From b76aa38f765b52bc681beccea093789755da633f Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Fri, 17 Feb 2023 08:49:35 -0500 Subject: [PATCH] *Move listenConnections call to private method that will do a backoff connection after returning --- src/index.ts | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/index.ts b/src/index.ts index d5ea156..3ce62e4 100644 --- a/src/index.ts +++ b/src/index.ts @@ -50,13 +50,7 @@ export class SwarmClient extends Client { return this._ready; } - this.connectModule( - "listenConnections", - { swarm: this.swarm }, - async (socketId: any) => { - this.emit("connection", await createSocket(socketId)); - } - ); + this._listen(); this._ready = this.callModuleReturn("ready", { swarm: this.swarm }); @@ -80,6 +74,19 @@ export class SwarmClient extends Client { await this.ready(); } + private async _listen() { + const connect = this.connectModule( + "listenConnections", + { swarm: this.swarm }, + async (socketId: any) => { + this.emit("connection", await createSocket(socketId)); + } + ); + + await connect[1]; + this._connectBackoff.backoff(); + } + public async addRelay(pubkey: string): Promise { return this.callModuleReturn("addRelay", { pubkey, swarm: this.swarm }); }