*hook close event before querying
This commit is contained in:
parent
d572e39a65
commit
e9e25b2573
|
@ -115,14 +115,26 @@ export default class RpcNetwork {
|
||||||
this.setupRelayPromise();
|
this.setupRelayPromise();
|
||||||
|
|
||||||
this._swarm.on("connection", async (relay: any) => {
|
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({
|
const query = this._factory.simple({
|
||||||
relay,
|
relay,
|
||||||
query: { module: "core", method: "get_methods", data: null },
|
query: { module: "core", method: "get_methods", data: null },
|
||||||
});
|
});
|
||||||
const resp = await query.result;
|
const resp = await query.result;
|
||||||
|
|
||||||
const pubkey = b4a.from(relay.remotePublicKey).toString("hex");
|
|
||||||
|
|
||||||
if (resp.data) {
|
if (resp.data) {
|
||||||
this._relays.set(pubkey, relay);
|
this._relays.set(pubkey, relay);
|
||||||
|
|
||||||
|
@ -135,19 +147,6 @@ export default class RpcNetwork {
|
||||||
});
|
});
|
||||||
this._relaysAvailableResolve?.();
|
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();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue