Function leptos_use::use_user_media

source ·
pub fn use_user_media() -> UseUserMediaReturn<impl Fn() + Clone, impl Fn() + Clone>
Expand description

Reactive mediaDevices.getUserMedia streaming.

§Demo

Link to Demo

§Usage

let video_ref = create_node_ref::<leptos::html::Video>();

let UseUserMediaReturn { stream, start, .. } = use_user_media();

start();

create_effect(move |_|
    video_ref.get().map(|v| {
        match stream.get() {
            Some(Ok(s)) => v.set_src_object(Some(&s)),
            Some(Err(e)) => logging::error!("Failed to get media stream: {:?}", e),
            None => logging::log!("No stream yet"),
        }
    })
);

view! { <video node_ref=video_ref controls=false autoplay=true muted=true></video> }

§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.