diff --git a/src/network.ts b/src/network.ts index 834349b..349f2d9 100644 --- a/src/network.ts +++ b/src/network.ts @@ -115,14 +115,26 @@ export default class RpcNetwork { this.setupRelayPromise(); this._swarm.on("connection", async (relay: any) => { + const pubkey = b4a.from(relay.remotePublicKey).toString("hex"); + relay.on("close", () => { + this._methods.forEach((item) => { + if (item.has(pubkey)) { + item.delete(pubkey); + } + }); + this.relays.delete(pubkey); + + if (!this._relays.size) { + this.setupRelayPromise(); + } + }); + const query = this._factory.simple({ relay, query: { module: "core", method: "get_methods", data: null }, }); const resp = await query.result; - const pubkey = b4a.from(relay.remotePublicKey).toString("hex"); - if (resp.data) { this._relays.set(pubkey, relay); @@ -135,19 +147,6 @@ export default class RpcNetwork { }); this._relaysAvailableResolve?.(); } - - relay.on("close", () => { - this._methods.forEach((item) => { - if (item.has(pubkey)) { - item.delete(pubkey); - } - }); - this.relays.delete(pubkey); - - if (!this._relays.size) { - this.setupRelayPromise(); - } - }); }); }