import BufferList from 'bl/BufferList' export interface MuxerFactory { new (options: MuxerOptions): Muxer; multicodec: string; } /** * A libp2p stream muxer */ export interface Muxer { readonly streams: Array; /** * Initiate a new stream with the given name. If no name is * provided, the id of th stream will be used. */ newStream (name?: string): MuxedStream; /** * A function called when receiving a new stream from the remote. */ onStream (stream: MuxedStream): void; /** * A function called when a stream ends. */ onStreamEnd (stream: MuxedStream): void; } export type MuxerOptions = { onStream: (stream: MuxedStream) => void; onStreamEnd: (stream: MuxedStream) => void; maxMsgSize?: number; } export type MuxedTimeline = { open: number; close?: number; } export interface MuxedStream extends AsyncIterable { close: () => void; abort: () => void; reset: () => void; sink: Sink; source: AsyncIterable; timeline: MuxedTimeline; id: string; } export type Sink = (source: AsyncIterable) => Promise;