Skip to content

FrameLink

Defined in: packages/net-core/src/frame-link.ts:111

Turns a byte Transport into a stream of typed values, and typed values back into bytes.

Owns everything that is protocol-independent: the decode loop (via DecodeDriver), streamed payloads (via BodyReader), read and write backpressure, silence timeouts, transport and codec swapping, and lifecycle. Protocol knowledge lives entirely in the injected Codec, and correlation lives entirely above in the session.

Message-mode datagrams bypass the decode loop entirely — a datagram is always exactly one complete value with no state carried to the next one, which DecodeDriver (built for accumulation across calls) has nothing to offer.

In

Decoded (inbound) value type.

Out = In

Encoded (outbound) value type. Separate from In because most non-trivial protocols are asymmetric.

new FrameLink<In, Out>(options): FrameLink<In, Out>

Defined in: packages/net-core/src/frame-link.ts:128

FrameLinkOptions<In, Out>

FrameLink<In, Out>

EventDispatcherMapBase<FrameLinkEvents>.constructor

get buffered(): number

Defined in: packages/net-core/src/frame-link.ts:173

Bytes received but not yet decoded.

number

[asyncDispose](): Promise<void>

Defined in: packages/net-core/src/frame-link.ts:350

Destroys the link, so it can be used with await using.

Promise<void>


destroy(error?): void

Defined in: packages/net-core/src/frame-link.ts:337

Tear down the link and its transport.

unknown

Optional cause reported to listeners.

void


detach(): Transport

Defined in: packages/net-core/src/frame-link.ts:311

Release the transport to another protocol, keeping every byte received but not yet decoded.

This is the HTTP Upgrade primitive: once the 101 is decoded or sent, the connection is no longer HTTP, and the bytes that arrived in the same segment belong to the next protocol. Safe to call from inside a FrameSink invocation; no value is decoded afterwards. The link emits no further event, close included — the connection is still open, it just is not this link’s anymore.

Stream mode only. A body still being streamed is errored.

Transport

The transport, paused and stopped. Its first delivery to the next owner is the undecoded bytes; starting it resumes the flow.

When the link is already closed or detached.


end(): Promise<void>

Defined in: packages/net-core/src/frame-link.ts:289

Half-close the outbound direction and flush pending writes.

Promise<void>

Resolves once the transport has flushed.


isSubscribed<K>(event, listener): boolean

Defined in: packages/async/src/events/event-dispatcher-map-base.ts:38

Check if a callback is subscribed to a specific event.

K extends keyof FrameLinkEvents

K

The event name.

Callable<FrameLinkEvents[K]>

The callback to check.

boolean

IEventDispatcherMap.isSubscribed

EventDispatcherMapBase.isSubscribed


pause(): void

Defined in: packages/net-core/src/frame-link.ts:210

Suspend value delivery by pausing the transport.

void


reset(): void

Defined in: packages/net-core/src/frame-link.ts:226

Discard undecoded bytes, decoder state and any silence timer.

Safe to call from inside a FrameSink invocation: DecodeDriver detects the reentrant call and stops rather than continuing over a buffer that no longer exists.

void


resume(): void

Defined in: packages/net-core/src/frame-link.ts:215

Resume value delivery suspended by pause.

void


send(value, signal?): Promise<void>

Defined in: packages/net-core/src/frame-link.ts:185

Encode and send one value.

Out

The value to transmit.

AbortSignal

Cancels the wait for transport capacity. Bytes already accepted by the transport cannot be unsent.

Promise<void>

Resolves once the transport has accepted the bytes.


sendRaw(data, signal?): Promise<void>

Defined in: packages/net-core/src/frame-link.ts:199

Send raw bytes, bypassing the encoder.

Required by protocols that interleave opaque payloads with framed commands, such as an SMTP DATA body.

Uint8Array<ArrayBufferLike> | readonly Uint8Array<ArrayBufferLike>[]

One or more buffers, written as a single vectored write.

AbortSignal

Cancels the wait for transport capacity.

Promise<void>

Resolves once the transport has accepted the bytes.


subscribe<K>(event, listener, options?): Callable | null

Defined in: packages/async/src/events/event-dispatcher-map-base.ts:23

K extends keyof FrameLinkEvents

K

Callable<FrameLinkEvents[K]>

EventDispatcherSubscribeOptions

Callable | null

IEventDispatcherMap.subscribe

EventDispatcherMapBase.subscribe


swapCodec(codec): void

Defined in: packages/net-core/src/frame-link.ts:250

Replace the codec, for example after an RTMP handshake completes or an SMTP session negotiates a new mode.

Codec<In, Out>

The codec to decode and encode with from now on.

void


swapTransport(transport, options?): void

Defined in: packages/net-core/src/frame-link.ts:267

Replace the transport, carrying over any undecoded bytes.

This is the STARTTLS primitive: the plaintext transport is detached (not destroyed, since the TLS transport wraps the same socket) and framing continues over the new one.

Transport

The transport to read from and write to from now on.

FrameLinkSwapTransportOptions

keepResidue retains undecoded bytes across the swap. Leave it false for security-sensitive switches such as STARTTLS, where buffered plaintext is a command-injection vector.

void


takeResidue(): Uint8Array

Defined in: packages/net-core/src/frame-link.ts:240

Remove and return the undecoded bytes without discarding them.

The residue after a protocol switch belongs to the next protocol: an HTTP Upgrade response may be followed immediately by WebSocket bytes in the same segment. Discarding them silently corrupts the upgraded connection.

Uint8Array

A copy of the bytes received but not yet decoded.


unsubscribe<K>(event, listener): void

Defined in: packages/async/src/events/event-dispatcher-map-base.ts:31

Unsubscribe a callback from a specific event.

K extends keyof FrameLinkEvents

K

The event name.

Callable<FrameLinkEvents[K]>

The callback to remove.

void

IEventDispatcherMap.unsubscribe

EventDispatcherMapBase.unsubscribe


wait<K>(event, options?): Promise<FrameLinkEvents[K]>

Defined in: packages/async/src/events/event-dispatcher-map-base.ts:45

Wait for the next occurrence of a specific event, optionally matching a predicate.

This is a convenience method that subscribes to the dispatcher, waits for the next event that matches the predicate (if provided), and then unsubscribes automatically.

K extends keyof FrameLinkEvents

K

The event name to wait for.

EventDispatcherWaitOptions<FrameLinkEvents[K]>

Optional settings including predicate and abort signal.

Promise<FrameLinkEvents[K]>

A promise that resolves with the event arguments as an array.

IEventDispatcherMap.wait

EventDispatcherMapBase.wait