Fully-resolved send parameters; see SendTransferParams.
Protected_Current lifecycle state.
Protected_Bytes transferred so far.
Protected_Chunks transferred so far.
Protected ReadonlychunkPayload bytes per chunk.
ReadonlydirectionAlways TransferDirection.Send.
ReadonlyidUnique identifier shared by both peers for this transfer.
ReadonlymetadataName, MIME type, and size of the file being transferred.
ReadonlypeerIdentifier of the remote peer participating in this transfer.
Protected ReadonlytotalTotal number of chunks the file is divided into.
Number of parallel data channels this transfer streams over.
Whether this transfer is paused awaiting a SendTransfer.reoffer after a channel drop.
true once the transfer has reached a terminal state (completed, failed, or cancelled).
The current lifecycle state of the transfer.
Protected_Hook invoked by Transfer.fail when a local failure must be signalled to the remote peer. Overridden by the concrete subclasses to send a cancel over the control channel; a no-op by default.
Protected_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.
Cancels the transfer, sending a cancel control message to the receiver and closing the source. No-op if the transfer is already terminal.
Optionalreason: stringOptional reason; when provided, surfaced via TransferEvent.Error.
Synchronously invokes every listener registered for event, in registration order.
The event name to emit.
The argument tuple to pass to each listener, matching Events[event].
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).
ProtectedemitEmits a TransferEvent.Progress event with the current snapshot.
ProtectedfailTransitions the transfer to TransferState.Failed and emits TransferEvent.Error. No-op if the transfer is already terminal.
The error describing the failure.
The same error, for convenient throw/return chaining.
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.
The decoded control message.
Optionalversion?: numberProtocol version of the sender; see FT_PROTOCOL_VERSION. Optional for back-compat.
Returns the number of listeners currently registered for event.
The event name to count listeners for.
The count of registered listeners (0 if none).
Removes a previously registered listener for event.
The event name the listener was registered for.
This emitter, for chaining.
Registers a listener that is invoked every time event is emitted.
The event name to listen for.
Callback invoked with the event's argument tuple.
This emitter, for chaining.
Registers a listener that is invoked at most once: it is removed automatically before
being called the first time event is emitted.
The event name to listen for.
Callback invoked with the event's argument tuple on the next emission.
This emitter, for chaining.
Remove a pending one-time listener by passing the same function reference to off.
Suspends streaming and notifies the receiver. No-op unless the transfer is TransferState.Active. In-flight chunk reads stop at the next pause gate.
Returns a point-in-time TransferProgress snapshot.
Current byte/chunk counts and completion ratio (ratio is 0 for zero-byte files).
Removes listeners for a single event, or for all events.
Optionalevent: keyof TransferEventsThe event name to clear; if omitted, listeners for every event are removed.
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.
The new binary data channels to stream over.
Resumes a paused transfer and notifies the receiver, releasing workers waiting at the pause gate. No-op unless the transfer is TransferState.Paused.
Begins the transfer by sending the offer control message to the receiver. Byte streaming starts only after the receiver accepts (or requests a resume). Idempotent once past TransferState.Idle. Called automatically by FileTransferManager.sendFile.
ProtectedtoNormalizes an unknown thrown value into a FileTransferError tagged with this transfer's id, passing through existing FileTransferErrors unchanged.
The caught value.
The FileTransferErrorCode to assign when wrapping.
Optionalmessage: stringOptional override message; otherwise derived from err.
A FileTransferError suitable for Transfer.fail.
ProtectedtransitionAttempts a state transition, enforcing the legal-transition table.
The state to move to.
true if the transition occurred (or was a no-op because already in next);
false if the transfer is already terminal or the transition is illegal. Transitions to
TransferState.Failed and TransferState.Cancelled are always permitted from
any non-terminal state.
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.Remarks
Instances are created and started by FileTransferManager.sendFile; construct via the manager rather than directly.
Example