fix: add endPeerOnError handler
This commit is contained in:
parent
1bb59e1079
commit
57f1e40eff
12
src/index.ts
12
src/index.ts
|
@ -1,6 +1,10 @@
|
||||||
import { addHandler, handleMessage } from "@lumeweb/libkernel/module";
|
import { addHandler, handleMessage } from "@lumeweb/libkernel/module";
|
||||||
import type { ActiveQuery } 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 { RpcNetwork, RpcQueryOptions, setupStream } from "@lumeweb/rpc-client";
|
||||||
import type { RPCRequest, RPCResponse } from "@lumeweb/interface-relay";
|
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.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;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue