use crate::cdp::types::*;
use super::*;
#[derive(Debug, Clone, Default, PartialEq)]
pub struct NativeRecordingOptions {
pub max_width: Option<u32>,
pub max_height: Option<u32>,
pub fps: Option<f64>,
}
impl NativeRecordingOptions {
pub(super) fn params(&self) -> Result<PageStartScreenRecording, RecordingError> {
if [self.max_width, self.max_height]
.into_iter()
.flatten()
.any(|value| value == 0 || value > i32::MAX as u32)
{
return Err(RecordingError::InvalidOptions(
"max_width and max_height must be positive CDP integers".into(),
));
}
if self.fps.is_some_and(|fps| {
!fps.is_finite() || !(1.0..=120.0).contains(&fps) || fps.fract() != 0.0
}) {
return Err(RecordingError::InvalidOptions(
"fps must be an integer in 1..=120 (native frameRate is an integer)".into(),
));
}
#[allow(
clippy::cast_possible_truncation,
clippy::cast_sign_loss,
reason = "fps was validated above as an integral value in 1..=120"
)]
Ok(PageStartScreenRecording {
audio: false,
max_width: self.max_width,
max_height: self.max_height,
frame_rate: self.fps.map(|fps| fps as u32),
})
}
}
#[derive(Debug, PartialEq, Eq)]
pub struct RecordingChunk {
pub data: Vec<u8>,
pub eof: bool,
}