Skip to main content

kdeconnect_proto/packet/
system_volume.rs

1//! The SystemVolume plugin allows sharing volume controls between devices.
2use serde::{Deserialize, Serialize};
3
4#[cfg(not(feature = "std"))]
5use alloc::{string::String, vec::Vec};
6
7/// An audio stream object.
8#[derive(Serialize, Deserialize, Debug, Clone)]
9#[serde(rename_all = "camelCase")]
10pub struct SystemVolumeStream {
11    /// The stream name.
12    pub name: String,
13
14    /// The stream display name.
15    pub description: String,
16
17    /// Whether the stream is enabled.
18    #[serde(skip_serializing_if = "Option::is_none")]
19    #[serde(default)]
20    pub enabled: Option<bool>,
21
22    /// Whether the stream is muted.
23    pub muted: bool,
24
25    /// The stream max volume level.
26    #[serde(skip_serializing_if = "Option::is_none")]
27    #[serde(default)]
28    pub max_volume: Option<u64>,
29
30    /// The stream volume level.
31    pub volume: u64,
32}
33
34/// This packet is a mixer stream state update.
35///
36/// <https://invent.kde.org/network/kdeconnect-meta/blob/master/protocol.md#kdeconnectsystemvolume>
37#[derive(Serialize, Deserialize, Debug, Clone)]
38#[serde(rename_all = "camelCase")]
39pub struct SystemVolumePacket {
40    /// The list of audio streams.
41    #[serde(skip_serializing_if = "Option::is_none")]
42    #[serde(default)]
43    pub sink_list: Option<Vec<SystemVolumeStream>>,
44
45    /// The stream name.
46    #[serde(skip_serializing_if = "Option::is_none")]
47    #[serde(default)]
48    pub name: Option<String>,
49
50    /// Whether the stream is enabled.
51    #[serde(skip_serializing_if = "Option::is_none")]
52    #[serde(default)]
53    pub enabled: Option<bool>,
54
55    /// Whether the stream is muted.
56    #[serde(skip_serializing_if = "Option::is_none")]
57    #[serde(default)]
58    pub muted: Option<bool>,
59
60    /// The stream volume level.
61    #[serde(skip_serializing_if = "Option::is_none")]
62    #[serde(default)]
63    pub volume: Option<u64>,
64}
65
66/// This packet is a audio stream request. It is used to request both the list of streams and changes to those streams.
67///
68/// <https://invent.kde.org/network/kdeconnect-meta/blob/master/protocol.md#kdeconnectsystemvolumerequest>
69#[derive(Serialize, Deserialize, Debug, Clone)]
70#[serde(rename_all = "camelCase")]
71pub struct SystemVolumeRequestPacket {
72    /// Indicates this is a request for the stream list.
73    #[serde(skip_serializing_if = "Option::is_none")]
74    #[serde(default)]
75    pub request_sinks: Option<bool>,
76
77    /// The name of a stream. If the packet contains this field, it is a request to adjust a stream.
78    #[serde(skip_serializing_if = "Option::is_none")]
79    #[serde(default)]
80    pub name: Option<String>,
81
82    /// Indicates the stream should become the active default. Always true if present.
83    #[serde(skip_serializing_if = "Option::is_none")]
84    #[serde(default)]
85    pub enabled: Option<bool>,
86
87    /// The requested mute state.
88    #[serde(skip_serializing_if = "Option::is_none")]
89    #[serde(default)]
90    pub muted: Option<bool>,
91
92    /// The requested volume. The maximum value is provided by the maxVolume field of the stream.
93    #[serde(skip_serializing_if = "Option::is_none")]
94    #[serde(default)]
95    pub volume: Option<u64>,
96}