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 }); }