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

    A file transfer in the sending direction.

    Announces the file to the receiver with an offer control message, then — once accepted — reads the source in SendTransferParams.chunkSize chunks and streams them as framed binary messages across one or more data channels. Chunks are striped round-robin across the channels, backpressure is applied via each channel's bufferedAmount (see the high/low water marks), and when checksums are enabled a SHA-256 digest is computed over the file and sent so the receiver can verify integrity. Supports pause/resume and cancellation, and honours a receiver's resume request by resending only the chunks it is missing.

    Instances are created and started by FileTransferManager.sendFile; construct via the manager rather than directly.

    const transfer = manager.sendFile(peerId, file)
    transfer.on('progress', (p) => console.log(`${Math.round(p.ratio * 100)}%`))
    transfer.on('complete', () => console.log('sent'))
    transfer.on('error', (err) => console.error(err.code, err.message))

    Hierarchy (View Summary)

    Index

    Constructors

    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.

    direction: "send" = TransferDirection.Send
    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

    • 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).

    • Processes an inbound control message from the receiver, driving the send state machine: accept/resume-request begin streaming (the latter resending only the receiver's missing chunks), reject/checksum-mismatch fail the transfer, complete finalizes it, and pause/resume/cancel are applied. Routed here by FileTransferManager.

      Parameters

      • msg:
            | {
                checksum: boolean;
                chunkSize: number;
                mimeType: string;
                name: string;
                parallelChannels: number;
                size: number;
                totalChunks: number;
                transferId: string;
                type: "ft-offer";
                version?: number;
            }
            | { haveChunks?: number[]; transferId: string; type: "ft-accept" }
            | { reason?: string; transferId: string; type: "ft-reject" }
            | { haveChunks: number[]; transferId: string; type: "ft-resume-request" }
            | { digest?: string; transferId: string; type: "ft-sent" }
            | { transferId: string; type: "ft-complete" }
            | { transferId: string; type: "ft-checksum-mismatch" }
            | { reason?: string; transferId: string; type: "ft-cancel" }
            | { transferId: string; type: "ft-pause" }
            | { transferId: string; type: "ft-resume" }

        The decoded control message.

        • {
              checksum: boolean;
              chunkSize: number;
              mimeType: string;
              name: string;
              parallelChannels: number;
              size: number;
              totalChunks: number;
              transferId: string;
              type: "ft-offer";
              version?: number;
          }
          • checksum: boolean
          • chunkSize: number
          • mimeType: string
          • name: string
          • parallelChannels: number
          • size: number
          • totalChunks: number
          • transferId: string
          • type: "ft-offer"
          • Optionalversion?: number

            Protocol version of the sender; see FT_PROTOCOL_VERSION. Optional for back-compat.

        • { haveChunks?: number[]; transferId: string; type: "ft-accept" }
        • { reason?: string; transferId: string; type: "ft-reject" }
        • { haveChunks: number[]; transferId: string; type: "ft-resume-request" }
        • { digest?: string; transferId: string; type: "ft-sent" }
        • { transferId: string; type: "ft-complete" }
        • { transferId: string; type: "ft-checksum-mismatch" }
        • { reason?: string; transferId: string; type: "ft-cancel" }
        • { transferId: string; type: "ft-pause" }
        • { transferId: string; type: "ft-resume" }

      Returns void

    • 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.

    • Re-announce this transfer on freshly reconnected data channels after an interrupt. The receiver responds with a resume request so only the chunks it is missing are resent. No-op unless the transfer was interrupted.

      Parameters

      • channels: RTCDataChannel[]

        The new binary data channels to stream over.

      Returns void