#[non_exhaustive]pub enum Event {
Show 13 variants
Connected {
server_id: String,
encrypted: bool,
},
Disconnected {
reason: String,
retry_in: Duration,
},
StreamStart {
format: AudioFormat,
},
StreamEnd {
reason: StreamEndReason,
},
StreamClear {
from_timestamp: Option<i64>,
},
Track {
title: String,
artist: String,
album: String,
album_artist: String,
artwork_url: String,
progress_ms: Option<u64>,
duration_ms: Option<u64>,
playback_speed: u32,
},
State(PlaybackState),
Volume {
requested: u8,
applied: u8,
muted: Option<bool>,
},
Paired {
server_id: String,
},
Unpaired {
server_id: String,
},
PairingRequired {
server_id: String,
reason: PairingRequiredReason,
},
PairingFailed {
reason: PairingFailure,
},
PairingCode {
code: String,
format: CodeFormat,
round: u32,
},
}Expand description
Something that happened on the connection.
Events are ordered as the connection produced them. A connection attempt ends with at most one
Event::Disconnected, and the crate then reconnects on its own, so a later event belongs to
the next attempt. The enum is non-exhaustive: a later revision adds events without breaking a
host’s match.
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Connected
The Noise handshake finished and the session is ready for playback.
Reported once per successful attempt. encrypted is always true: this client has no path
that speaks to a server without Noise, so the field documents the property rather than
hedging it.
Fields
Disconnected
The attempt ended.
Another attempt follows unless the audio sink failed or the host dropped the connection.
reason is human-readable and never contains key material. retry_in is the delay
before the next attempt, one step of the reconnect policy: it is two seconds after an
attempt that never reached Event::Connected, doubles with every further failed attempt
up to ClientConfig::max_backoff, and drops to one second again after a session that
connected. It is Duration::ZERO when no attempt follows, because the audio sink failed.
Fields
StreamStart
A stream was announced with the given format.
The sink has been opened for this format before the event is emitted.
Fields
format: AudioFormatFormat of the new stream.
StreamEnd
A player stream ended.
Reported before the sink is flushed, so a host can mute or stop its output first. The
client flushes the sink itself as well, after this event. A seek does not end the stream;
it is reported as Event::StreamClear, and chunks after it still belong to the open
stream.
Fields
reason: StreamEndReasonWhy the stream ended.
StreamClear
The server asked to drop buffered audio without ending the stream.
Reported before the sink is flushed, so a host can restart its output or drop the matching part of its own queue first. The announced format stays open, and chunks that follow still belong to it.
Fields
Track
Now-playing metadata changed.
Absent text fields are reported as empty strings, so a host can clear its display; absent
progress fields are None.
Fields
playback_speed: u32Playback speed per mille: 1000 is normal speed, 500 half speed and 0 paused.
Reported as NORMAL_PLAYBACK_SPEED when the server sends no speed, because a track
without the field plays at normal speed.
State(PlaybackState)
The server’s view of playback state changed.
Volume
The server asked this player to change its volume or mute state.
The session applies the VolumePolicy from its configuration and reports the applied
level back to the server in client/state. The event carries both numbers, so a host can
see what the server asked for and what the policy allowed without repeating the policy.
muted is present for a mute command and absent for a volume command; a mute leaves the
level unchanged, so both numbers then name the level already in force.
Fields
Paired
A pairing completed and the record is stored.
Reported after server/pair-finalize, once Storage accepted
the record. The record authenticates later connections to that server, and the server
normally rotates the live connection to it with an in-band re-handshake: the session swaps
its keys without reopening the stream, so playback continues and the next connection is
keyed by the same long-term PSK.
Fields
Unpaired
The server dropped its pairing record for this client.
Reported when a paired session receives server/unpair. The record is gone from
Storage by the time the event arrives, and the client closes
the connection: the next connection to that server lands in the Sentinel fallback unless the
host pairs again. The client does not send client/goodbye - the crate has no writer for it
(docs/spec-deviations.md, entry 9) - so the server sees the close without a reason.
A record the host passed through
connect_with_psks is not in a store the client may write, so
the client reports it and ends the connection without removing it: the host owns that
record and has to drop it.
Fields
PairingRequired
A server needs a pairing this client cannot complete with what it holds.
Reported once per connection, never once per message: the situation is decided by the
Noise handshake, so the event fires after Event::Connected and before the session acts
on its first message, and never again while that connection lasts. A plain guest handshake -
an unpaired connection whose server announced the Sentinel key - is not a mismatch and
reports nothing.
Nothing is removed or replaced on either side, and the session continues as an ordinary unpaired one. A server that holds a record for this client will keep the connection in pairing or idle until the host offers pairing again.
Fields
reason: PairingRequiredReasonWhat the server expects and the client cannot provide.
PairingFailed
A pairing attempt ended without a record.
Nothing was stored: the host has to offer pairing again, or act on the reason. The connection itself stays open - a pairing abort is not a connection failure - so the session keeps serving playback in the roles it had.
Fields
reason: PairingFailureWhy the attempt ended.
PairingCode
A dynamic pairing code is ready for the operator.
The code belongs to one attempt and is bound to the Noise handshake and to the two nonces
of that attempt. A client with a display or a speaker shows or speaks it; the operator then
types or scans it into the server. The code does not change across the rounds of an attempt,
so a host that already shows it can ignore a repeat with the same code, while round
tells it that another round is running.
The value is deliberate: it is the method’s whole point, and the host is expected to render it. It is not key material, but it does authorise one pairing, so a host should not keep it longer than the attempt.
Trait Implementations§
Source§impl Debug for Event
impl Debug for Event
Source§fn fmt(&self, formatter: &mut Formatter<'_>) -> Result
fn fmt(&self, formatter: &mut Formatter<'_>) -> Result
Formats an event, redacting the dynamic pairing code it may carry.
A host renders that code deliberately, through the event itself; a Debug format is what a
panic, an assertion or a logging facade writes, and the code authorises one pairing, so it
must not appear there. Every other field is what a log line needs.