1use serde::{Serialize, Deserialize};
5use serde_json::Value as JsonValue;
6use std::borrow::Cow;
7
8pub type PlayerId<'a> = Cow<'a, str>;
11
12
13pub type Timestamp = f64;
14
15#[derive(Debug, Clone, Serialize, Deserialize, Default)]
19#[serde(rename_all = "camelCase")]
20pub struct PlayerMessage<'a> {
21 level: Cow<'a, str>,
31 message: Cow<'a, str>,
32}
33
34impl<'a> PlayerMessage<'a> {
35 pub fn builder(level: impl Into<Cow<'a, str>>, message: impl Into<Cow<'a, str>>) -> PlayerMessageBuilder<'a> {
39 PlayerMessageBuilder {
40 level: level.into(),
41 message: message.into(),
42 }
43 }
44 pub fn level(&self) -> &str { self.level.as_ref() }
54 pub fn message(&self) -> &str { self.message.as_ref() }
55}
56
57
58pub struct PlayerMessageBuilder<'a> {
59 level: Cow<'a, str>,
60 message: Cow<'a, str>,
61}
62
63impl<'a> PlayerMessageBuilder<'a> {
64 pub fn build(self) -> PlayerMessage<'a> {
65 PlayerMessage {
66 level: self.level,
67 message: self.message,
68 }
69 }
70}
71
72#[derive(Debug, Clone, Serialize, Deserialize, Default)]
75#[serde(rename_all = "camelCase")]
76pub struct PlayerProperty<'a> {
77 name: Cow<'a, str>,
78 value: Cow<'a, str>,
79}
80
81impl<'a> PlayerProperty<'a> {
82 pub fn builder(name: impl Into<Cow<'a, str>>, value: impl Into<Cow<'a, str>>) -> PlayerPropertyBuilder<'a> {
86 PlayerPropertyBuilder {
87 name: name.into(),
88 value: value.into(),
89 }
90 }
91 pub fn name(&self) -> &str { self.name.as_ref() }
92 pub fn value(&self) -> &str { self.value.as_ref() }
93}
94
95
96pub struct PlayerPropertyBuilder<'a> {
97 name: Cow<'a, str>,
98 value: Cow<'a, str>,
99}
100
101impl<'a> PlayerPropertyBuilder<'a> {
102 pub fn build(self) -> PlayerProperty<'a> {
103 PlayerProperty {
104 name: self.name,
105 value: self.value,
106 }
107 }
108}
109
110#[derive(Debug, Clone, Serialize, Deserialize, Default)]
113#[serde(rename_all = "camelCase")]
114pub struct PlayerEvent<'a> {
115 timestamp: Timestamp,
116 value: Cow<'a, str>,
117}
118
119impl<'a> PlayerEvent<'a> {
120 pub fn builder(timestamp: Timestamp, value: impl Into<Cow<'a, str>>) -> PlayerEventBuilder<'a> {
124 PlayerEventBuilder {
125 timestamp: timestamp,
126 value: value.into(),
127 }
128 }
129 pub fn timestamp(&self) -> &Timestamp { &self.timestamp }
130 pub fn value(&self) -> &str { self.value.as_ref() }
131}
132
133
134pub struct PlayerEventBuilder<'a> {
135 timestamp: Timestamp,
136 value: Cow<'a, str>,
137}
138
139impl<'a> PlayerEventBuilder<'a> {
140 pub fn build(self) -> PlayerEvent<'a> {
141 PlayerEvent {
142 timestamp: self.timestamp,
143 value: self.value,
144 }
145 }
146}
147
148#[derive(Debug, Clone, Serialize, Deserialize, Default)]
152#[serde(rename_all = "camelCase")]
153pub struct PlayerErrorSourceLocation<'a> {
154 file: Cow<'a, str>,
155 line: i64,
156}
157
158impl<'a> PlayerErrorSourceLocation<'a> {
159 pub fn builder(file: impl Into<Cow<'a, str>>, line: i64) -> PlayerErrorSourceLocationBuilder<'a> {
163 PlayerErrorSourceLocationBuilder {
164 file: file.into(),
165 line: line,
166 }
167 }
168 pub fn file(&self) -> &str { self.file.as_ref() }
169 pub fn line(&self) -> i64 { self.line }
170}
171
172
173pub struct PlayerErrorSourceLocationBuilder<'a> {
174 file: Cow<'a, str>,
175 line: i64,
176}
177
178impl<'a> PlayerErrorSourceLocationBuilder<'a> {
179 pub fn build(self) -> PlayerErrorSourceLocation<'a> {
180 PlayerErrorSourceLocation {
181 file: self.file,
182 line: self.line,
183 }
184 }
185}
186
187#[derive(Debug, Clone, Serialize, Deserialize, Default)]
190#[serde(rename_all = "camelCase")]
191pub struct PlayerError<'a> {
192 #[serde(rename = "errorType")]
193 error_type: Cow<'a, str>,
194 code: i64,
197 stack: Vec<PlayerErrorSourceLocation<'a>>,
199 cause: Vec<Box<PlayerError<'a>>>,
202 data: serde_json::Map<String, JsonValue>,
204}
205
206impl<'a> PlayerError<'a> {
207 pub fn builder(error_type: impl Into<Cow<'a, str>>, code: i64, stack: Vec<PlayerErrorSourceLocation<'a>>, cause: Vec<Box<PlayerError<'a>>>, data: serde_json::Map<String, JsonValue>) -> PlayerErrorBuilder<'a> {
214 PlayerErrorBuilder {
215 error_type: error_type.into(),
216 code: code,
217 stack: stack,
218 cause: cause,
219 data: data,
220 }
221 }
222 pub fn error_type(&self) -> &str { self.error_type.as_ref() }
223 pub fn code(&self) -> i64 { self.code }
226 pub fn stack(&self) -> &[PlayerErrorSourceLocation<'a>] { &self.stack }
228 pub fn cause(&self) -> &[Box<PlayerError<'a>>] { &self.cause }
231 pub fn data(&self) -> &serde_json::Map<String, JsonValue> { &self.data }
233}
234
235
236pub struct PlayerErrorBuilder<'a> {
237 error_type: Cow<'a, str>,
238 code: i64,
239 stack: Vec<PlayerErrorSourceLocation<'a>>,
240 cause: Vec<Box<PlayerError<'a>>>,
241 data: serde_json::Map<String, JsonValue>,
242}
243
244impl<'a> PlayerErrorBuilder<'a> {
245 pub fn build(self) -> PlayerError<'a> {
246 PlayerError {
247 error_type: self.error_type,
248 code: self.code,
249 stack: self.stack,
250 cause: self.cause,
251 data: self.data,
252 }
253 }
254}
255
256
257#[derive(Debug, Clone, Serialize, Deserialize, Default)]
258#[serde(rename_all = "camelCase")]
259pub struct Player<'a> {
260 #[serde(rename = "playerId")]
261 player_id: PlayerId<'a>,
262 #[serde(skip_serializing_if = "Option::is_none", rename = "domNodeId")]
263 dom_node_id: Option<crate::dom::BackendNodeId>,
264}
265
266impl<'a> Player<'a> {
267 pub fn builder(player_id: impl Into<PlayerId<'a>>) -> PlayerBuilder<'a> {
270 PlayerBuilder {
271 player_id: player_id.into(),
272 dom_node_id: None,
273 }
274 }
275 pub fn player_id(&self) -> &PlayerId<'a> { &self.player_id }
276 pub fn dom_node_id(&self) -> Option<&crate::dom::BackendNodeId> { self.dom_node_id.as_ref() }
277}
278
279
280pub struct PlayerBuilder<'a> {
281 player_id: PlayerId<'a>,
282 dom_node_id: Option<crate::dom::BackendNodeId>,
283}
284
285impl<'a> PlayerBuilder<'a> {
286 pub fn dom_node_id(mut self, dom_node_id: crate::dom::BackendNodeId) -> Self { self.dom_node_id = Some(dom_node_id); self }
287 pub fn build(self) -> Player<'a> {
288 Player {
289 player_id: self.player_id,
290 dom_node_id: self.dom_node_id,
291 }
292 }
293}
294
295#[derive(Debug, Clone, Serialize, Deserialize, Default)]
296pub struct EnableParams {}
297
298impl EnableParams { pub const METHOD: &'static str = "Media.enable"; }
299
300impl<'a> crate::CdpCommand<'a> for EnableParams {
301 const METHOD: &'static str = "Media.enable";
302 type Response = crate::EmptyReturns;
303}
304
305#[derive(Debug, Clone, Serialize, Deserialize, Default)]
306pub struct DisableParams {}
307
308impl DisableParams { pub const METHOD: &'static str = "Media.disable"; }
309
310impl<'a> crate::CdpCommand<'a> for DisableParams {
311 const METHOD: &'static str = "Media.disable";
312 type Response = crate::EmptyReturns;
313}