Initial commit with a sorta working demo
This commit is contained in:
commit
1428cc3289
|
@ -0,0 +1,2 @@
|
|||
/target
|
||||
*.sw*
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,18 @@
|
|||
[package]
|
||||
name = "charcuterie"
|
||||
version = "0.1.0"
|
||||
authors = ["R. Tyler Croy <rtyler@brokenco.de>"]
|
||||
edition = "2018"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
async-std = { version = "~1.6.1", features = ["attributes"] }
|
||||
glob = "~0.3.0"
|
||||
handlebars = { version = "~3.4.0", features = ["dir_source"] }
|
||||
log = "~0.4.11"
|
||||
pretty_env_logger = "~0.3.1"
|
||||
rodio = "~0.11.0"
|
||||
serde = { version = "~1.0.104", features = ["derive"] }
|
||||
serde_json = "~1.0.0"
|
||||
tide = "~0.13.0"
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,60 @@
|
|||
#[macro_use]
|
||||
extern crate serde_json;
|
||||
|
||||
use async_std::task;
|
||||
use glob::glob;
|
||||
use handlebars::Handlebars;
|
||||
use log::*;
|
||||
use rodio::Source;
|
||||
use tide::{Body, Request, StatusCode};
|
||||
|
||||
use std::fs::File;
|
||||
use std::io::BufReader;
|
||||
|
||||
|
||||
async fn index(req: Request<()>) -> Result<Body, tide::Error> {
|
||||
let mut hb = Handlebars::new();
|
||||
hb.register_templates_directory(".hbs", "views")
|
||||
.expect("Failed to register templates");
|
||||
|
||||
let mut sounds = vec![];
|
||||
|
||||
for sound in glob("sounds/*.wav").expect("Failed to glob sounds") {
|
||||
if let Ok(sound) = sound {
|
||||
if let Some(name) = sound.as_path().file_stem() {
|
||||
sounds.push(name.to_os_string().into_string().unwrap());
|
||||
}
|
||||
}
|
||||
}
|
||||
info!("sounds: {:?}", sounds);
|
||||
|
||||
let view = hb.render("index", &json!({"sounds": sounds}))
|
||||
.expect("Failed to render");
|
||||
let mut body = Body::from_string(view);
|
||||
body.set_mime("text/html");
|
||||
Ok(body)
|
||||
}
|
||||
|
||||
async fn play(req: Request<()>) -> tide::Result {
|
||||
if let Ok(sound) = req.param::<String>("sound") {
|
||||
let device = rodio::default_output_device().unwrap();
|
||||
let file = File::open(format!("sounds/{}.wav", sound)).unwrap();
|
||||
let source = rodio::Decoder::new(BufReader::new(file)).unwrap();
|
||||
rodio::play_raw(&device, source.convert_samples());
|
||||
Ok(tide::Redirect::new("/").into())
|
||||
}
|
||||
else {
|
||||
Err(tide::Error::from_str(StatusCode::NotFound, "Could not find sound"))
|
||||
}
|
||||
}
|
||||
|
||||
#[async_std::main]
|
||||
async fn main() -> Result<(), tide::Error> {
|
||||
pretty_env_logger::init();
|
||||
|
||||
let mut app = tide::new();
|
||||
app.at("/play/:sound").post(play);
|
||||
app.at("/").get(index);
|
||||
|
||||
Ok(app.listen("0.0.0.0:9077").await?)
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
<html>
|
||||
<head>
|
||||
<title>Charcuterie</title>
|
||||
</head>
|
||||
<body>
|
||||
A sound board for Meet, get it?
|
||||
|
||||
{{#each sounds}}
|
||||
<form action="/play/{{this}}" method="POST">
|
||||
<input type="submit" value="{{this}}"/>
|
||||
</form>
|
||||
{{/each}}
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
||||
|
||||
<!--
|
||||
vim: ft=html
|
||||
-->
|
Loading…
Reference in New Issue