*Move listenConnections call to private method that will do a backoff connection after returning

This commit is contained in:
Derrick Hammer 2023-02-17 08:49:35 -05:00
parent 7d031231a3
commit b76aa38f76
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 14 additions and 7 deletions

View File

@ -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<void> {
return this.callModuleReturn("addRelay", { pubkey, swarm: this.swarm });
}