Skip to content

Commit

Permalink
feat(webcam): begin implementation of webcam audio recorder
Browse files Browse the repository at this point in the history
  • Loading branch information
HoKim98 committed Oct 2, 2024
1 parent ac1708f commit 03b6ad1
Show file tree
Hide file tree
Showing 16 changed files with 426 additions and 15 deletions.
8 changes: 5 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[workspace]
default-members = ["crates/cassette"]
members = ["crates/*"]
exclude = ["crates/target"]
resolver = "2"

[workspace.package]
Expand Down Expand Up @@ -63,9 +64,9 @@ include_dir = { version = "=0.7" }
inflector = { package = "Inflector", version = "=0.11" }
itertools = { version = "=0.13" }
js-sys = { version = "=0.3", default-features = false }
k8s-openapi = { version = "=0.23", features = ["latest", "schemars"] }
kube = { version = "=0.95", default-features = false }
kube-core = { version = "=0.95", default-features = false }
k8s-openapi = { version = "=0.22", features = ["latest", "schemars"] }
kube = { version = "=0.93", default-features = false }
kube-core = { version = "=0.93", default-features = false }
mime = { version = "=0.3", default-features = false }
once_cell = { version = "=1.20" }
patternfly-yew = { version = "=0.6", default-features = false, features = [
Expand Down Expand Up @@ -96,6 +97,7 @@ uuid = { version = "=1.10", default-features = false, features = [
"serde",
"v4",
] }
wasm-bindgen = { version = "=0.2" }
wasm-streams = { version = "=0.4" }
web-sys = { version = "=0.3", features = [
"FileList",
Expand Down
5 changes: 4 additions & 1 deletion Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ init:
@# Rust Deny
@which cargo-deny >/dev/null || cargo install cargo-deny

@# Rust Mobile
@which cargo-mobile >/dev/null || cargo install cargo-mobile2

@# Rust Trunk
@which trunk >/dev/null || cargo install trunk
@which wasm-bindgen >/dev/null || cargo install wasm-bindgen-cli
Expand All @@ -61,7 +64,7 @@ build *ARGS: ( _trunk "build" ARGS )

run *ARGS: ( _trunk "serve" ARGS )

run-examples *ARGS: ( _trunk "serve" "--features" "examples,full,mock-release" ARGS )
run-examples *ARGS: ( _trunk "serve" "--features" "examples,full" ARGS )

run-gateway *ARGS:
cargo watch -s 'clear && cargo run --package cassette-gateway -- {{ ARGS }}'
Expand Down
2 changes: 1 addition & 1 deletion Trunk.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ ignore = []

[serve]
# The address to serve on.
addresses = ["127.0.0.1"]
addresses = ["0.0.0.0"]
# The port to serve on.
port = 6080
# Open a browser tab once the initial build is complete.
Expand Down
2 changes: 2 additions & 0 deletions crates/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/cassette-standalone
/target
6 changes: 3 additions & 3 deletions crates/cassette-gateway/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,21 @@ workspace = true

[features]
default = ["default-tls", "full", "openark"]
full = ["cdl", "helm", "kubernetes"]
full = ["helm", "kubernetes"]
experimental = []
openark = ["vine"]

# TLS
default-tls = ["rustls-tls"]
openssl-tls = [
"actix-web/openssl",
"cassette-plugin-cdl-api/openssl-tls",
"cassette-plugin-cdl-api?/openssl-tls",
"kube/openssl-tls",
"reqwest?/native-tls",
]
rustls-tls = [
"actix-web/rustls",
"cassette-plugin-cdl-api/rustls-tls",
"cassette-plugin-cdl-api?/rustls-tls",
"kube/rustls-tls",
"reqwest?/rustls-tls",
]
Expand Down
2 changes: 1 addition & 1 deletion crates/cassette-gateway/src/agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,6 @@ pub struct AgentArgs {

impl AgentArgs {
const fn default_bind_addr() -> SocketAddr {
SocketAddr::V4(SocketAddrV4::new(Ipv4Addr::new(127, 0, 0, 1), 8080))
SocketAddr::V4(SocketAddrV4::new(Ipv4Addr::new(0, 0, 0, 0), 8080))
}
}
29 changes: 29 additions & 0 deletions crates/cassette-plugin-webcam-audio/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
[package]
name = "cassette-plugin-webcam-audio"

authors = { workspace = true }
description = { workspace = true }
documentation = "https://docs.rs/cassette-plugin-webcam-audio"
edition = { workspace = true }
include = { workspace = true }
keywords = { workspace = true }
license = { workspace = true }
readme = { workspace = true }
rust-version = { workspace = true }
homepage = { workspace = true }
repository = { workspace = true }
version = { workspace = true }

[lints]
workspace = true

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
cassette-core = { path = "../cassette-core", features = ["ui"] }
cassette-plugin-webcam-core = { path = "../cassette-plugin-webcam-core", features = [
"ui",
] }

serde = { workspace = true, features = ["derive"] }
yew = { workspace = true }
44 changes: 44 additions & 0 deletions crates/cassette-plugin-webcam-audio/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
use cassette_core::{
cassette::{CassetteContext, GenericCassetteTaskHandle},
components::ComponentRenderer,
prelude::*,
task::{TaskResult, TaskState},
};
use cassette_plugin_webcam_core::{hooks::use_webcam, Constraints, Handler};
use serde::{Deserialize, Serialize};
use yew::prelude::*;

#[derive(Clone, Debug, PartialEq, Deserialize, Properties)]
#[serde(rename_all = "camelCase")]
pub struct Spec {
#[serde(flatten)]
handler: Handler,
}

#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct State {}

impl ComponentRenderer<Spec> for State {
fn render(self, ctx: &mut CassetteContext, spec: Spec) -> TaskResult<Option<Self>> {
let Spec { handler } = spec;

let constraints = Constraints {
audio: true,
video: false,
};
let webcam = match use_webcam(ctx, &handler, &constraints).get() {
Ok(webcam) => webcam,
Err(msg) => {
return Ok(TaskState::Break {
body: html! { <Error msg={ msg.clone() } /> },
state: None,
})
}
};

Ok(TaskState::Skip {
state: Some(Self {}),
})
}
}
57 changes: 57 additions & 0 deletions crates/cassette-plugin-webcam-core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
[package]
name = "cassette-plugin-webcam-core"

authors = { workspace = true }
description = { workspace = true }
documentation = "https://docs.rs/cassette-plugin-webcam-core"
edition = { workspace = true }
include = { workspace = true }
keywords = { workspace = true }
license = { workspace = true }
readme = { workspace = true }
rust-version = { workspace = true }
homepage = { workspace = true }
repository = { workspace = true }
version = { workspace = true }

[lints]
workspace = true

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[features]
default = []
ui = [
"cassette-core/ui",
"dep:anyhow",
"dep:js-sys",
"dep:wasm-bindgen",
"dep:web-sys",
"dep:yew",
]

[dependencies]
cassette-core = { path = "../cassette-core" }

anyhow = { workspace = true, optional = true }
js-sys = { workspace = true, optional = true }
serde = { workspace = true }
wasm-bindgen = { workspace = true, optional = true }
web-sys = { workspace = true, optional = true, features = [
"MediaStream",
"MediaRecorder",
"MediaDevices",
"MediaStreamConstraints",
"MediaTrackConstraints",
"HtmlElement",
"Window",
"console",
"Url",
"Blob",
"BlobEvent",
"EventTarget",
"HtmlAnchorElement",
"Document",
"Navigator",
] }
yew = { workspace = true, optional = true }
Loading

0 comments on commit 03b6ad1

Please sign in to comment.