#[non_exhaustive]pub enum Event {
Show 17 variants
Connected {
server_id: String,
encrypted: bool,
},
Disconnected {
reason: String,
retry_in: Duration,
},
ServerError {
reason: String,
},
StreamStart {
format: AudioFormat,
},
StreamEnd {
reason: StreamEndReason,
},
StreamClear {
from_timestamp: Option<i64>,
},
LateAudio {
late_by: Duration,
dropped: u64,
},
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),
GroupIdNotCanonical {
len: usize,
},
Volume {
requested: u8,
applied: u8,
muted: Option<bool>,
},
OutputDelay {
requested: u32,
applied: u32,
},
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,
and for every connection of an advertising client, which does not dial at all and waits for
the next server instead.
Fields
ServerError
The server rejected the connection’s client/init with server/error.
Reported during the cleartext exchange, before Event::Connected, and followed by
Event::Disconnected because the server closes after it. reason is the wire value
carried verbatim: unsupported_version, unsupported_suite and malformed are the ones
this revision defines, and an unknown value is what a newer server sends. The message is
unauthenticated, so the reason is a hint for logging and operator display, not a verified
fact.
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 buffered audio is discarded or 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
LateAudio
Audio was dropped as late or because the playout queue was full.
roles/player/v1.md lets a client drop a chunk whose deadline already passed instead of
playing it late, and this client does. late_by is the worst lateness in the reporting
window; it is zero when only a full queue dropped frames, which were not late themselves.
dropped counts every frame the window dropped - late arrivals and capacity overruns
together.
Reported at most once per second while it happens, and never for a frame that was merely due. A burst of drops is one report; when the interval elapses with no further drop, the frames accumulated since the last report follow as one more event, so the tail of a burst is not lost. Diagnostic only: the frames are dropped either way, and the host has nothing to recover.
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.
GroupIdNotCanonical
The server sent a group_id the spec does not allow, and the client accepted it.
messaging.md gives group_id as 32 server-chosen bytes in 43 base64url characters and
calls any other value a protocol error. The default configuration tolerates a well-formed
value instead - one that is non-empty, at most 128 bytes and free of control characters -
because a real server sends a UUID. The event reports the departure so a host can log it or
surface it to the operator; it never carries the identifier itself.
Reported at most once per connection, however many non-canonical updates arrive. It is not
reported for a canonical identifier, and it does not exist when
ClientConfig::strict_group_id is set, because that configuration closes the connection
instead. An empty, oversized or control-character value is a protocol error in both modes.
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
OutputDelay
The server asked this player to change its output delay.
Sent only while ClientConfig::output_delay_control is set. A value above the protocol’s
0-5000 ms is capped to 5000 (deviation 21); a negative one is dropped with the malformed
message it arrives in. The host applies applied to its sink and persists it as
roles/player/v1.md requires. The session then reports what the sink returns in a
client/state: at once when the host calls ControlHandle::output_delay_applied, and
otherwise from a single fallback read of the sink half a second after the command (a value
the sink has not adopted by then waits for the next timing poll, after a clock burst).
The event follows every accepted command, also when applied equals the delay already in
force, so a host must tolerate repeats.
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 says
goodbye with reason unpaired and closes the connection: the next connection to that
server lands in the Sentinel fallback unless the host pairs again.
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.
Two situations report it, each with its own PairingRequiredReason.
The handshake reports a credential mismatch 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 for that reason while the
connection lasts. A plain guest handshake - an unpaired connection whose server announced the
Sentinel key - is not a mismatch and reports nothing.
The second situation is a refused activation: unpaired access is off and the server sent a
server/activate that would be admissible if it were on. The value is
ClientConfig::unpaired_access unless ControlHandle::set_unpaired_access changed it on
this connection. That report fires at most once, immediately before the client closes the
connection with client/goodbye reason pairing_required, and never for a session whose
setting admits unpaired access. A connection the host closes because it turned the setting
off reports no such event: that is a host choice, not a refused activation. One connection
can therefore report this event twice, once per reason, when the handshake found a
credential mismatch and the activation is then refused.
In the credential-mismatch case 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
server_id: StringStatic public key of the server this requirement concerns, as 43 base64url characters.
reason: PairingRequiredReasonWhich situation produced the requirement: a credential mismatch, or a refused unpaired session.
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.