Skip to main content

ControlHandle

Struct ControlHandle 

Source
pub struct ControlHandle { /* private fields */ }
Expand description

Playback controls for a live connection.

A call returns once the connection has handled it: a transport command or a seek has been written to the server, and a level or mute change has been recorded and included in the next state report. It is an error when the connection has ended, when no session is established at that moment, and when the server did not activate the role the command belongs to: transport commands and seeks need controller@v1, volume and mute state need player@v1. A transport command or seek the server did not list in its controller state is refused as well, so a host can offer exactly the buttons the server accepts. An absolute seek needs the reported range on top of that, so it is refused before the first controller state.

Implementations§

Source§

impl ControlHandle

Source

pub async fn play(&self) -> Result<()>

Resumes playback.

Source

pub async fn pause(&self) -> Result<()>

Pauses playback at the current position.

Source

pub async fn next(&self) -> Result<()>

Skips to the next track.

Source

pub async fn previous(&self) -> Result<()>

Skips to the previous track.

Source

pub async fn seek(&self, position_ms: u64) -> Result<()>

Seeks to an absolute position in milliseconds.

The server must offer seek and report a range: the target is checked against PlaybackState::seek_max_ms, so a position beyond it is refused and nothing is sent. Before the first controller state neither the command nor the range is known, so an absolute seek is refused; ControlHandle::seek_relative follows the open-window rule of the other transport commands instead, because an offset needs no range.

§Errors

Returns an error when the connection has ended, when no session is established, when the server did not activate controller@v1, when it did not offer seek, when it reported no seekable range, and when position_ms is beyond that range. The last error names both the target and the range.

Source

pub async fn seek_relative(&self, offset_ms: i64) -> Result<()>

Seeks by an offset in milliseconds from the current position; a negative offset rewinds.

The server must offer seek_relative. The window before its first controller state is open, as it is for the other transport commands: an offset needs no known range, so there is nothing to check it against. An absolute ControlHandle::seek is different and is refused until the range is known.

§Errors

Returns an error when the connection has ended, when no session is established, when the server did not activate controller@v1, and when it did not offer seek_relative.

Source

pub async fn set_volume(&self, level: u8) -> Result<u8>

Sets the output level, limited by ClientConfig::volume_policy against the level in force, and returns the level that was applied.

The level belongs to the connection: the session reports the applied value to the server with its next state report, which is the initial report when the first clock measurement is still pending, and every reconnect keeps it. A new connection starts from ClientConfig::volume, so a host passes the level it restored there and uses this call for changes after that. ControlHandle::volume answers what is in force without a call.

Source

pub async fn report_volume(&self, level: u8) -> Result<()>

Reports the level the device is actually at, without applying the volume policy.

ControlHandle::set_volume treats its argument as a request, so the policy may lower it and above the threshold it limits one step. A host that knows the level its output is really at - because the device applied a level at its own control, or because another process raised it - reports that level with this call instead: it becomes the level in force, ControlHandle::volume returns it, and the next client/state carries it unchanged, so the server’s view matches the output.

The protocol’s range still applies. A level above 100 is refused with an error before anything is recorded or sent; the policy is not consulted and does not clamp the value.

§Errors

Returns an error for a level above 100, for a connection that has ended, and when the server did not activate player@v1.

Source

pub async fn set_muted(&self, muted: bool) -> Result<()>

Sets the mute state without changing the level.

The reported level therefore stays what it was, and the server sees the mute in the muted field alone.

Source

pub async fn set_unpaired_access(&self, enabled: bool) -> Result<()>

Enables or disables unpaired access on the live connection.

The value is what client/hello advertises and what the activation guard enforces. ClientConfig::unpaired_access is the value a connect call starts from. A live change is carried for the rest of that call - the next client/hello advertises it - and a new connect starts from the configuration again.

Turning it off closes a connection that relies on it - an unpaired session with active roles or with the playback activity declared by an accepted activation - after saying goodbye with GoodbyeReason::PairingRequired. An unpaired session that relies on nothing yet stays open, and the existing activation guard refuses the next activation that would need unpaired access. A paired session is never closed by the setting, because the setting never applied to it. Turning it on stores the value and restarts an unpaired session with client/goodbye reason GoodbyeReason::Restart: client/hello is the only carrier of the advertisement, so a live connection cannot advertise the new value without a new one. A paired session is neither closed nor restarted, because the setting never applied to it. Pairing stays admissible in both directions, because the setting gates only roles and the playback activity, never pairing.

§Errors

Returns an error when the connection has ended, and when the connection is switching keys at that moment: the request is refused then, before anything is written, and the host can retry. A change made while the client is between connections is stored, not refused: it is what the next client/hello advertises.

Source

pub fn volume(&self) -> u8

Returns the volume level in force.

The value follows every change the connection made or received, including a mute, which leaves it untouched. It is available without a call, so a host can render its slider while the connection is reconnecting.

Source

pub fn pairing_token(&self) -> Option<String>

The version-0 pairing token for this client, or None when no Storage is configured.

The token is SP:0 plus the base32 body of the identity’s public key and the pairing PSK that was drawn or restored when the client started, so it is fixed for the client’s lifetime and survives a reconnect. A token is a credential: anyone holding it can pair a server with this client, so a host renders it only while the operator needs it and never writes it into a log.

Source

pub async fn open_pairing_window(&self) -> Result<()>

Opens a pairing window on the live connection and starts a waiting static-code attempt.

The pairing window is the client’s half of the static code flow’s operator gesture: the host decides what the gesture is - a button press, a pinhole, a power-cycle pattern - and calls this when it happened. The window belongs to the connection that is live now, so it is opened there and closes when that connection ends, when the configured lifetime expires, when a pairing completes, or after five failed key confirmations.

§Errors

Returns an error when no connection is established at this moment. A call that arrives while the client is reconnecting is refused rather than remembered for the next connection, which the spec requires: a window admits attempts only on the connection that carries its gesture.

Source

pub async fn release_holdback(&self) -> Result<()>

Releases the dynamic flow’s round limit: the deliberate operator action the spec requires.

After twenty rounds without a verified server_kc, the client aborts the attempt and holds further dynamic attempts back, answering their activations with client/pair-pending. The counter is not partitioned by server and only this call - or a verified server_kc - resets it. A host wires it to whatever gesture means “let this device try pairing again”.

Unlike a pairing window, the release needs no connection: the count belongs to the process, and the next connection starts from a clean one. The call still answers the current level, so it observes the same contract as the other control requests.

Trait Implementations§

Source§

impl Clone for ControlHandle

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 ControlHandle

Source§

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

Formats the value using the given formatter. Read more

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.