Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions .mise.toml
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,60 @@ description = "Build the comm1 workflow WASM module"
dir = "services/ws-modules/comm1"
run = "wasm-pack build . --target web"

[tasks.build-ws-sensor1-module]
description = "Build the sensor1 workflow WASM module"
dir = "services/ws-modules/sensor1"
run = "wasm-pack build . --target web"

[tasks.build-ws-audio1-module]
description = "Build the audio1 workflow WASM module"
dir = "services/ws-modules/audio1"
run = "wasm-pack build . --target web"

[tasks.build-ws-video1-module]
description = "Build the video1 workflow WASM module"
dir = "services/ws-modules/video1"
run = "wasm-pack build . --target web"

[tasks.build-ws-bluetooth-module]
description = "Build the bluetooth workflow WASM module"
dir = "services/ws-modules/bluetooth"
run = "wasm-pack build . --target web"

[tasks.build-ws-geolocation-module]
description = "Build the geolocation workflow WASM module"
dir = "services/ws-modules/geolocation"
run = "wasm-pack build . --target web"

[tasks.build-ws-graphics-info-module]
description = "Build the graphics info workflow WASM module"
dir = "services/ws-modules/graphics-info"
run = "wasm-pack build . --target web"

[tasks.build-ws-speech-recognition-module]
description = "Build the speech recognition workflow WASM module"
dir = "services/ws-modules/speech-recognition"
run = "wasm-pack build . --target web"

[tasks.build-ws-nfc-module]
description = "Build the nfc workflow WASM module"
dir = "services/ws-modules/nfc"
run = "wasm-pack build . --target web"

[tasks.build-wasm]
depends = [
"build-ws-audio1-module",
"build-ws-bluetooth-module",
"build-ws-comm1-module",
"build-ws-data1-module",
"build-ws-face-detection-module",
"build-ws-geolocation-module",
"build-ws-graphics-info-module",
"build-ws-har1-module",
"build-ws-nfc-module",
"build-ws-sensor1-module",
"build-ws-speech-recognition-module",
"build-ws-video1-module",
"build-ws-wasm-agent",
]
description = "Build all WebAssembly modules"
Expand Down
13 changes: 13 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"recommendations": [
"davidanson.vscode-markdownlint",
"editorconfig.editorconfig",
"fill-labs.dependi",
"github.vscode-github-actions",
"ms-azuretools.vscode-docker",
"rust-lang.rust-analyzer",
"streetsidesoftware.code-spell-checker",
"tamasfe.even-better-toml",
"yzhang.markdown-all-in-one"
]
}
10 changes: 10 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,27 @@ rust-version = "1.87.0"
[workspace]
members = [
"libs/edge-toolkit",
"libs/web",
"services/ws-modules/audio1",
"services/ws-modules/bluetooth",
"services/ws-modules/comm1",
"services/ws-modules/data1",
"services/ws-modules/face-detection",
"services/ws-modules/geolocation",
"services/ws-modules/graphics-info",
"services/ws-modules/har1",
"services/ws-modules/nfc",
"services/ws-modules/sensor1",
"services/ws-modules/speech-recognition",
"services/ws-modules/video1",
"services/ws-server",
"services/ws-wasm-agent",
]
resolver = "2"

[workspace.dependencies]
chrono = { version = "0.4", features = ["serde"] }
et-web = { path = "libs/web" }
serde = { version = "1", features = ["derive"] }
serde_json = "1"
tracing = "0.1"
Expand Down
23 changes: 23 additions & 0 deletions libs/web/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[package]
name = "et-web"
description = "Web helpers for WASM modules"
version = "0.1.0"
edition.workspace = true
license.workspace = true
repository.workspace = true

[lib]
crate-type = ["cdylib", "rlib"]

[dependencies]
js-sys = "0.3"
wasm-bindgen = "0.2"
wasm-bindgen-futures = "0.4"
web-sys = { version = "0.3", features = [
"MediaDevices",
"MediaStream",
"MediaStreamConstraints",
"MediaStreamTrack",
"MessageEvent",
"Navigator",
] }
40 changes: 40 additions & 0 deletions libs/web/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
use wasm_bindgen::prelude::*;

pub const SENSOR_PERMISSION_GRANTED: &str = "granted";

pub fn get_media_devices(navigator: &web_sys::Navigator) -> Result<web_sys::MediaDevices, JsValue> {
let media_devices = js_sys::Reflect::get(navigator, &JsValue::from_str("mediaDevices"))?;

if media_devices.is_undefined() || media_devices.is_null() {
return Err(JsValue::from_str(
"navigator.mediaDevices is unavailable. Use https://... or http://localhost and allow access.",
));
}

media_devices
.dyn_into::<web_sys::MediaDevices>()
.map_err(|_| JsValue::from_str("navigator.mediaDevices is not accessible in this browser"))
}

pub async fn request_sensor_permission(target: JsValue) -> Result<String, JsValue> {
if target.is_null() || target.is_undefined() {
return Ok(SENSOR_PERMISSION_GRANTED.to_string());
}

let request_permission = js_sys::Reflect::get(&target, &JsValue::from_str("requestPermission"))?;
if request_permission.is_null() || request_permission.is_undefined() {
return Ok(SENSOR_PERMISSION_GRANTED.to_string());
}

let request_permission = request_permission
.dyn_into::<js_sys::Function>()
.map_err(|_| JsValue::from_str("requestPermission is not callable"))?;
let promise = request_permission
.call0(&target)?
.dyn_into::<js_sys::Promise>()
.map_err(|_| JsValue::from_str("requestPermission did not return a Promise"))?;
let result = wasm_bindgen_futures::JsFuture::from(promise).await?;
Ok(result
.as_string()
.unwrap_or_else(|| SENSOR_PERMISSION_GRANTED.to_string()))
}
34 changes: 34 additions & 0 deletions services/ws-modules/audio1/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[package]
description = "audio capture module"
name = "et-ws-audio1"
version = "0.1.0"
edition.workspace = true
license.workspace = true
repository.workspace = true

[lib]
crate-type = ["cdylib", "rlib"]

[dependencies]
et-web.workspace = true
et-ws-wasm-agent = { path = "../../ws-wasm-agent" }
js-sys = "0.3"
serde.workspace = true
serde-wasm-bindgen = "0.6"
serde_json.workspace = true
tracing.workspace = true
tracing-wasm = "0.2"
wasm-bindgen = "0.2"
wasm-bindgen-futures = "0.4"
web-sys = { version = "0.3", features = [
"MediaDevices",
"MediaStream",
"MediaStreamConstraints",
"MediaStreamTrack",
"Navigator",
"Window",
"console",
] }

[dev-dependencies]
wasm-bindgen-test = "0.3"
Loading
Loading