Skip to content

Commit

Permalink
UI finally connected
Browse files Browse the repository at this point in the history
  • Loading branch information
naps62 committed Aug 3, 2020
1 parent b3065e1 commit d5fd93c
Show file tree
Hide file tree
Showing 18 changed files with 172 additions and 488 deletions.
2 changes: 2 additions & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
daemon: cd daemon && cargo run --color always -- -i /dev/video0 -o /dev/video2 -w 800 -h 600 -f 30 -b 4 -p
ui: cd ui && npm start
27 changes: 14 additions & 13 deletions daemon/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,28 @@ pub fn create(app: App) -> thread::JoinHandle<()> {
})
}

fn make_cors() -> Cors {
CorsOptions {
allowed_origins: AllowedOrigins::some_exact(&["http://localhost:3000"]),
allowed_methods: vec![Method::Get, Method::Post]
.into_iter()
.map(From::from)
.collect(),
..Default::default()
}
.to_cors()
.unwrap()
}

#[get("/settings")]
fn get_settings(state: State<App>) -> String {
state.lock().unwrap().get_settings()
}

#[post("/settings", data = "<settings>")]
fn set_setting(settings: String, state: State<App>) -> status::Accepted<String> {
println!("{:?}", settings);
state.lock().unwrap().set_settings(settings);

status::Accepted(None)
}

fn make_cors() -> Cors {
CorsOptions {
allowed_origins: AllowedOrigins::some_exact(&["http://localhost:3000"]),
allowed_methods: vec![Method::Options, Method::Get, Method::Post]
.into_iter()
.map(From::from)
.collect(),
..Default::default()
}
.to_cors()
.unwrap()
}
59 changes: 59 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "instacam",
"version": "1.0.0",
"description": "# Setup",
"main": "index.js",
"scripts": {
"start": "nf start"
},
"repository": {
"type": "git",
"url": "git+https://github.com/naps62/instacam.git"
},
"author": "Miguel Palhas",
"license": "ISC",
"bugs": {
"url": "https://github.com/naps62/instacam/issues"
},
"homepage": "https://github.com/naps62/instacam#readme",
"dependencies": {
"foreman": "^3.0.1"
}
}
31 changes: 31 additions & 0 deletions ui/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"@types/node": "^12.12.53",
"@types/react": "^16.9.44",
"@types/react-dom": "^16.9.8",
"axios": "^0.19.2",
"instacam-wasm": "file:../wasm/pkg",
"react": "^16.13.1",
"react-dom": "^16.13.1",
Expand Down
71 changes: 43 additions & 28 deletions ui/src/components/settings/index.tsx
Original file line number Diff line number Diff line change
@@ -1,43 +1,58 @@
import React, { useState, useEffect } from "react";
import axios from "axios";
import "./style.css";

const fetchSettings = async (callback: Function) => {
try {
const { data } = await axios("http:///localhost:8000/settings");

callback(data);
} catch (err) {
console.error(err);
}
};

const updateSettings = async (settings: String) => {
try {
await axios({
method: "post",
url: "http://localhost:8000/settings",
data: settings,
});
} catch (err) {
console.error(err);
}
};

const Settings: React.FC = () => {
const [wasm, setWasm] = useState();
const [settings, setSettings] = useState("");

useEffect(() => {
(async () => {
const wasm = await import("instacam-wasm");
setWasm(wasm);
})();
});

useEffect(() => {
if (!wasm) return;

console.log(wasm.get_settings());
}, [wasm]);
fetchSettings((settings: JSON) => setSettings(JSON.stringify(settings)));
}, []);

const onSubmit = (e: any) => {
e.preventDefault();
wasm.set_settings(settings);

try {
const json = JSON.parse(settings);
updateSettings(json);
} catch (err) {
console.error(err);
}
};

if (!wasm) {
return <div>Loading</div>;
} else {
return (
<form onSubmit={onSubmit}>
<textarea
rows={20}
className="Settings"
defaultValue={settings}
onChange={(e) => setSettings(e.target.value)}
/>
<input type="submit" value="Save" />
</form>
);
}
return (
<form onSubmit={onSubmit}>
<textarea
rows={20}
className="Settings"
defaultValue={settings}
onChange={(e) => setSettings(e.target.value)}
/>
<input type="submit" value="Save" />
</form>
);
};

export default Settings;
2 changes: 0 additions & 2 deletions ui/src/components/video/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ const Video: React.FC = () => {
navigator.mediaDevices.enumerateDevices().then(handleDevices);
}, [handleDevices]);

console.log(deviceId);

let webcam = null;
if (deviceId !== null && deviceId !== "") {
webcam = (
Expand Down
11 changes: 0 additions & 11 deletions wasm/.appveyor.yml

This file was deleted.

Empty file removed wasm/.cargo-ok
Empty file.
6 changes: 0 additions & 6 deletions wasm/.gitignore

This file was deleted.

69 changes: 0 additions & 69 deletions wasm/.travis.yml

This file was deleted.

35 changes: 0 additions & 35 deletions wasm/Cargo.toml

This file was deleted.

Loading

0 comments on commit d5fd93c

Please sign in to comment.