Skip to main content

ClientConfig

Struct ClientConfig 

Source
pub struct ClientConfig {
Show 22 fields pub server: String, pub player_name: String, pub device_info: Option<DeviceInfo>, pub identity: Identity, pub storage: Option<Arc<dyn Storage>>, pub audio_mode: AudioMode, pub volume: u8, pub muted: bool, pub output_delay_control: bool, pub required_lead_time_ms: u32, pub min_buffer_ms: Option<u32>, pub volume_policy: VolumePolicy, pub max_backoff: Duration, pub strict_group_id: bool, pub unpaired_access: bool, pub pairing_timeout: Duration, pub static_pairing_code: Option<String>, pub pairing_window: Duration, pub pairing_pending_text: Option<String>, pub code_formats: Vec<CodeFormat>, pub code_out_channels: Vec<CodeOutChannel>, pub inbound: Option<Inbound>,
}
Expand description

Everything the client needs to open a session.

The identity is the client’s long-lived X25519 keypair. It also becomes the client_id the server sees, so reusing it keeps the player recognisable across reconnects; the crate never generates or replaces one on its own.

Fields§

§server: String

Server address as host:port, or a full ws:// URL.

A bare address connects to ws://<server>/sendspin. TLS is not part of this build, so a wss:// URL is rejected rather than silently downgraded.

§player_name: String

Friendly name announced to the server, non-empty and at most MAX_PLAYER_NAME_LEN bytes.

§device_info: Option<DeviceInfo>

Description of the device the client runs on, announced in client/hello.

The server displays it to the operator. A host that does not know the hardware passes None and no device_info object is sent, so the server shows only the player name.

§identity: Identity

Long-lived keypair that identifies this client.

Restore a stored keypair with Identity::from_secret_base64; generating a fresh one makes the server treat the player as a new device.

§storage: Option<Arc<dyn Storage>>

Where the pairing PSK and the pairing records live, or None for a guest-only client.

The host owns the store; see Storage. With a store the client offers the Pairing PSK method, keeps one pairing PSK across restarts and writes a record for every completed pairing. Without one it offers no pairing method at all: it never draws a key it cannot hand back, and it answers a pairing activation with pair/abort reason method_not_supported. A plain guest session is unchanged either way.

§audio_mode: AudioMode

Whether the sink receives samples or encoded frames.

§volume: u8

Output level to start from, in the protocol’s 0-100 range.

The session reports this level in its first client/state and applies the volume limit against it, so a host passes the level it restored instead of an invented one. A host without a stored level passes 100, which neither attenuates nor limits an incoming request.

§muted: bool

Mute state to start from.

Reported in the first client/state; a host without a stored state passes false.

§output_delay_control: bool

Whether the server may set this player’s output delay with set_output_delay.

Off by default. A host that can change the delay after its audio port (external speakers, an amplifier, a soundbar) opts in: the client then advertises the command, reports Event::OutputDelay for a command it accepts, and the host applies the value to its sink and persists it. A host that cannot apply the command must leave this off, because roles/player/v1.md lets a client advertise only what it applies.

The command is an instruction to the host, not a value the session applies itself: the sink remains the authority for output_delay_ms. Once the host applied the value it calls ControlHandle::output_delay_applied, and the session reads the sink, re-maps queued deadlines and reports it. A host that never calls it is still reported: the session reads the sink once, half a second after the command, and sends a client/state if the sink adopted a new value by then. A host that applies the value later than that must call output_delay_applied. Persisting the value, so it survives restarts and reconnects, is the host’s duty: the session never stores it.

Adding this field is a 0.x break for a full ClientConfig { .. } literal (the changelog is generated from the commit history at release time); ClientConfig::new and ClientConfig::with_output_delay_control keep working.

§required_lead_time_ms: u32

Minimum start-up lead the server must give this player, in milliseconds.

This is the host’s own start-up cost: launching the output (gst-launch, pacat), the decoder’s warm-up, and whatever the backend needs before the first sample is audible. The client asks the server to schedule the first sample of a stream this far ahead of the playout deadline; the value is a hint, and the server in this workspace ignores it until docs/spec-deviations.md #17 closes.

A host must keep it at least as large as the buffer its backend still plays after a stream/clear: the clear discards that audio, and a shorter lead would schedule the replacement audio while the old audio is still audible.

The default is 250, the value every release before this field reported, which covers a pipeline that starts within a quarter of a second. The protocol gives the field no upper bound beyond the type, so the configuration accepts every u32.

§min_buffer_ms: Option<u32>

Buffer duration the server should keep filled, in milliseconds, or None to derive it.

Some(n) pins the value: every client/state reports n and the session never derives one from arriving audio. A host pins it when it knows its backend’s tolerance and wants the value to stay put. The protocol bounds the reported buffer to 0-5000 ms, and a configuration outside that range is refused before a connection is attempted.

None leaves the value to the session, which derives it from the arrival delay of audio chunks as roles/player/v1.md asks: the first report is 250, and the value follows the upper tail of the measured distribution once enough samples exist.

§volume_policy: VolumePolicy

Limits applied to every volume request.

