libp2p
    Preparing search index...

    Class YamuxStream

    YamuxStream is used to represent a logical stream within a session

    Hierarchy (View Summary)

    Index

    Whether this stream is inbound or outbound

    id: string

    Unique identifier for a stream. Identifiers are not unique across muxers.

    inactivityTimeout: number

    If no data is transmitted over the stream in this many ms, the stream will be aborted with an InactivityTimeoutError

    log: Logger

    A logging implementation that can be used to log stream-specific messages

    maxMessageSize?: number
    maxReadBufferLength: number

    The maximum number of bytes to store when paused. If receipt of more bytes from the remote end of the stream causes the buffer size to exceed this value the stream will be reset and a 'close' event emitted.

    This value can be changed at runtime.

    maxWriteBufferLength?: number

    When the .send method returns false it means that the underlying resource has signalled that it's write buffer is full. If the user continues to call .send, outgoing bytes are stored in an internal buffer until the underlying resource signals that it can accept more data.

    If the size of that internal buffer exceed this value the stream will be reset and a 'close' event emitted.

    This value can be changed at runtime.

    protocol: string

    The protocol negotiated for this stream

    readBuffer: Uint8ArrayList

    Any data stored here is emitted before any new incoming data.

    This is used when the stream is paused or if data is pushed onto the stream

    The status of the readable end of the stream

    remoteReadStatus: MessageStreamReadStatus

    The status of the readable end of the remote end of the stream - n.b. this requires the underlying stream transport to support sending STOP_SENDING messages or similar.

    remoteWriteStatus: MessageStreamWriteStatus

    The status of the writable end of the remote end of the stream

    sendingData: boolean

    The current status of the message stream

    streamId: number

    Timestamps of when stream events occurred

    writableNeedsDrain: boolean

    If this property is true, the underlying transport has signalled that its write buffer is full and that .send should not be called again.

    A drain event will be emitted after which is its safe to call .send again to resume sending.

    writeBuffer: Uint8ArrayList

    The status of the writable end of the stream

    • get readableEnded(): boolean

      True once 'end' has been emitted. Read this instead of waiting for the event, which fires only once and may already have passed.

      It does not mean the readable end is closed, or that the read buffer is empty. Where the readable end is still open, data can be pushed back after 'end', for example by unwrapping a byte stream that read ahead.

      Returns boolean

    • get readBufferLength(): number

      Returns the number of bytes that are queued to be read

      Returns number

    • get writeBufferLength(): number

      Returns the number of bytes that are queued to be written

      Returns number

    • Close immediately for reading and writing and send a reset message (local error)

      Parameters

      Returns void

    • Stop accepting new data to send and return a promise that resolves when any unsent data has been written into the underlying resource.

      Parameters

      Returns Promise<void>

    • Send a message to the remote end of the stream informing them that any incoming data will be discarded so they should stop sending.

      This requires the underlying resource to support this operation - for example the QUIC, WebTransport, WebRTC transports do but anything multiplexed using Yamux or Mplex do not.

      Parameters

      Returns Promise<void>

    • The dispatchEvent() method of the EventTarget sends an Event to the object, (synchronously) invoking the affected event listeners in the appropriate order. The normal event processing rules (including the capturing and optional bubbling phase) also apply to events dispatched manually with dispatchEvent().

      MDN Reference

      Parameters

      Returns boolean

    • The dispatchEvent() method of the EventTarget sends an Event to the object, (synchronously) invoking the affected event listeners in the appropriate order. The normal event processing rules (including the capturing and optional bubbling phase) also apply to events dispatched manually with dispatchEvent().

      MDN Reference

      Parameters

      Returns boolean

    • Returns boolean

    • Returns the number of listeners for the event type

      Parameters

      • type: string

      Returns number

    • Emit 'end' if nothing is buffered and no more data will be delivered. Emits at most once

      Returns void

    • When an extending class reads data from it's implementation-specific source, call this method to allow the stream consumer to read the data.

      Parameters

      Returns void

    • Returns a promise that resolves when the stream can accept new data or rejects if the stream is closed or reset before this occurs.

      Parameters

      Returns Promise<void>

    • Returns void

    • Returns void

    • Called by extending classes when the remote closes its readable end

      Returns void

    • Called by extending classes when the remote closes its writable end

      Returns void

    • Receive a reset message - close immediately for reading and writing (remote error)

      Returns void

    • The underlying resource or transport this stream uses has closed - it is not possible to send any more messages though any data still in the read buffer may still be read

      Parameters

      Returns void

    • Stop emitting further 'message' events. Any received data will be stored in an internal buffer. If the buffer size reaches maxReadBufferLength, the stream will be reset and a StreamAbortEvent emitted.

      If the underlying resource supports it, the remote peer will be instructed to pause transmission of further data.

      Returns void

    • Returns boolean

    • Queue the passed data to be emitted as a 'message' event either during the next tick or sooner if data is received from the underlying resource.

      Parameters

      Returns void

    • The removeEventListener() method of the EventTarget interface removes an event listener previously registered with EventTarget.addEventListener() from the target. The event listener to be removed is identified using a combination of the event type, the event listener function itself, and various optional options that may affect the matching process; see Matching event listeners for removal.

      MDN Reference

      Type Parameters

      Parameters

      Returns void

    • Resume emitting 'message' events.

      If the underlying resource supports it, the remote peer will be informed that it is ok to start sending data again.

      Returns void

    • Type-safe version of EventTarget.dispatchEvent - only events from the event map are supported.

      Attempting to dispatch an unsupported event results in a TypeScript compilation error.

      Type Parameters

      • Detail

      Parameters

      Returns boolean

    • Write data to the stream. If the method returns false it means the internal buffer is now full and the caller should wait for the 'drain' event before sending more data.

      This method may throw if:

      • The internal send buffer is full
      • The stream has previously been closed for writing locally or remotely

      Parameters

      Returns boolean

    • Similar to the .push method, except this ensures the passed data is emitted before any other queued data.

      Parameters

      Returns void