music_player_graphql/schema/objects/
device.rs1use async_graphql::*;
2use music_player_discovery::{SERVICE_NAME, XBMC_SERVICE_NAME};
3use music_player_types::types;
4use serde::Serialize;
5
6#[derive(Enum, Copy, Clone, Eq, PartialEq)]
7pub enum App {
8 MusicPlayer,
9 XBMC,
10}
11
12#[derive(Default, Clone, Serialize)]
13pub struct Device {
14 pub id: ID,
15 pub name: String,
16 pub host: String,
17 pub port: u16,
18 pub service: String,
19 pub app: String,
20 pub is_connected: bool,
21}
22
23#[Object]
24impl Device {
25 async fn id(&self) -> &str {
26 &self.id
27 }
28
29 async fn name(&self) -> &str {
30 &self.name
31 }
32
33 async fn host(&self) -> &str {
34 &self.host
35 }
36
37 async fn port(&self) -> u16 {
38 self.port
39 }
40
41 async fn service(&self) -> &str {
42 &self.service
43 }
44
45 async fn app(&self) -> &str {
46 &self.app
47 }
48
49 async fn is_connected(&self) -> bool {
50 self.is_connected
51 }
52}
53
54impl From<types::Device> for Device {
55 fn from(device: types::Device) -> Self {
56 Self {
57 id: ID::from(device.id),
58 name: device.name,
59 host: device.host,
60 port: device.port,
61 service: device.service,
62 app: device.app,
63 is_connected: device.is_connected,
64 }
65 }
66}
67
68#[derive(Default, Clone, Serialize)]
69pub struct ConnectedDevice {
70 pub id: ID,
71 pub name: String,
72 pub host: String,
73 pub port: u16,
74 pub service: String,
75 pub app: String,
76 pub is_connected: bool,
77}
78
79#[Object]
80impl ConnectedDevice {
81 async fn id(&self) -> &str {
82 &self.id
83 }
84
85 async fn name(&self) -> &str {
86 &self.name
87 }
88
89 async fn host(&self) -> &str {
90 &self.host
91 }
92
93 async fn port(&self) -> u16 {
94 self.port
95 }
96
97 async fn service(&self) -> &str {
98 &self.service
99 }
100
101 async fn app(&self) -> &str {
102 &self.app
103 }
104
105 async fn is_connected(&self) -> bool {
106 self.is_connected
107 }
108}
109
110impl From<types::Device> for ConnectedDevice {
111 fn from(device: types::Device) -> Self {
112 Self {
113 id: ID::from(device.id),
114 name: device.name,
115 host: device.host,
116 port: device.port,
117 service: device.service,
118 app: device.app,
119 is_connected: true,
120 }
121 }
122}
123
124#[derive(Default, Clone, Serialize)]
125pub struct DisconnectedDevice {
126 pub id: ID,
127 pub name: String,
128 pub host: String,
129 pub port: u16,
130 pub service: String,
131 pub app: String,
132 pub is_connected: bool,
133}
134
135#[Object]
136impl DisconnectedDevice {
137 async fn id(&self) -> &str {
138 &self.id
139 }
140
141 async fn name(&self) -> &str {
142 &self.name
143 }
144
145 async fn host(&self) -> &str {
146 &self.host
147 }
148
149 async fn port(&self) -> u16 {
150 self.port
151 }
152
153 async fn service(&self) -> &str {
154 &self.service
155 }
156
157 async fn app(&self) -> &str {
158 &self.app
159 }
160
161 async fn is_connected(&self) -> bool {
162 self.is_connected
163 }
164}
165
166impl From<types::Device> for DisconnectedDevice {
167 fn from(device: types::Device) -> Self {
168 Self {
169 id: ID::from(device.id),
170 name: device.name,
171 host: device.host,
172 port: device.port,
173 service: device.service,
174 app: device.app,
175 is_connected: false,
176 }
177 }
178}