*Change ready to init
*Add new ready method that listens for a ready event but returns if activeRelay is set
This commit is contained in:
parent
4e443f4ccb
commit
236e445ff8
23
src/index.ts
23
src/index.ts
|
@ -49,6 +49,7 @@ addHandler("addRelay", handleAddRelay);
|
||||||
addHandler("removeRelay", handleRemoveRelay);
|
addHandler("removeRelay", handleRemoveRelay);
|
||||||
addHandler("clearRelays", handleClearRelays);
|
addHandler("clearRelays", handleClearRelays);
|
||||||
addHandler("getRelays", handleGetRelays);
|
addHandler("getRelays", handleGetRelays);
|
||||||
|
addHandler("init", handleInit);
|
||||||
addHandler("ready", handleReady);
|
addHandler("ready", handleReady);
|
||||||
|
|
||||||
async function handlePresentSeed(aq: ActiveQuery) {
|
async function handlePresentSeed(aq: ActiveQuery) {
|
||||||
|
@ -282,9 +283,25 @@ async function handleGetPeerByPubkey(aq: ActiveQuery) {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function handleReady(aq: ActiveQuery) {
|
async function handleInit(aq: ActiveQuery) {
|
||||||
const swarm = await getSwarm(aq);
|
const swarm = await getSwarm(aq);
|
||||||
// @ts-ignore
|
try {
|
||||||
await swarm.ready();
|
await swarm.init();
|
||||||
|
} catch (e) {
|
||||||
|
aq.reject((e as Error).message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
aq.respond();
|
aq.respond();
|
||||||
}
|
}
|
||||||
|
async function handleReady(aq: ActiveQuery) {
|
||||||
|
const swarm = await getSwarm(aq);
|
||||||
|
|
||||||
|
if (swarm.activeRelay) {
|
||||||
|
aq.respond();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
swarm.once("ready", () => {
|
||||||
|
aq.respond();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue