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

    Class FileTransferManager

    Entry point for peer-to-peer file transfer over WebRTC data channels.

    Wraps a DataChannelHub and orchestrates both directions of transfer. For each peer it maintains a single JSON control channel (labelled CONTROL_CHANNEL_LABEL) carrying the offer/accept/complete/cancel handshake, and opens per-transfer binary channels for the framed chunk data. Outbound transfers are started with FileTransferManager.sendFile; inbound offers surface as FileTransferEvent.IncomingOffer events carrying a ReceiveTransfer the application accepts or rejects. The manager routes inbound control messages and data channels to the right Transfer, buffering data channels that arrive before their offer.

    The manager does not create or negotiate RTCPeerConnections itself — that is the hub's job. Completed, failed, and cancelled transfers are automatically removed from the manager's registry.

    const manager = new FileTransferManager(hub, { parallelChannels: 4 })

    // Sending
    const send = manager.sendFile(peerId, file)
    send.on('progress', (p) => console.log(p.ratio))

    // Receiving
    manager.on('incoming-offer', (transfer) => {
    transfer.accept(new MemorySink())
    })

    Hierarchy (View Summary)

    Index

    Constructors

    Methods

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

      Type Parameters

      Parameters

      • event: K

        The event name to emit.

      • ...args: FileTransferManagerEvents[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 listeners for a single event, or for all events.

      Parameters

      • Optionalevent: keyof FileTransferManagerEvents

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

      Returns this

      This emitter, for chaining.

    • Resume an interrupted resumable send by re-announcing it on freshly opened data channels (call after the peer connection reconnects). Only the chunks the receiver is still missing are resent. No-op unless the transfer exists, is a SendTransfer, and was interrupted.

      Parameters

      • transferId: string

        Id of the interrupted send transfer.

      Returns void