diff --git a/examples/Cargo.toml b/examples/Cargo.toml index 462659c..d9f03b9 100644 --- a/examples/Cargo.toml +++ b/examples/Cargo.toml @@ -14,7 +14,6 @@ members = [ "use_cycle_list", "use_debounce_fn", "use_display_media", - "use_display_media", "use_document_visibility", "use_draggable", "use_drop_zone", diff --git a/src/use_display_media.rs b/src/use_display_media.rs index 4d46744..848d2f7 100644 --- a/src/use_display_media.rs +++ b/src/use_display_media.rs @@ -3,23 +3,8 @@ use wasm_bindgen::{JsValue, JsCast}; use web_sys::{DisplayMediaStreamConstraints, MediaStream}; use crate::use_window::use_window; -async fn create_media(opts: Option) -> Result { - let media = use_window() - .navigator() - .ok_or_else(|| JsValue::from_str("Failed to access window.navigator")) - .and_then(|n| n.media_devices())?; - let promise = match opts { - Some(o) => media.get_display_media_with_constraints(&o), - None => media.get_display_media(), - }?; - let res = wasm_bindgen_futures::JsFuture::from(promise).await?; - Ok::<_, JsValue>(MediaStream::unchecked_from_js(res)) -} - -type UseDisplayReturn = Resource, Result>; - -/// +/// Get a media stream from the user's display. /// /// ## Demo /// @@ -46,3 +31,22 @@ where create_local_resource(move || opts.with(|o| o.as_ref().cloned()), create_media) } +async fn create_media(opts: Option) -> Result { + let media = use_window() + .navigator() + .ok_or_else(|| JsValue::from_str("Failed to access window.navigator")) + .and_then(|n| n.media_devices())?; + + let promise = match opts { + Some(o) => media.get_display_media_with_constraints(&o), + None => media.get_display_media(), + }?; + let res = wasm_bindgen_futures::JsFuture::from(promise).await?; + Ok::<_, JsValue>(MediaStream::unchecked_from_js(res)) +} + + +/// A leptos resource which optionally accepts a [DisplayMediaParamContraints](https://rustwasm.github.io/wasm-bindgen/api/web_sys/struct.DisplayMediaStreamConstraints.html) +/// The resource contains a result containing the media stream or the rejected JsValue +type UseDisplayReturn = Resource, Result>; +