UNPKG

kubo-rpc-client

Version:
26 lines 1.05 kB
import { peerIdFromString } from '@libp2p/peer-id'; import { multiaddr } from '@multiformats/multiaddr'; import { toUrlSearchParams } from '../lib/to-url-search-params.js'; export function createPeers(client) { return async function peers(options = {}) { const res = await client.post('swarm/peers', { signal: options.signal, searchParams: toUrlSearchParams(options), headers: options.headers }); const body = await res.json(); return (body.Peers ?? []).map((peer) => { return { addr: multiaddr(peer.Addr), peer: peerIdFromString(peer.Peer), muxer: peer.Muxer, latency: peer.Latency, streams: peer.Streams, // eslint-disable-next-line no-nested-ternary direction: peer.Direction == null ? undefined : peer.Direction === 0 ? 'inbound' : 'outbound', identify: peer.Identify }; }); }; } //# sourceMappingURL=peers.js.map