kdeconnect-proto 0.2.0

A pure Rust modular implementation of the KDE Connect protocol
Documentation
//! The SystemVolume plugin allows sharing volume controls between devices.
use serde::{Deserialize, Serialize};

#[cfg(not(feature = "std"))]
use alloc::{string::String, vec::Vec};

/// An audio stream object.
#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct SystemVolumeStream {
    /// The stream name.
    pub name: String,

    /// The stream display name.
    pub description: String,

    /// Whether the stream is enabled.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(default)]
    pub enabled: Option<bool>,

    /// Whether the stream is muted.
    pub muted: bool,

    /// The stream max volume level.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(default)]
    pub max_volume: Option<u64>,

    /// The stream volume level.
    pub volume: u64,
}

/// This packet is a mixer stream state update.
///
/// <https://invent.kde.org/network/kdeconnect-meta/blob/master/protocol.md#kdeconnectsystemvolume>
#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct SystemVolumePacket {
    /// The list of audio streams.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(default)]
    pub sink_list: Option<Vec<SystemVolumeStream>>,

    /// The stream name.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(default)]
    pub name: Option<String>,

    /// Whether the stream is enabled.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(default)]
    pub enabled: Option<bool>,

    /// Whether the stream is muted.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(default)]
    pub muted: Option<bool>,

    /// The stream volume level.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(default)]
    pub volume: Option<u64>,
}

/// This packet is a audio stream request. It is used to request both the list of streams and changes to those streams.
///
/// <https://invent.kde.org/network/kdeconnect-meta/blob/master/protocol.md#kdeconnectsystemvolumerequest>
#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct SystemVolumeRequestPacket {
    /// Indicates this is a request for the stream list.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(default)]
    pub request_sinks: Option<bool>,

    /// The name of a stream. If the packet contains this field, it is a request to adjust a stream.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(default)]
    pub name: Option<String>,

    /// Indicates the stream should become the active default. Always true if present.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(default)]
    pub enabled: Option<bool>,

    /// The requested mute state.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(default)]
    pub muted: Option<bool>,

    /// The requested volume. The maximum value is provided by the maxVolume field of the stream.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(default)]
    pub volume: Option<u64>,
}