The session applies the policy to a command from the server and to a level the host sets through ControlHandle::set_volume; the value it reports back is always the applied one. VolumePolicy::default keeps the fixed rule of earlier releases.

§max_backoff: Duration

Upper bound for the delay between reconnects.

The connection reports a recommended delay in Event::Disconnected and waits it before the next attempt; next_backoff never returns more than this.

§strict_group_id: bool

Whether a group_id outside the spec’s 43 base64url characters closes the connection.

The spec makes such a value a protocol error, and with true the client behaves that way: the attempt ends and Event::Disconnected reports why.

The default is false. A non-canonical but well-formed identifier - non-empty, at most 128 bytes, valid UTF-8 without control characters - is then accepted as an opaque string and reported once per connection as Event::GroupIdNotCanonical. That tolerance exists because a real server sends a UUID instead; see docs/spec-deviations.md. A host that talks to a conformant server, or that wants the spec’s rule enforced, sets this to true.

§unpaired_access: bool

Whether this client admits a server with no pairing record.

The value is advertised in client/hello as unpaired_access.enabled and both sides act on it. With false this client refuses to activate a session that is not keyed by a long-term PSK for playback: such a server/activate ends the connection with client/goodbye reason pairing_required. A server that honours the advertisement grants no roles to an unpaired client whose hello says false. Pairing is unaffected: the setting gates only roles and the playback activity, never pairing.

The value can change while the client runs: ControlHandle::set_unpaired_access stores a new value, which the next client/hello advertises and the activation guard enforces. Enabling it on an unpaired session forces that hello by reconnecting. This field is the value each connect call starts from.

pairing.md leaves the default to the manufacturer and recommends false for a client whose input a stranger could reach, such as a microphone. The default here is true, which is what every release before this setting did.

§pairing_timeout: Duration

How long one pairing attempt may run, measured from client/pair-init.

On expiry the client sends pair/abort with reason attempt_timeout and reports Event::PairingFailed. The protocol recommends two minutes, which is DEFAULT_PAIRING_TIMEOUT; a host shortens it only for tests or for a deployment that wants a tighter bound.

§static_pairing_code: Option<String>

The operator-facing static pairing code, exactly eight decimal digits.

The code is configuration, never generated: a manufacturer provisions one per device, and the operator reads it off the device or its leaflet. Offering the static code method in client/hello depends on this field being set, so a client without a code never advertises a method it cannot complete.

The code is a credential: anyone who knows it and can reach the server may pair. It is never formatted - ClientConfig’s Debug prints it redacted - and never logged.

§pairing_window: Duration

How long an operator-opened pairing window admits attempts, recommended five minutes.

The window runs from ControlHandle::open_pairing_window and does not pause during an attempt. On expiry it closes silently; an attempt already in progress runs to its own end.

§pairing_pending_text: Option<String>

Sentence sent in client/pair-pending, in the host’s language.

A host that wants to tell the operator what to do sets it here; without one the message is sent with no text, because the crate does not invent operator-facing prose.

§code_formats: Vec<CodeFormat>

Emission formats the client offers for a dynamic pairing code.

An empty list offers no dynamic method at all; a non-empty one advertises dynamic_pairing_code in client/hello, together with ClientConfig::code_out_channels. Both lists must be set for the method to be offered, because the protocol treats a descriptor left without a known format or channel as unrecognized. The code itself is derived per attempt, never configured.

§code_out_channels: Vec<CodeOutChannel>

Channels the host can carry a dynamic pairing code through.

The host sets what it can render or speak; the server picks the method’s format, and the client emits the code through Event::PairingCode.

§inbound: Option<Inbound>

The server-initiated half of the connection mode, or None for client-initiated connections.

Setting it makes advertise publish _sendspin._tcp and accept the servers that connect, and makes a manual connect fail: connection.md lets a client use one of the two methods at a time, never both. Inbound::new fills the listen address and the path with the values the spec recommends.

Implementations§

Source§

impl ClientConfig

Source

pub fn with_output_delay_control(self, enabled: bool) -> Self

Lets the server set this player’s output delay; see ClientConfig::output_delay_control.

Source

pub fn new( server: impl Into<String>, player_name: impl Into<String>, identity: Identity, ) -> ClientConfig

Builds a configuration for server with the crate’s defaults.

Everything a host rarely changes starts at a documented value: no device description, no pairing store, AudioMode::Decode, volume 100 and unmuted, VolumePolicy::default, a 250 ms start-up lead, a buffer the session derives rather than a pinned one, DEFAULT_MAX_BACKOFF, the tolerated foreign group_id, unpaired access admitted, and DEFAULT_PAIRING_TIMEOUT. A host that restores a level or a mute state sets ClientConfig::volume and ClientConfig::muted on the value this returns.

The fields stay public, so a host can also build the struct itself and name every field.

Trait Implementations§

Source§

impl Clone for ClientConfig

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ClientConfig

Source§

fn fmt(&self, formatter: &mut Formatter<'_>) -> Result

Formats the configuration without the store and without key material.

The store holds the pairing PSK and the records, and its own Debug is the host’s; the identity redacts its secret. Neither is delegated to here, so a Debug log of a configuration cannot leak a key.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.