Skip to main content

Event

Enum Event 

Source
#[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
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

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

§server_id: String

The server’s static public key as 43 base64url characters.

§encrypted: bool

Whether the connection is encrypted; always true.

§

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

§reason: String

Why the attempt ended.

§retry_in: Duration

How long to wait before the next attempt; zero when none follows.

§

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.

Fields

§reason: String

Why the server refused the init.

§

StreamStart

A stream was announced with the given format.

The sink has been opened for this format before the event is emitted.

Fields

§format: AudioFormat

Format 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: StreamEndReason

Why 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

§from_timestamp: Option<i64>

Server timestamp the audio should resume from, when the server named one.

§

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.

Fields

§late_by: Duration

Worst lateness in the window.

§dropped: u64

Frames dropped in the window.

§

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

§title: String

Track title.

§artist: String

Track artist.

§album: String

Album title.

§album_artist: String

Album artist.

§artwork_url: String

URL of the artwork image, empty when the server sent none.

§progress_ms: Option<u64>

Position within the track in milliseconds, when the server reports one.

§duration_ms: Option<u64>

Track length in milliseconds, when the server reports one.

§playback_speed: u32

Playback 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.

Fields

§len: usize

Length of the value in bytes, which is all a log line needs.

§

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

§requested: u8

Level the server asked for, as it arrived on the wire.

A non-conformant server can send a value above 100; it is reported unchanged so a host can log it, while applied always stays inside the protocol’s range.

§applied: u8

Level that was applied, always in the range 0-100.

§muted: Option<bool>

Mute state that was requested, absent for a volume command.

§

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

§requested: u32

Delay the server asked for, as it arrived on the wire.

§applied: u32

Delay the host should apply, always in the range 0-5000 ms.

§

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

§server_id: String

Static public key of the server the record belongs to, as 43 base64url characters.

§

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

§server_id: String

Static public key of the server that dropped the record, as 43 base64url characters.

§

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: String

Static public key of the server this requirement concerns, as 43 base64url characters.

§reason: PairingRequiredReason

Which 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: PairingFailure

Why 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.

Fields

§code: String

The code to show: six digits in the digits format, a version-1 token in qr_code.

§format: CodeFormat

Emission format the server activated.

§round: u32

Round this emission belongs to, counting from one.

Trait Implementations§

Source§

impl Clone for Event

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 Event

Source§

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.

Source§

impl Eq for Event

Source§

impl PartialEq for Event

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Event

Auto Trait Implementations§

§

impl Forget for Event

§

impl Freeze for Event

§

impl Move for Event

§

impl RefUnwindSafe for Event

§

impl Send for Event

§

impl Sync for Event

§

impl Unpin for Event

§

impl UnsafeUnpin for Event

§

impl UnwindSafe for Event

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.