use_display_media
Reactive mediaDevices.getDisplayMedia streaming.
Demo
Usage
use leptos::prelude::*;
use leptos::logging::{log, error};
use leptos_use_display_media::{use_display_media, UseDisplayMediaReturn};
#[component]
fn Demo() -> impl IntoView {
let video_ref = NodeRef::<leptos::html::Video>::new();
let UseDisplayMediaReturn { stream, start, .. } = use_display_media();
start();
Effect::new(move |_|
video_ref.get().map(|v| {
match stream.get() {
Some(Ok(s)) => v.set_src_object(Some(&s)),
Some(Err(e)) => error!("Failed to get media stream: {:?}", e),
None => log!("No stream yet"),
}
})
);
view! { <video node_ref=video_ref controls=false autoplay=true muted=true></video> }
}
SendWrapped Return
The returned closures start and stop are sendwrapped functions. They can
only be called from the same thread that called use_display_media.
Server-Side Rendering
Make sure you follow the instructions in Server-Side Rendering.
On the server calls to start or any other way to enable the stream will be ignored
and the stream will always be None.
Installation
cargo add leptos-use-display-media
Options
UseDisplayMediaOptions
Options for use_display_media.
Every option is set with a builder method of the same name, e.g. UseDisplayMediaOptions::default().enabled(...). See also the API docs.
enabled
Type: MaybeRwSignal<bool>
If the stream is enabled. Defaults to false.
audio
Type: bool
A value of true indicates that the returned MediaStream
will contain an audio track, if audio is supported and available for the display surface chosen by the user.
The default value is false.