Skip to main content

ferridriver_script/bindings/
video.rs

1//! `VideoJs` — QuickJS binding for [`ferridriver::Video`].
2//!
3//! Mirrors Playwright's client-side `Video` class from
4//! `/tmp/playwright/packages/playwright-core/src/client/video.ts` and
5//! the public-type contract in
6//! `/tmp/playwright/packages/playwright-core/types/types.d.ts:21621`:
7//! sync construction, async `path()` / `saveAs()` / `delete()` that
8//! block until the owning page closes and the encoder finalises.
9
10use std::sync::Arc;
11
12use crate::bindings::convert::FerriResultExt;
13use ferridriver::Video as CoreVideo;
14use rquickjs::JsLifetime;
15use rquickjs::class::Trace;
16
17#[derive(JsLifetime, Trace)]
18#[rquickjs::class(rename = "Video")]
19pub struct VideoJs {
20  #[qjs(skip_trace)]
21  inner: Arc<CoreVideo>,
22}
23
24impl VideoJs {
25  #[must_use]
26  pub fn new(inner: Arc<CoreVideo>) -> Self {
27    Self { inner }
28  }
29}
30
31#[rquickjs::methods]
32impl VideoJs {
33  /// Playwright: `video.path(): Promise<string>`.
34  #[qjs(rename = "path")]
35  pub async fn path(&self) -> rquickjs::Result<String> {
36    let path = self.inner.path().await.into_js()?;
37    Ok(path.to_string_lossy().into_owned())
38  }
39
40  /// Playwright: `video.saveAs(path: string): Promise<void>`.
41  #[qjs(rename = "saveAs")]
42  pub async fn save_as(&self, path: String) -> rquickjs::Result<()> {
43    self.inner.save_as(path).await.into_js()
44  }
45
46  /// Playwright: `video.delete(): Promise<void>`.
47  #[qjs(rename = "delete")]
48  pub async fn delete(&self) -> rquickjs::Result<()> {
49    self.inner.delete().await.into_js()
50  }
51}