use crate::error::Result;
use crate::protocol::page::Page;
use crate::server::channel_owner::ChannelOwner;
use std::path::PathBuf;
#[derive(Debug, Clone)]
pub struct ScreencastFrame {
pub data: bytes::Bytes,
}
#[derive(Debug, Default, Clone)]
pub struct ScreencastStartOptions {
pub size: Option<ScreencastSize>,
pub quality: Option<i32>,
pub path: Option<PathBuf>,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct ScreencastSize {
pub width: i32,
pub height: i32,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ActionPosition {
TopLeft,
Top,
TopRight,
BottomLeft,
Bottom,
BottomRight,
}
impl ActionPosition {
pub(crate) fn as_str(self) -> &'static str {
match self {
ActionPosition::TopLeft => "top-left",
ActionPosition::Top => "top",
ActionPosition::TopRight => "top-right",
ActionPosition::BottomLeft => "bottom-left",
ActionPosition::Bottom => "bottom",
ActionPosition::BottomRight => "bottom-right",
}
}
}
#[derive(Debug, Default, Clone)]
pub struct ShowActionsOptions {
pub duration: Option<f64>,
pub position: Option<ActionPosition>,
pub font_size: Option<i32>,
}
#[derive(Debug, Default, Clone)]
pub struct ChapterOptions {
pub description: Option<String>,
pub duration: Option<f64>,
}
#[derive(Debug, Default, Clone)]
pub struct ShowOverlayOptions {
pub duration: Option<f64>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct OverlayId(pub String);
#[derive(Clone)]
pub struct Screencast {
page: Page,
}
impl Screencast {
pub(crate) fn new(page: Page) -> Self {
Self { page }
}
#[tracing::instrument(level = "info", skip_all, fields(page_guid = %self.page.guid()))]
pub async fn start(&self, options: ScreencastStartOptions) -> Result<()> {
self.page.screencast_start(options).await
}
#[tracing::instrument(level = "info", skip_all, fields(page_guid = %self.page.guid()))]
pub async fn stop(&self) -> Result<()> {
self.page.screencast_stop().await
}
pub fn on_frame<F, Fut>(&self, handler: F)
where
F: Fn(ScreencastFrame) -> Fut + Send + Sync + 'static,
Fut: std::future::Future<Output = Result<()>> + Send + 'static,
{
self.page.screencast_on_frame(handler);
}
#[tracing::instrument(level = "debug", skip_all, fields(page_guid = %self.page.guid()))]
pub async fn show_actions(&self, options: ShowActionsOptions) -> Result<()> {
self.page.screencast_show_actions(options).await
}
#[tracing::instrument(level = "debug", skip_all, fields(page_guid = %self.page.guid()))]
pub async fn hide_actions(&self) -> Result<()> {
self.page.screencast_hide_actions().await
}
#[tracing::instrument(level = "debug", skip_all, fields(page_guid = %self.page.guid(), title = %title))]
pub async fn show_chapter(&self, title: &str, options: ChapterOptions) -> Result<()> {
self.page.screencast_chapter(title, options).await
}
#[tracing::instrument(level = "debug", skip_all, fields(page_guid = %self.page.guid()))]
pub async fn show_overlay(&self, html: &str, options: ShowOverlayOptions) -> Result<OverlayId> {
self.page.screencast_show_overlay(html, options).await
}
#[tracing::instrument(level = "debug", skip_all, fields(page_guid = %self.page.guid()))]
pub async fn remove_overlay(&self, id: OverlayId) -> Result<()> {
self.page.screencast_remove_overlay(id).await
}
#[tracing::instrument(level = "debug", skip_all, fields(page_guid = %self.page.guid(), visible))]
pub async fn set_overlay_visible(&self, visible: bool) -> Result<()> {
self.page.screencast_set_overlay_visible(visible).await
}
}