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

    A file transfer in the receiving direction.

    Created when a remote offer arrives (see FileTransferEvent.IncomingOffer). The application inspects ReceiveTransfer.metadata and then calls ReceiveTransfer.accept with a StorageSink — or ReceiveTransfer.reject to decline. Once accepted, framed chunks arriving on the data channel(s) are decoded, deduplicated, hashed (when checksums are enabled), and written to the sink at their byte offset. When the sender signals it is done and every chunk has been received, the digest is verified, the sink is closed, and the resulting SinkResult is exposed via ReceiveTransfer.result.

    manager.on('incoming-offer', (transfer) => {
    console.log(`incoming ${transfer.fileName} (${transfer.metadata.size} bytes)`)
    transfer.accept(new MemorySink())
    transfer.on('complete', () => {
    const blob = transfer.result?.blob
    })
    })

    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: "receive" = TransferDirection.Receive
    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

    • 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 sender. A sent message records the sender-computed digest and marks the stream complete (triggering finalization once all chunks have arrived); a cancel aborts the transfer. 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.

    • Ask the sender to resume, reporting the chunks already received so only the missing ones are resent. Invoked by FileTransferManager when the sender re-announces an in-progress transfer after a reconnect. No-op if the transfer is terminal or has not yet been accepted.

      Returns void