mirror of
https://github.com/logos-messaging/js-waku.git
synced 2026-01-14 03:33:11 +00:00
chore: add modularity to getting connected peers
This commit is contained in:
parent
be7a0b05ec
commit
aec9451486
@ -56,15 +56,18 @@ export class BaseProtocol implements IBaseProtocolCore {
|
||||
return getPeersForProtocol(this.components.peerStore, [this.multicodec]);
|
||||
}
|
||||
|
||||
public async connectedPeers(): Promise<Peer[]> {
|
||||
public async connectedPeers(withOpenStreams = false): Promise<Peer[]> {
|
||||
const peers = await this.allPeers();
|
||||
return peers.filter((peer) => {
|
||||
const connections = this.components.connectionManager.getConnections(
|
||||
peer.id
|
||||
);
|
||||
return connections.some((c) =>
|
||||
c.streams.some((s) => s.protocol === this.multicodec)
|
||||
);
|
||||
if (withOpenStreams) {
|
||||
return connections.some((c) =>
|
||||
c.streams.some((s) => s.protocol === this.multicodec)
|
||||
);
|
||||
}
|
||||
return connections.length > 0;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@ -17,7 +17,7 @@ export enum Protocols {
|
||||
export type IBaseProtocolCore = {
|
||||
multicodec: string;
|
||||
allPeers: () => Promise<Peer[]>;
|
||||
connectedPeers: () => Promise<Peer[]>;
|
||||
connectedPeers: (withOpenStreams?: boolean) => Promise<Peer[]>;
|
||||
addLibp2pEventListener: Libp2p["addEventListener"];
|
||||
removeLibp2pEventListener: Libp2p["removeEventListener"];
|
||||
};
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user