AbstractTransfer identity and chunking parameters.
Payload bytes per chunk.
Unique transfer id shared with the remote peer.
File name, MIME type, and size.
Remote peer identifier.
Number of chunks the file is split into.
Protected_Current lifecycle state.
Protected_Bytes transferred so far.
Protected_Chunks transferred so far.
Protected ReadonlychunkPayload bytes per chunk.
Abstract ReadonlydirectionWhether the local peer is sending or receiving; set by the concrete subclass.
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.
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.
AbstractcancelAborts the transfer, notifying the remote peer.
Optionalreason: stringOptional human-readable reason surfaced to both peers.
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.
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.
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.
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.
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.
Remarks
Failure and cancellation are always reachable from any non-terminal state; the ordinary lifecycle otherwise proceeds idle → offered → accepted → active (⇄ paused) → completing → completed.