RTCForge API Reference v1.1.1
    Preparing search index...

    Class TransferAbstract

    Base class for a single file transfer in either direction.

    Owns the identity and metadata of a transfer, tracks byte/chunk progress, and enforces the TransferState state machine (see the legal-transition table), emitting TransferEvents as it advances. Concrete behavior lives in the SendTransfer and ReceiveTransfer subclasses.

    Failure and cancellation are always reachable from any non-terminal state; the ordinary lifecycle otherwise proceeds idle → offered → accepted → active (⇄ paused) → completing → completed.

    Hierarchy (View Summary)

    Index

    Constructors

    • Parameters

      • params: {
            chunkSize: number;
            id: string;
            metadata: FileMetadata;
            peerId: string;
            totalChunks: number;
        }

        Transfer identity and chunking parameters.

        • chunkSize: number

          Payload bytes per chunk.

        • id: string

          Unique transfer id shared with the remote peer.

        • metadata: FileMetadata

          File name, MIME type, and size.

        • peerId: string

          Remote peer identifier.

        • totalChunks: number

          Number of chunks the file is split into.

      Returns Transfer

    Properties

    _state: TransferState = TransferState.Idle

    Current lifecycle state.

    _transferredBytes: number = 0

    Bytes transferred so far.

    _transferredChunks: number = 0

    Chunks transferred so far.

    chunkSize: number

    Payload bytes per chunk.

    Whether the local peer is sending or receiving; set by the concrete subclass.

    id: string

    Unique identifier shared by both peers for this transfer.

    metadata: FileMetadata

    Name, MIME type, and size of the file being transferred.

    peerId: string

    Identifier of the remote peer participating in this transfer.

    totalChunks: number

    Total number of chunks the file is divided into.

    Accessors

    Methods

    • Hook invoked once when the transfer first reaches a terminal state (completed/failed/cancelled). Subclasses override it to release resources — close per-transfer data channels, drain any suspended workers, clear timers.

      Returns void

    • Aborts the transfer, notifying the remote peer.

      Parameters

      • Optionalreason: string

        Optional human-readable reason surfaced to both peers.

      Returns void

    • Synchronously invokes every listener registered for event, in registration order.

      Type Parameters

      Parameters

      • event: K

        The event name to emit.

      • ...args: TransferEvents[K]

        The argument tuple to pass to each listener, matching Events[event].

      Returns boolean

      true if at least one listener was invoked, false if there were none.

      The listener list is snapshotted before dispatch, so mutations made by handlers take effect only on subsequent emissions. Listeners are isolated: if one throws, the remaining listeners still run and the error is surfaced via console.error rather than swallowed silently (consistent with LocalMessageBus).

    • Removes a previously registered listener for event.

      Type Parameters

      Parameters

      • event: K

        The event name the listener was registered for.

      • listener: (...args: TransferEvents[K]) => void

        The exact function reference passed to on or once.

      Returns this

      This emitter, for chaining.

      If the listener is not currently registered, this is a no-op. Only the first matching registration is removed.

    • Registers a listener that is invoked at most once: it is removed automatically before being called the first time event is emitted.

      Type Parameters

      Parameters

      • event: K

        The event name to listen for.

      • listener: (...args: TransferEvents[K]) => void

        Callback invoked with the event's argument tuple on the next emission.

      Returns this

      This emitter, for chaining.

      Remove a pending one-time listener by passing the same function reference to off.

    • Removes listeners for a single event, or for all events.

      Parameters

      • Optionalevent: keyof TransferEvents

        The event name to clear; if omitted, listeners for every event are removed.

      Returns this

      This emitter, for chaining.