1use serde::{Deserialize, Serialize};
2
3pub use super::client::Host;
4use super::{group::Group, stream::Stream};
5
6#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
9pub struct Server {
10 pub server: ServerDetails,
11 pub groups: Vec<Group>,
12 pub streams: Vec<Stream>,
13}
14
15#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
16pub struct ServerDetails {
17 pub host: Host,
18 pub snapserver: Snapserver,
19}
20
21#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
22pub struct Snapserver {
23 pub name: String,
24 #[serde(rename = "protocolVersion")]
25 pub protocol_version: usize,
26 #[serde(rename = "controlProtocolVersion")]
27 pub control_protocol_version: usize,
28 pub version: String,
29}
30
31#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
33pub struct GetRpcVersionResult {
34 pub major: usize,
35 pub minor: usize,
36 pub patch: usize,
37}
38
39#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
40pub struct GetStatusResult {
41 pub server: Server,
42}
43
44#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
45pub struct DeleteClientParams {
46 pub id: String,
47}
48
49#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
50pub struct DeleteClientResult {
51 pub server: Server,
52}
53
54#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
56pub struct OnUpdateParams {
57 pub server: Server,
58}
59
60#[cfg(test)]
61mod tests {
62 use std::collections::HashMap;
63
64 use crate::protocol::{
65 client::{Client, ClientConfig, ClientVolume, Host, LastSeen, Snapclient},
66 stream::StreamUri,
67 };
68
69 use super::*;
70
71 #[test]
72 fn serialize_server() {
73 let server = Server {
74 groups: vec![Group {
75 id: "4dcc4e3b-c699-a04b-7f0c-8260d23c43e1".to_string(),
76 muted: false,
77 name: "".to_string(),
78 stream_id: "stream 2".to_string(),
79 clients: vec![
80 Client {
81 config: ClientConfig {
82 instance: 1,
83 latency: 0,
84 name: "".to_string(),
85 volume: ClientVolume {
86 muted: false,
87 percent: 100,
88 },
89 },
90 connected: true,
91 host: Host {
92 arch: "x86_64".to_string(),
93 ip: "127.0.0.1".to_string(),
94 mac: "00:21:6a:7d:74:fc".to_string(),
95 name: "T400".to_string(),
96 os: "Linux Mint 17.3 Rosa".to_string(),
97 },
98 id: "00:21:6a:7d:74:fc".to_string(),
99 last_seen: LastSeen {
100 sec: 1488025905,
101 usec: 45238,
102 },
103 snapclient: Snapclient {
104 name: "Snapclient".to_string(),
105 protocol_version: 2,
106 version: "0.10.0".to_string(),
107 },
108 },
109 Client {
110 config: ClientConfig {
111 instance: 2,
112 latency: 6,
113 name: "123 456".to_string(),
114 volume: ClientVolume {
115 muted: false,
116 percent: 48,
117 },
118 },
119 connected: true,
120 host: Host {
121 arch: "x86_64".to_string(),
122 ip: "127.0.0.1".to_string(),
123 mac: "00:21:6a:7d:74:fc".to_string(),
124 name: "T400".to_string(),
125 os: "Linux Mint 17.3 Rosa".to_string(),
126 },
127 id: "00:21:6a:7d:74:fc#2".to_string(),
128 last_seen: LastSeen {
129 sec: 1488025901,
130 usec: 864472,
131 },
132 snapclient: Snapclient {
133 name: "Snapclient".to_string(),
134 protocol_version: 2,
135 version: "0.10.0".to_string(),
136 },
137 },
138 ],
139 }],
140 server: ServerDetails {
141 host: Host {
142 arch: "x86_64".to_string(),
143 ip: "".to_string(),
144 mac: "".to_string(),
145 name: "T400".to_string(),
146 os: "Linux Mint 17.3 Rosa".to_string(),
147 },
148 snapserver: Snapserver {
149 control_protocol_version: 1,
150 name: "Snapserver".to_string(),
151 protocol_version: 1,
152 version: "0.10.0".to_string(),
153 },
154 },
155 streams: vec![
156 Stream {
157 id: "stream 1".to_string(),
158 status: "idle".into(),
159 properties: None,
160 uri: StreamUri {
161 fragment: "".to_string(),
162 host: "".to_string(),
163 path: "/tmp/snapfifo".to_string(),
164 query: HashMap::new(),
165 raw: "pipe:///tmp/snapfifo?name=stream 1".to_string(),
166 scheme: "pipe".to_string(),
167 },
168 },
169 Stream {
170 id: "stream 2".to_string(),
171 status: "idle".into(),
172 properties: None,
173 uri: StreamUri {
174 fragment: "".to_string(),
175 host: "".to_string(),
176 path: "/tmp/snapfifo".to_string(),
177 query: HashMap::new(),
178 raw: "pipe:///tmp/snapfifo?name=stream 2".to_string(),
179 scheme: "pipe".to_string(),
180 },
181 },
182 ],
183 };
184
185 serde_json::to_string(&server).unwrap();
186 }
187
188 #[test]
189 fn deserialize_server() {
190 let json = r#"{"groups":[{"clients":[{"config":{"instance":2,"latency":6,"name":"123 456","volume":{"muted":false,"percent":48}},"connected":true,"host":{"arch":"x86_64","ip":"127.0.0.1","mac":"00:21:6a:7d:74:fc","name":"T400","os":"Linux Mint 17.3 Rosa"},"id":"00:21:6a:7d:74:fc#2","lastSeen":{"sec":1488025901,"usec":864472},"snapclient":{"name":"Snapclient","protocolVersion":2,"version":"0.10.0"}},{"config":{"instance":1,"latency":0,"name":"","volume":{"muted":false,"percent":100}},"connected":true,"host":{"arch":"x86_64","ip":"127.0.0.1","mac":"00:21:6a:7d:74:fc","name":"T400","os":"Linux Mint 17.3 Rosa"},"id":"00:21:6a:7d:74:fc","lastSeen":{"sec":1488025905,"usec":45238},"snapclient":{"name":"Snapclient","protocolVersion":2,"version":"0.10.0"}}],"id":"4dcc4e3b-c699-a04b-7f0c-8260d23c43e1","muted":false,"name":"","stream_id":"stream 2"}],"server":{"host":{"arch":"x86_64","ip":"","mac":"","name":"T400","os":"Linux Mint 17.3 Rosa"},"snapserver":{"controlProtocolVersion":1,"name":"Snapserver","protocolVersion":1,"version":"0.10.0"}},"streams":[{"id":"stream 1","status":"idle","uri":{"fragment":"","host":"","path":"/tmp/snapfifo","query":{"chunk_ms":"20","codec":"flac","name":"stream 1","sampleformat":"48000:16:2"},"raw":"pipe:///tmp/snapfifo?name=stream 1","scheme":"pipe"}},{"id":"stream 2","status":"idle","uri":{"fragment":"","host":"","path":"/tmp/snapfifo","query":{"chunk_ms":"20","codec":"flac","name":"stream 2","sampleformat":"48000:16:2"},"raw":"pipe:///tmp/snapfifo?name=stream 2","scheme":"pipe"}}]}"#;
191 let server: Server = serde_json::from_str(json).unwrap();
192
193 assert_eq!(server.server.host.name, "T400");
194 }
195}