@hyperfrontend/network-protocol/node/receiver

receiver

Node.js-side inbound pipeline: frames in, opened packets out.

createReceiver(label, receivePacket, logger, open, onDrop?) builds a Receiver from a ReceivePacketFn callback that takes each opened UnencryptedPacket and the session's PacketOpener (protocol.open). receiver.receive(frame) takes the raw bytes from a TCP socket data event, a process.on('message', ...) IPC handler, or a WebSocket message handler; a single open queue opens one frame at a time, which keeps the session's replay counter exact, and delivers each packet in order. A frame that is forged, replayed, malformed, or from another session is reported through onDrop and never delivered.

Hello frames belong to the protocol's acceptHello, not to the receiver. Pair with /node/sender on the other end and a protocol from /node/v3 or /node/v4; a channel from /node/channel creates both for you.

Function signatures match /browser/receiver so cross-runtime communication is symmetric.

API Reference§

◈ Interfaces

§interface

InboundQueue

Represents an inbound processing queue with measurable size
Properties
§readonly size:numberNumber of items in the queue
§interface

Receiver

Receiver interface for processing inbound frames
Properties
§readonly receive:ReceiveFnFeeds an incoming frame into the pipeline
§readonly stop:() => voidPauses frame processing
§readonly resume:() => voidResumes frame processing
§readonly queue:InboundQueueThe frames waiting to be opened

◆ Types

§type

CreateReceiver

Factory function type for creating a Receiver instance; onDrop receives each frame the opener rejects
type CreateReceiver = (label: string, receiver: ReceivePacketFn<T>, logger: Logger, open: PacketOpener<T>, onDrop?: PacketDropHandler) => Receiver
§type

ReceiveFn

Function to receive raw wire bytes
type ReceiveFn = (packet: Uint8Array) => void
§type

ReceivePacketFn

Callback invoked with each opened packet
type ReceivePacketFn = (packet: UnencryptedPacket<T>) => void
§type

ReceiverFactory

Alias for CreateReceiver factory type
type ReceiverFactory = CreateReceiver

● Variables

§type

createReceiver

Creates the inbound half of a channel: frames are opened one at a time on the session's receiving key and delivered as plaintext packets.
A frame the opener rejects (forged, replayed, foreign, or malformed) is reported through onDrop and never delivered.
Example

Creating a receiver fed by a message listener

const receiver = createReceiver('host receiver', (packet) => deliver(packet.data.message), logger, protocol.open, (drop) => report(drop))
window.addEventListener('message', (event) => receiver.receive(event.data))