Skip to main content

browser_protocol/cast/
mod.rs

1//! A domain for interacting with Cast, Presentation API, and Remote Playback API
2//! functionalities.
3
4
5use serde::{Serialize, Deserialize};
6use serde_json::Value as JsonValue;
7use std::borrow::Cow;
8
9
10#[derive(Debug, Clone, Serialize, Deserialize, Default)]
11#[serde(rename_all = "camelCase")]
12pub struct Sink<'a> {
13    name: Cow<'a, str>,
14    id: Cow<'a, str>,
15    /// Text describing the current session. Present only if there is an active
16    /// session on the sink.
17    #[serde(skip_serializing_if = "Option::is_none")]
18    session: Option<Cow<'a, str>>,
19}
20
21impl<'a> Sink<'a> {
22    pub fn builder(name: impl Into<Cow<'a, str>>, id: impl Into<Cow<'a, str>>) -> SinkBuilder<'a> {
23        SinkBuilder {
24            name: name.into(),
25            id: id.into(),
26            session: None,
27        }
28    }
29    pub fn name(&self) -> &str { self.name.as_ref() }
30    pub fn id(&self) -> &str { self.id.as_ref() }
31    pub fn session(&self) -> Option<&str> { self.session.as_deref() }
32}
33
34
35pub struct SinkBuilder<'a> {
36    name: Cow<'a, str>,
37    id: Cow<'a, str>,
38    session: Option<Cow<'a, str>>,
39}
40
41impl<'a> SinkBuilder<'a> {
42    /// Text describing the current session. Present only if there is an active
43    /// session on the sink.
44    pub fn session(mut self, session: impl Into<Cow<'a, str>>) -> Self { self.session = Some(session.into()); self }
45    pub fn build(self) -> Sink<'a> {
46        Sink {
47            name: self.name,
48            id: self.id,
49            session: self.session,
50        }
51    }
52}
53
54/// Starts observing for sinks that can be used for tab mirroring, and if set,
55/// sinks compatible with |presentationUrl| as well. When sinks are found, a
56/// |sinksUpdated| event is fired.
57/// Also starts observing for issue messages. When an issue is added or removed,
58/// an |issueUpdated| event is fired.
59
60#[derive(Debug, Clone, Serialize, Deserialize, Default)]
61#[serde(rename_all = "camelCase")]
62pub struct EnableParams<'a> {
63    #[serde(skip_serializing_if = "Option::is_none")]
64    presentationUrl: Option<Cow<'a, str>>,
65}
66
67impl<'a> EnableParams<'a> {
68    pub fn builder() -> EnableParamsBuilder<'a> {
69        EnableParamsBuilder {
70            presentationUrl: None,
71        }
72    }
73    pub fn presentationUrl(&self) -> Option<&str> { self.presentationUrl.as_deref() }
74}
75
76#[derive(Default)]
77pub struct EnableParamsBuilder<'a> {
78    presentationUrl: Option<Cow<'a, str>>,
79}
80
81impl<'a> EnableParamsBuilder<'a> {
82    pub fn presentationUrl(mut self, presentationUrl: impl Into<Cow<'a, str>>) -> Self { self.presentationUrl = Some(presentationUrl.into()); self }
83    pub fn build(self) -> EnableParams<'a> {
84        EnableParams {
85            presentationUrl: self.presentationUrl,
86        }
87    }
88}
89
90impl<'a> EnableParams<'a> { pub const METHOD: &'static str = "Cast.enable"; }
91
92impl<'a> crate::CdpCommand<'a> for EnableParams<'a> {
93    const METHOD: &'static str = "Cast.enable";
94    type Response = crate::EmptyReturns;
95}
96
97#[derive(Debug, Clone, Serialize, Deserialize, Default)]
98pub struct DisableParams {}
99
100impl DisableParams { pub const METHOD: &'static str = "Cast.disable"; }
101
102impl<'a> crate::CdpCommand<'a> for DisableParams {
103    const METHOD: &'static str = "Cast.disable";
104    type Response = crate::EmptyReturns;
105}
106
107/// Sets a sink to be used when the web page requests the browser to choose a
108/// sink via Presentation API, Remote Playback API, or Cast SDK.
109
110#[derive(Debug, Clone, Serialize, Deserialize, Default)]
111#[serde(rename_all = "camelCase")]
112pub struct SetSinkToUseParams<'a> {
113    sinkName: Cow<'a, str>,
114}
115
116impl<'a> SetSinkToUseParams<'a> {
117    pub fn builder(sinkName: impl Into<Cow<'a, str>>) -> SetSinkToUseParamsBuilder<'a> {
118        SetSinkToUseParamsBuilder {
119            sinkName: sinkName.into(),
120        }
121    }
122    pub fn sinkName(&self) -> &str { self.sinkName.as_ref() }
123}
124
125
126pub struct SetSinkToUseParamsBuilder<'a> {
127    sinkName: Cow<'a, str>,
128}
129
130impl<'a> SetSinkToUseParamsBuilder<'a> {
131    pub fn build(self) -> SetSinkToUseParams<'a> {
132        SetSinkToUseParams {
133            sinkName: self.sinkName,
134        }
135    }
136}
137
138impl<'a> SetSinkToUseParams<'a> { pub const METHOD: &'static str = "Cast.setSinkToUse"; }
139
140impl<'a> crate::CdpCommand<'a> for SetSinkToUseParams<'a> {
141    const METHOD: &'static str = "Cast.setSinkToUse";
142    type Response = crate::EmptyReturns;
143}
144
145/// Starts mirroring the desktop to the sink.
146
147#[derive(Debug, Clone, Serialize, Deserialize, Default)]
148#[serde(rename_all = "camelCase")]
149pub struct StartDesktopMirroringParams<'a> {
150    sinkName: Cow<'a, str>,
151}
152
153impl<'a> StartDesktopMirroringParams<'a> {
154    pub fn builder(sinkName: impl Into<Cow<'a, str>>) -> StartDesktopMirroringParamsBuilder<'a> {
155        StartDesktopMirroringParamsBuilder {
156            sinkName: sinkName.into(),
157        }
158    }
159    pub fn sinkName(&self) -> &str { self.sinkName.as_ref() }
160}
161
162
163pub struct StartDesktopMirroringParamsBuilder<'a> {
164    sinkName: Cow<'a, str>,
165}
166
167impl<'a> StartDesktopMirroringParamsBuilder<'a> {
168    pub fn build(self) -> StartDesktopMirroringParams<'a> {
169        StartDesktopMirroringParams {
170            sinkName: self.sinkName,
171        }
172    }
173}
174
175impl<'a> StartDesktopMirroringParams<'a> { pub const METHOD: &'static str = "Cast.startDesktopMirroring"; }
176
177impl<'a> crate::CdpCommand<'a> for StartDesktopMirroringParams<'a> {
178    const METHOD: &'static str = "Cast.startDesktopMirroring";
179    type Response = crate::EmptyReturns;
180}
181
182/// Starts mirroring the tab to the sink.
183
184#[derive(Debug, Clone, Serialize, Deserialize, Default)]
185#[serde(rename_all = "camelCase")]
186pub struct StartTabMirroringParams<'a> {
187    sinkName: Cow<'a, str>,
188}
189
190impl<'a> StartTabMirroringParams<'a> {
191    pub fn builder(sinkName: impl Into<Cow<'a, str>>) -> StartTabMirroringParamsBuilder<'a> {
192        StartTabMirroringParamsBuilder {
193            sinkName: sinkName.into(),
194        }
195    }
196    pub fn sinkName(&self) -> &str { self.sinkName.as_ref() }
197}
198
199
200pub struct StartTabMirroringParamsBuilder<'a> {
201    sinkName: Cow<'a, str>,
202}
203
204impl<'a> StartTabMirroringParamsBuilder<'a> {
205    pub fn build(self) -> StartTabMirroringParams<'a> {
206        StartTabMirroringParams {
207            sinkName: self.sinkName,
208        }
209    }
210}
211
212impl<'a> StartTabMirroringParams<'a> { pub const METHOD: &'static str = "Cast.startTabMirroring"; }
213
214impl<'a> crate::CdpCommand<'a> for StartTabMirroringParams<'a> {
215    const METHOD: &'static str = "Cast.startTabMirroring";
216    type Response = crate::EmptyReturns;
217}
218
219/// Stops the active Cast session on the sink.
220
221#[derive(Debug, Clone, Serialize, Deserialize, Default)]
222#[serde(rename_all = "camelCase")]
223pub struct StopCastingParams<'a> {
224    sinkName: Cow<'a, str>,
225}
226
227impl<'a> StopCastingParams<'a> {
228    pub fn builder(sinkName: impl Into<Cow<'a, str>>) -> StopCastingParamsBuilder<'a> {
229        StopCastingParamsBuilder {
230            sinkName: sinkName.into(),
231        }
232    }
233    pub fn sinkName(&self) -> &str { self.sinkName.as_ref() }
234}
235
236
237pub struct StopCastingParamsBuilder<'a> {
238    sinkName: Cow<'a, str>,
239}
240
241impl<'a> StopCastingParamsBuilder<'a> {
242    pub fn build(self) -> StopCastingParams<'a> {
243        StopCastingParams {
244            sinkName: self.sinkName,
245        }
246    }
247}
248
249impl<'a> StopCastingParams<'a> { pub const METHOD: &'static str = "Cast.stopCasting"; }
250
251impl<'a> crate::CdpCommand<'a> for StopCastingParams<'a> {
252    const METHOD: &'static str = "Cast.stopCasting";
253    type Response = crate::EmptyReturns;
254}