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
impl ControlHandle
Sourcepub async fn seek(&self, position_ms: u64) -> Result<()>
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.
Sourcepub async fn seek_relative(&self, offset_ms: i64) -> Result<()>
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.
Sourcepub async fn set_volume(&self, level: u8) -> Result<u8>
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.
Sourcepub async fn report_volume(&self, level: u8) -> Result<()>
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.
Sourcepub async fn output_delay_applied(&self) -> Result<()>
pub async fn output_delay_applied(&self) -> Result<()>
Tells the session that the host applied an output delay, so it reports the new value.
The host calls this after it applied the delay from Event::OutputDelay to its sink and
persisted it. The session reads Sink::output_delay, re-maps the queued deadlines and
sends a client/state at once when the sink’s timing differs from what was last reported,
so the server recomputes its send-ahead from the value in force. Without the call the
session makes one fallback read of the sink half a second after a server command; a host
that applies the value later, or that changes the delay on its own without a server
command, must call this, or the report waits for the next timing poll after a clock burst.
§Errors
Returns an error for a connection that has ended, and when the server did not activate
player@v1.
Sourcepub async fn set_muted(&self, muted: bool) -> Result<()>
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.
Sourcepub async fn set_unpaired_access(&self, enabled: bool) -> Result<()>
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.
Sourcepub fn volume(&self) -> u8
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.
Sourcepub fn pairing_token(&self) -> Option<String>
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.
Sourcepub async fn open_pairing_window(&self) -> Result<()>
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.
Sourcepub async fn release_holdback(&self) -> Result<()>
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.