@hyperfrontend/network-protocol/browser/receiver

receiver

Browser-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 message event on window, a MessagePort, or a Worker; 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 /browser/sender on the other end and a protocol from /browser/v3 or /browser/v4; a channel from /browser/channel creates both for you.

API Reference§

Interfaces

§interface

InboundQueue

Represents an inbound processing queue with measurable size

Properties

§readonly size:number
Number of items in the queue
§interface

Receiver

Receiver interface for processing inbound frames

Properties

§readonly queue:InboundQueue
The frames waiting to be opened
§readonly receive:ReceiveFn
Feeds an incoming frame into the pipeline
§readonly resume:() => void
Resumes frame processing
§readonly stop:() => void
Pauses frame processing

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.