fix: add endPeerOnError handler

This commit is contained in:
Derrick Hammer 2023-07-22 10:28:31 -04:00
parent 1bb59e1079
commit 57f1e40eff
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 11 additions and 1 deletions

View File

@ -1,6 +1,10 @@
import { addHandler, handleMessage } from "@lumeweb/libkernel/module";
import type { ActiveQuery } from "@lumeweb/libkernel/module";
import { createClient, SwarmClient } from "@lumeweb/kernel-swarm-client";
import {
createClient,
Socket,
SwarmClient,
} from "@lumeweb/kernel-swarm-client";
import { RpcNetwork, RpcQueryOptions, setupStream } from "@lumeweb/rpc-client";
import type { RPCRequest, RPCResponse } from "@lumeweb/interface-relay";
@ -102,6 +106,12 @@ async function createNetwork(def = true): Promise<number> {
dhtInstance.swarm.on("setup", async (peer: any) => setupStream(peer));
dhtInstance.endPeerOnError = async (peer: Socket) => {
const listeners = (await peer.getListeners()) as string[];
return listeners.length <= 1;
};
return id;
}