-
Notifications
You must be signed in to change notification settings - Fork 155
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
acc49be
commit 1942206
Showing
10 changed files
with
192 additions
and
5 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,4 +9,3 @@ crate-type = ["cdylib"] | |
|
||
[dependencies] | ||
seed = {path = "../../"} | ||
wasm-bindgen-futures = "0.4.18" |
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,20 @@ | ||
[package] | ||
name = "record_screen" | ||
version = "0.1.0" | ||
authors = ["Martin Kavík <martin@kavik.cz>"] | ||
edition = "2018" | ||
|
||
[lib] | ||
crate-type = ["cdylib"] | ||
|
||
[dependencies] | ||
seed = {path = "../../"} | ||
|
||
[dependencies.web-sys] | ||
version = "0.3.45" | ||
features = [ | ||
"DisplayMediaStreamConstraints", | ||
"MediaDevices", | ||
"MediaStream", | ||
"HtmlMediaElement", | ||
] |
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,27 @@ | ||
extend = "../../Makefile.toml" | ||
|
||
# ---- BUILD ---- | ||
|
||
[tasks.build] | ||
alias = "default_build" | ||
|
||
[tasks.build_release] | ||
alias = "default_build_release" | ||
|
||
# ---- START ---- | ||
|
||
[tasks.start] | ||
alias = "default_start" | ||
|
||
[tasks.start_release] | ||
alias = "default_start_release" | ||
|
||
# ---- TEST ---- | ||
|
||
[tasks.test_firefox] | ||
alias = "default_test_firefox" | ||
|
||
# ---- LINT ---- | ||
|
||
[tasks.clippy] | ||
alias = "default_clippy" |
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,11 @@ | ||
## Record Screen example | ||
|
||
How to record the screen using the [Screen Capture API](https://developer.mozilla.org/en-US/docs/Web/API/Screen_Capture_API/Using_Screen_Capture). | ||
|
||
--- | ||
|
||
```bash | ||
cargo make start | ||
``` | ||
|
||
Open [127.0.0.1:8000](http://127.0.0.1:8000) in your browser. |
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,18 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
|
||
<head> | ||
<meta charset="utf-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" /> | ||
<title>Record Screen example</title> | ||
</head> | ||
|
||
<body> | ||
<section id="app"></section> | ||
<script type="module"> | ||
import init from '/pkg/package.js'; | ||
init('/pkg/package_bg.wasm'); | ||
</script> | ||
</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,97 @@ | ||
use seed::{prelude::*, *}; | ||
use wasm_bindgen_futures::JsFuture; | ||
use web_sys::{DisplayMediaStreamConstraints, HtmlMediaElement, MediaStream}; | ||
|
||
// ------ ------ | ||
// Init | ||
// ------ ------ | ||
|
||
fn init(_: Url, _: &mut impl Orders<Msg>) -> Model { | ||
Model::default() | ||
} | ||
|
||
// ------ ------ | ||
// Model | ||
// ------ ------ | ||
|
||
#[derive(Default)] | ||
struct Model { | ||
video: ElRef<HtmlMediaElement>, | ||
} | ||
|
||
// ------ ------ | ||
// Update | ||
// ------ ------ | ||
|
||
enum Msg { | ||
RecordScreen, | ||
DisplayMedia(Result<MediaStream, JsValue>), | ||
} | ||
|
||
fn update(msg: Msg, model: &mut Model, orders: &mut impl Orders<Msg>) { | ||
match msg { | ||
Msg::RecordScreen => { | ||
orders.perform_cmd(display_media()); | ||
} | ||
Msg::DisplayMedia(Ok(media_stream)) => { | ||
model | ||
.video | ||
.get() | ||
.expect("get video element") | ||
.set_src_object(Some(&media_stream)); | ||
} | ||
Msg::DisplayMedia(Err(error)) => { | ||
log!(error); | ||
} | ||
} | ||
} | ||
|
||
async fn display_media() -> Msg { | ||
let mut constraints = DisplayMediaStreamConstraints::new(); | ||
constraints.video(&JsValue::from(true)); | ||
|
||
let media_stream_promise = window() | ||
.navigator() | ||
.media_devices() | ||
.unwrap() | ||
.get_display_media_with_constraints(&constraints) | ||
.unwrap(); | ||
|
||
Msg::DisplayMedia( | ||
JsFuture::from(media_stream_promise) | ||
.await | ||
.map(MediaStream::from), | ||
) | ||
} | ||
|
||
// ------ ------ | ||
// View | ||
// ------ ------ | ||
|
||
fn view(model: &Model) -> Node<Msg> { | ||
div![ | ||
button![ | ||
style! { | ||
St::Display => "block", | ||
}, | ||
"Record Screen", | ||
ev(Ev::Click, |_| Msg::RecordScreen) | ||
], | ||
video![ | ||
el_ref(&model.video), | ||
attrs! { | ||
At::Width => 1024, | ||
At::AutoPlay => AtValue::None, | ||
} | ||
] | ||
] | ||
} | ||
|
||
// ------ ------ | ||
// Start | ||
// ------ ------ | ||
|
||
#[wasm_bindgen(start)] | ||
pub fn start() { | ||
App::start("app", init, update, view); | ||
} |
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 |
---|---|---|
|
@@ -9,5 +9,4 @@ crate-type = ["cdylib"] | |
|
||
[dependencies] | ||
seed = {path = "../../"} | ||
wasm-bindgen-futures = "0.4.18" | ||
enclose = "1.1.8" |