• Preparing search index...
  • The search index is not available
@libp2p/multistream-select - v3.1.9
  • @libp2p/multistream-select - v3.1.9
  • handle

Function handle

  • handle(stream: Duplex<Source<Uint8Array>, Source<Uint8Array>, unknown>, protocols: string | string[], options: ByteArrayInit): Promise<ProtocolStream<Uint8Array>>
  • Handle multistream protocol selections for the given list of protocols.

    Note that after a protocol is handled listener can no longer be used.

    Returns

    A stream for the selected protocol and the protocol that was selected from the list of protocols provided to select

    Example

    import { pipe } from 'it-pipe'
    import * as mss from '@libp2p/multistream-select'
    import { Mplex } from '@libp2p/mplex'

    const muxer = new Mplex({
    async onStream (muxedStream) {
    // mss.handle(handledProtocols)
    // Returns selected stream and protocol
    const { stream, protocol } = await mss.handle(muxedStream, [
    '/ipfs-dht/1.0.0',
    '/ipfs-bitswap/1.0.0'
    ])

    // Typically here we'd call the handler function that was registered in
    // libp2p for the given protocol:
    // e.g. handlers[protocol].handler(stream)
    //
    // If protocol was /ipfs-dht/1.0.0 it might do something like this:
    // try {
    // await pipe(
    // dhtStream,
    // source => (async function * () {
    // for await (const chunk of source)
    // // Incoming DHT data -> process and yield to respond
    // })(),
    // dhtStream
    // )
    // } catch (err) {
    // // Error in stream
    // }
    }
    })

    Parameters

    • stream: Duplex<Source<Uint8Array>, Source<Uint8Array>, unknown>

      A duplex iterable stream to listen on

    • protocols: string | string[]

      A list of protocols (or single protocol) that this listener is able to speak.

    • options: ByteArrayInit

      an options object containing an AbortSignal and an optional boolean writeBytes - if this is true, Uint8Arrays will be written into duplex, otherwise Uint8ArrayLists will

    Returns Promise<ProtocolStream<Uint8Array>>

    • Defined in handle.ts:58
  • handle(stream: Duplex<Source<Uint8Array | Uint8ArrayList>, Source<Uint8Array | Uint8ArrayList>, unknown>, protocols: string | string[], options?: ByteListInit): Promise<ProtocolStream<Uint8ArrayList, Uint8ArrayList | Uint8Array>>
  • Parameters

    • stream: Duplex<Source<Uint8Array | Uint8ArrayList>, Source<Uint8Array | Uint8ArrayList>, unknown>
    • protocols: string | string[]
    • Optional options: ByteListInit

    Returns Promise<ProtocolStream<Uint8ArrayList, Uint8ArrayList | Uint8Array>>

    • Defined in handle.ts:59

Settings

Member Visibility

Theme

Modules

  • @libp2p/multistream-select - v3.1.9
    • ByteArrayInit
    • ByteListInit
    • MultistreamSelectInit
    • ProtocolStream
    • PROTOCOL_ID
    • handle
    • lazySelect
    • select