Expand description
Client side of Sendspin.
This crate owns the session: it connects to a server, runs the Noise handshake, keeps a clock
estimate and feeds audio to a sink the host provides. It stays device agnostic - the
application that owns the speakers implements Sink and decides what playout means.
A connection always ends in Noise: the client refuses a server that does not complete the
handshake and never falls back to cleartext. A successful attempt reports Event::Connected
and then one event per change; an attempt that ends reports Event::Disconnected with the
delay before the next one, and the crate reconnects on its own with the same sink and identity.
connect validates the configuration and spawns the connection; the first attempt and every
retry run in that task and reach the caller through the EventStream. Only an invalid
configuration or an address this build cannot use returns an error - an unreachable server is
reported as Event::Disconnected. The ClientHandle waits for the connection to end and
hands out a ControlHandle for transport commands, the volume level and mute state. The level
follows ClientConfig::volume_policy - see clamp_volume_with, and clamp_volume for the
default - and the value the server receives is the applied one. ClientConfig::volume and
ClientConfig::muted are the level and mute state the first report carries, so a host passes
the values it restored instead of letting the server see a baseline the output is not at.
ControlHandle::report_volume is the other direction: a level the host reads from its own
output is recorded and sent unchanged, because the policy limits requests rather than the level
the device is at.
ClientConfig::device_info describes the device the client runs on and is announced in
client/hello; a host without an answer passes None and the server sees only the player name.
Pairing records and the long-lived pairing PSK belong to the host: it implements
storage::Storage and the client keeps what it restores, so a paired server is recognised
across restarts. The crate does no file I/O of its own; storage::FileStorage is an optional
JSON backend behind the storage-file feature for a host that wants one.
With a store the client offers the Pairing PSK method, the one method the protocol makes
mandatory, and runs it when a server admits an attempt: it draws the long-term PSK, sends
client/pair-init and client/pair-finalize, and writes the record after server/pair-finalize.
Event::Paired reports the record and Event::PairingFailed an attempt that ended without
one, always with the reason pair/abort carries. Without a store it offers no pairing method at
all: a guest connection is unchanged, and a server that picks pairing anyway is answered with
pair/abort reason method_not_supported. A pairing attempt is bounded by
ClientConfig::pairing_timeout, DEFAULT_PAIRING_TIMEOUT by default.
With the pairing-code feature and a code in
ClientConfig::static_pairing_code, the client also offers the Static Pairing Code method. Every
attempt is gated by an operator gesture: ControlHandle::open_pairing_window opens a window on
the live connection, the client answers a pairing activation with client/pair-pending while
none is open, and the fifth failed key confirmation closes the window. The round runs CPace over
X25519 with SHA-512 and delivers the new long-term PSK sealed under its output; that layer has
not had an external review.
With the same feature and at least one entry in each of ClientConfig::code_formats and
ClientConfig::code_out_channels, the client offers the Dynamic Pairing Code method instead of
relying on a fixed secret. It draws a nonce per attempt, locks it with commit_B in
client/pair-init, and derives the per-session code once the server’s nonce_A arrives: six
digits, or a version-1 pairing token for a QR code. Event::PairingCode carries the code and
its round; the code stays the same across the rounds of one attempt. A failed key confirmation
asks the server for another round, and the twentieth failed round ends the attempt. After the
limit the client holds dynamic attempts back - answering them with client/pair-pending - until
ControlHandle::release_holdback is called, the deliberate operator action the spec requires.
A pairing record can also be dropped from the server’s side. server/unpair removes it, reports
Event::Unpaired and closes the connection; a server that announces a psk_id the client does
not hold is reported once per connection as Event::PairingRequired with reason
PairingRequiredReason::CredentialMismatch, so a host can offer pairing again instead of the
lost record going unnoticed.
A host that renders the stream sees its lifecycle as events: Event::StreamStart for a new
format, Event::StreamEnd when the server pauses or removes the player role, and
Event::StreamClear for a seek, plus Event::Track for the now-playing metadata with its
position, duration and playback speed. The end and clear events arrive before the sink is
flushed, so the host can mute, stop or restart its output first.
The connection keeps running until the audio sink fails, which the host has to repair, or until the handle or the event stream is dropped.
Modules§
- storage
- Where pairing records live.
Structs§
- Audio
Format - The audio format a stream announces.
- Client
- Namespaced entry point, for callers that prefer a type to the free function.
- Client
Config - Everything the client needs to open a session.
- Client
Handle - A live connection.
- Control
Handle - Playback controls for a live connection.
- Device
Info - What the client announces about the device it runs on.
- Event
Stream - The receiving end of a session’s
Eventstream. - Identity
- A long-lived X25519 keypair that identifies one side of a connection.
- Playback
State - Playback state as the server describes it.
- Stored
Psk - A pre-shared key the host stores for a known server.
- Volume
Policy - Limits the session applies to a volume request.
Enums§
- Audio
Frame - One audio frame handed to a
Sink. - Audio
Mode - How the client wants the stream delivered.
- Code
Format - Emission format of a dynamic pairing code.
- Code
OutChannel - Channel a dynamic pairing code reaches the operator through.
- Codec
- Audio codec of a stream.
- Event
- Something that happened on the connection.
- Pairing
Failure - Why a pairing attempt ended without a record.
- Pairing
Required Reason - Why a server needs a pairing this client cannot satisfy with what it holds.
- PskCategory
- Category of a pre-shared key, as the server announces it in Noise message 1.
- Stream
EndReason - Why a player stream ended.
Constants§
- DEFAULT_
PAIRING_ TIMEOUT - How long one pairing attempt may run, measured from
client/pair-init. - DEFAULT_
PAIRING_ WINDOW - How long an operator-opened pairing window admits attempts.
- INITIAL_
BACKOFF - Delay before the first reconnect attempt, and the value the backoff resets to.
- MAX_
PAIRING_ PENDING_ TEXT_ LEN - Longest
client/pair-pendingmessage the protocol allows, in bytes of UTF-8. - MAX_
PLAYER_ NAME_ LEN - Longest player name the protocol allows, in bytes of UTF-8.
- NORMAL_
PLAYBACK_ SPEED - Playback speed the protocol defines as normal, in per-mille.
- STATIC_
PAIRING_ CODE_ LEN - Number of digits in a static pairing code.
Traits§
- Sink
- Audio output owned by the host application.
Functions§
- clamp_
volume - Returns the volume level to apply for
requestedwhilecurrentis in force. - clamp_
volume_ with - Returns the volume level to apply for
requestedwhilecurrentis in force, usingpolicy. - connect
- Connects to a server and returns its handle and event stream.
- connect_
with_ psks - Connects with pairing keys the host stores for known servers.
- next_
backoff - Returns the delay to wait before the next connection attempt.
- version
- Returns the version of this crate as recorded in its manifest.