Skip to main content

Module frame

Module frame 

Source
Expand description

The binary frames on the socket.

One WebSocket binary message per frame: a one-byte kind tag, then the payload. Three kinds, and what tells them apart is the tag alone:

  • Kind::Dictation - a client’s mono PCM at SAMPLE_RATE, the rate the dictation models read. The server decodes this one.
  • Kind::BrowserFrame - the server’s relay of one encoded browser frame: the profile id, sequence, view size, format, key flag, the page’s own viewport and the WebP payload, exactly as the host encoded it. The bytes are never re-encoded or decoded here; the server only moves them.
  • Kind::BrowserAudio - the viewed page’s audio, relayed to the controlling client with its profile, sequence, sample rate and channels.

Tag 3 is not a kind here. A whole ServerMessage body, gzipped for a client that declared deflate=1, is built by the connection’s encoder and read by that client’s decoder, so it crosses as a server-only frame rather than as a variant of Kind.

The kind tag is why the shape can grow: a new client frame is a variant here plus a line in the recorded contract, not a new message type.

The server decodes what clients send and encodes what it sends. A browser frame arriving from a client is refused: the host is the only encoder.

A frame leaves the server through one interface. FrameTransport is what the connection asks to deliver a viewer’s frame; the socket is its only implementation today, and a WebRTC backend later is another implementation rather than a change to input, tools or the draw path.

Re-exports§

use axum::extract::ws::Message; 🔒
use forge_primitives::browser::BrowserAudio; 🔒
use forge_primitives::browser::BrowserFrame; 🔒
use futures_util::SinkExt as _; 🔒
use super::WRITE_BOUND; 🔒
use super::write_within; 🔒

Structs§

SocketFrames
The socket’s own transport: one tagged binary message per frame.

Enums§

Frame
One decoded frame.
Kind
What a binary frame is.
Refusal
Why a binary message was not a frame this server takes.

Constants§

HEADER_BYTES
One dictation frame’s header: the kind tag and nothing else.
MAX_PAYLOAD_BYTES
The largest dictation payload a frame may carry. Twenty-five times the 20 ms frame a client sends, so a malformed or hostile length cannot make the server hold a large allocation per message.
SAMPLE_RATE
The rate every dictation frame’s samples are at. Pinned against the dictation crate’s own constant by a test rather than imported: the wire’s rate is this crate’s rule, and the transport does not need the audio crate to state it.

Traits§

FrameTransport
How one viewer receives a browser’s frames.

Functions§

audio_bytes 🔒
One audio packet’s bytes: the kind tag, the profile, tab, sequence, sample rate and channels, then the interleaved little-endian i16 samples.
decode
Decode one binary message a client sent.
terminal_output_bytes
One terminal output frame’s bytes: the tag, the id, the sequence, then the shell’s own bytes.