viewpoint_cdp/protocol/page_screencast/
mod.rs

1//! Page screencast types.
2//!
3//! Types for Page.startScreencast, Page.stopScreencast, and related events.
4
5use serde::{Deserialize, Serialize};
6
7/// Screencast frame format.
8#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Default)]
9#[serde(rename_all = "lowercase")]
10pub enum ScreencastFormat {
11    /// JPEG format.
12    #[default]
13    Jpeg,
14    /// PNG format.
15    Png,
16}
17
18/// Parameters for Page.startScreencast.
19#[derive(Debug, Clone, Serialize, Default)]
20#[serde(rename_all = "camelCase")]
21pub struct StartScreencastParams {
22    /// Image compression format.
23    #[serde(skip_serializing_if = "Option::is_none")]
24    pub format: Option<ScreencastFormat>,
25    /// Compression quality from range [0..100].
26    #[serde(skip_serializing_if = "Option::is_none")]
27    pub quality: Option<i32>,
28    /// Maximum screenshot width.
29    #[serde(skip_serializing_if = "Option::is_none")]
30    pub max_width: Option<i32>,
31    /// Maximum screenshot height.
32    #[serde(skip_serializing_if = "Option::is_none")]
33    pub max_height: Option<i32>,
34    /// Send every n-th frame.
35    #[serde(skip_serializing_if = "Option::is_none")]
36    pub every_nth_frame: Option<i32>,
37}
38
39impl StartScreencastParams {
40    /// Create new screencast parameters.
41    pub fn new() -> Self {
42        Self::default()
43    }
44
45    /// Set the image format.
46    #[must_use]
47    pub fn format(mut self, format: ScreencastFormat) -> Self {
48        self.format = Some(format);
49        self
50    }
51
52    /// Set the compression quality (0-100).
53    #[must_use]
54    pub fn quality(mut self, quality: i32) -> Self {
55        self.quality = Some(quality);
56        self
57    }
58
59    /// Set the maximum width.
60    #[must_use]
61    pub fn max_width(mut self, width: i32) -> Self {
62        self.max_width = Some(width);
63        self
64    }
65
66    /// Set the maximum height.
67    #[must_use]
68    pub fn max_height(mut self, height: i32) -> Self {
69        self.max_height = Some(height);
70        self
71    }
72
73    /// Set which frames to capture (every nth frame).
74    #[must_use]
75    pub fn every_nth_frame(mut self, n: i32) -> Self {
76        self.every_nth_frame = Some(n);
77        self
78    }
79}
80
81/// Parameters for Page.stopScreencast (empty).
82#[derive(Debug, Clone, Serialize, Default)]
83pub struct StopScreencastParams {}
84
85/// Parameters for Page.screencastFrameAck.
86#[derive(Debug, Clone, Serialize)]
87#[serde(rename_all = "camelCase")]
88pub struct ScreencastFrameAckParams {
89    /// Frame number to acknowledge.
90    pub session_id: i32,
91}
92
93/// Event: Page.screencastFrame
94///
95/// Compressed image data requested by startScreencast.
96#[derive(Debug, Clone, Deserialize)]
97#[serde(rename_all = "camelCase")]
98pub struct ScreencastFrameEvent {
99    /// Base64-encoded compressed image.
100    pub data: String,
101    /// Screencast frame metadata.
102    pub metadata: ScreencastFrameMetadata,
103    /// Frame number.
104    pub session_id: i32,
105}
106
107/// Screencast frame metadata.
108#[derive(Debug, Clone, Deserialize)]
109#[serde(rename_all = "camelCase")]
110pub struct ScreencastFrameMetadata {
111    /// Top offset in DIP.
112    pub offset_top: f64,
113    /// Page scale factor.
114    pub page_scale_factor: f64,
115    /// Device screen width in DIP.
116    pub device_width: f64,
117    /// Device screen height in DIP.
118    pub device_height: f64,
119    /// Position of horizontal scroll in CSS pixels.
120    pub scroll_offset_x: f64,
121    /// Position of vertical scroll in CSS pixels.
122    pub scroll_offset_y: f64,
123    /// Frame timestamp in seconds.
124    pub timestamp: Option<f64>,
125}
126
127/// Event: Page.screencastVisibilityChanged
128///
129/// Fired when the page becomes visible or hidden.
130#[derive(Debug, Clone, Deserialize)]
131pub struct ScreencastVisibilityChangedEvent {
132    /// True if the page is visible.
133    pub visible: bool,
134}