-
-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #130 from hcandelaria/user-media-api
- Loading branch information
Showing
16 changed files
with
692 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# use_user_media | ||
|
||
<!-- cmdrun python3 ../extract_doc_comment.py use_user_media --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
[package] | ||
name = "use_user_media" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
leptos = { version = "0.6", features = ["nightly", "csr"] } | ||
console_error_panic_hook = "0.1" | ||
console_log = "1" | ||
log = "0.4" | ||
leptos-use = { path = "../..", features = ["docs"] } | ||
web-sys = "0.3" | ||
|
||
[dev-dependencies] | ||
wasm-bindgen = "0.2" | ||
wasm-bindgen-test = "0.3.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
A simple example for `use_user_media`. | ||
|
||
If you don't have it installed already, install [Trunk](https://trunkrs.dev/) and [Tailwind](https://tailwindcss.com/docs/installation) | ||
as well as the nightly toolchain for Rust and the wasm32-unknown-unknown target: | ||
|
||
```bash | ||
cargo install trunk | ||
npm install -D tailwindcss @tailwindcss/forms | ||
rustup toolchain install nightly | ||
rustup target add wasm32-unknown-unknown | ||
``` | ||
|
||
Then, open two terminals. In the first one, run: | ||
|
||
``` | ||
npx tailwindcss -i ./input.css -o ./style/output.css --watch | ||
``` | ||
|
||
In the second one, run: | ||
|
||
```bash | ||
trunk serve --open | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[build] | ||
public_url = "/demo/" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<link data-trunk rel="css" href="style/output.css"> | ||
</head> | ||
<body></body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
@tailwind base; | ||
@tailwind components; | ||
@tailwind utilities; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[toolchain] | ||
channel = "nightly" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
use leptos::*; | ||
use leptos_use::docs::demo_or_body; | ||
use leptos_use::{use_user_media, UseUserMediaReturn}; | ||
|
||
#[component] | ||
fn Demo() -> impl IntoView { | ||
let video_ref = create_node_ref::<leptos::html::Video>(); | ||
|
||
let UseUserMediaReturn { | ||
stream, | ||
enabled, | ||
set_enabled, | ||
.. | ||
} = use_user_media(); | ||
|
||
create_effect(move |_| { | ||
match stream.get() { | ||
Some(Ok(s)) => { | ||
video_ref.get().map(|v| v.set_src_object(Some(&s))); | ||
return; | ||
} | ||
Some(Err(e)) => logging::error!("Failed to get media stream: {:?}", e), | ||
None => logging::log!("No stream yet"), | ||
} | ||
|
||
video_ref.get().map(|v| v.set_src_object(None)); | ||
}); | ||
|
||
view! { | ||
<div class="flex flex-col gap-4 text-center"> | ||
<div> | ||
<button on:click=move |_| set_enabled( | ||
!enabled(), | ||
)>{move || if enabled() { "Stop" } else { "Start" }} video</button> | ||
</div> | ||
|
||
<div> | ||
<video | ||
node_ref=video_ref | ||
controls=false | ||
autoplay=true | ||
muted=true | ||
class="h-96 w-auto" | ||
></video> | ||
</div> | ||
</div> | ||
} | ||
} | ||
|
||
fn main() { | ||
_ = console_log::init_with_level(log::Level::Debug); | ||
console_error_panic_hook::set_once(); | ||
|
||
mount_to(demo_or_body(), || { | ||
view! { <Demo/> } | ||
}) | ||
} |
Oops, something went wrong.