Load status from relative url (#5)
Build Mumble Web 2 / linux_build (push) Successful in 2m23s
Build Mumble Web 2 / windows_build (push) Successful in 2m33s

Remove public_url config option
Use proxy_url instead for example configs
Get status from relative endpoint, like /config
Show version on login page

Reviewed-on: #5
Co-authored-by: Sam Sartor <me@samsartor.com>
Co-committed-by: Sam Sartor <me@samsartor.com>
This commit was merged in pull request #5.
This commit is contained in:
2025-12-05 07:00:38 +00:00
committed by Sam Sartor
parent 5df7b0e082
commit d6b482528f
9 changed files with 119 additions and 61 deletions
-1
View File
@@ -3,7 +3,6 @@ use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Deserialize, Serialize, Default)] #[derive(Debug, Clone, Deserialize, Serialize, Default)]
pub struct ClientConfig { pub struct ClientConfig {
pub proxy_url: Option<String>, pub proxy_url: Option<String>,
pub status_url: Option<String>,
pub cert_hash: Option<Vec<u8>>, pub cert_hash: Option<Vec<u8>>,
pub any_server: bool, pub any_server: bool,
} }
+1 -1
View File
@@ -1,4 +1,4 @@
public_url = "https://127.0.0.1:4433" proxy_url = "https://127.0.0.1:4433/proxy"
https_listen_address = "127.0.0.1:4433" https_listen_address = "127.0.0.1:4433"
http_listen_address = "127.0.0.1:8080" http_listen_address = "127.0.0.1:8080"
mumble_server_url = "[SERVER_URL_HERE]" mumble_server_url = "[SERVER_URL_HERE]"
-1
View File
@@ -1,4 +1,3 @@
public_url = "https://localhost:64444"
proxy_url = "https://127.0.0.1:4433/proxy" proxy_url = "https://127.0.0.1:4433/proxy"
https_listen_address = "127.0.0.1:4433" https_listen_address = "127.0.0.1:4433"
http_listen_address = "127.0.0.1:4400" http_listen_address = "127.0.0.1:4400"
+5
View File
@@ -279,6 +279,11 @@ a:visited {
color: #b3c6b4; color: #b3c6b4;
} }
&_version {
color: var(--txt-color);
font-weight: normal;
}
&_bttn { &_bttn {
font-weight: bold; font-weight: bold;
font-size: large; font-size: large;
+55 -7
View File
@@ -1,7 +1,39 @@
use std::env;
use std::path::Path; use std::path::Path;
use std::process::Command; use std::process::Command;
fn main() { fn version_env() -> Option<()> {
if env::var("MUMBLE_WEB2_VERSION").is_ok() {
return Some(());
}
let output = Command::new("git")
.args(["rev-parse", "--short", "HEAD"])
.output()
.ok()?;
let git_hash = String::from_utf8(output.stdout).ok()?;
let git_hash = git_hash.trim(); // drop trailing newline
let status = Command::new("git")
.args(["status", "--porcelain"])
.output()
.ok()?;
let dirty = match status.stdout.is_empty() {
true => "",
false => "-dirty",
};
// Expose it as a compile-time env var
println!("cargo::rustc-env=MUMBLE_WEB2_VERSION=git-{git_hash}{dirty}");
// Optional: rebuild when HEAD changes
println!("cargo::rerun-if-changed=.git/HEAD");
Some(())
}
fn download_deepfilternet() {
// Define the target directory and file // Define the target directory and file
let assets_dir = "assets"; let assets_dir = "assets";
let target_file = format!("{}/DeepFilterNet3_ll_onnx.tar.gz", assets_dir); let target_file = format!("{}/DeepFilterNet3_ll_onnx.tar.gz", assets_dir);
@@ -9,11 +41,17 @@ fn main() {
// Check if the file already exists // Check if the file already exists
if target_path.exists() { if target_path.exists() {
println!("cargo:warning=DeepFilterNet model already exists at {}", target_file); println!(
"cargo::warning=DeepFilterNet model already exists at {}",
target_file
);
return; return;
} }
println!("cargo:warning=Downloading DeepFilterNet model to {}...", target_file); println!(
"cargo::warning=Downloading DeepFilterNet model to {}...",
target_file
);
// Download the file using curl // Download the file using curl
let url = "https://github.com/Rikorose/DeepFilterNet/raw/refs/heads/main/models/DeepFilterNet3_ll_onnx.tar.gz"; let url = "https://github.com/Rikorose/DeepFilterNet/raw/refs/heads/main/models/DeepFilterNet3_ll_onnx.tar.gz";
@@ -21,18 +59,28 @@ fn main() {
let status = Command::new("curl") let status = Command::new("curl")
.args([ .args([
"-L", // Follow redirects "-L", // Follow redirects
"-o", &target_file, // Output file "-o",
&target_file, // Output file
url, url,
]) ])
.status() .status()
.expect("Failed to execute curl command. Make sure curl is installed."); .expect("Failed to execute curl command. Make sure curl is installed.");
if !status.success() { if !status.success() {
panic!("Failed to download DeepFilterNet model from {}", url); println!("cargo::error=Failed to download DeepFilterNet model from {url}");
return;
} }
println!("cargo:warning=Successfully downloaded DeepFilterNet model to {}", target_file); println!(
"cargo::warning=Successfully downloaded DeepFilterNet model to {}",
target_file
);
// Rerun this build script if the target file is deleted // Rerun this build script if the target file is deleted
println!("cargo:rerun-if-changed={}", target_file); println!("cargo::rerun-if-changed={}", target_file);
}
fn main() {
version_env();
download_deepfilternet();
} }
+6 -19
View File
@@ -545,33 +545,15 @@ pub fn ServerView(config: Resource<ClientConfig>) -> Element {
) )
} }
async fn get_status(
client: &reqwest::Client,
status_url: &str,
) -> color_eyre::Result<ServerStatus> {
Ok(client
.get(status_url)
.send()
.await?
.json::<ServerStatus>()
.await?)
}
#[component] #[component]
pub fn LoginView(config: Resource<ClientConfig>) -> Element { pub fn LoginView(config: Resource<ClientConfig>) -> Element {
let net: Coroutine<Command> = use_coroutine_handle(); let net: Coroutine<Command> = use_coroutine_handle();
let last_status = use_signal(|| None::<color_eyre::Result<ServerStatus>>); let last_status = use_signal(|| None::<color_eyre::Result<ServerStatus>>);
use_resource(move || async move { use_resource(move || async move {
let Some(config) = config.read().clone() else {
return;
};
let Some(status_url) = config.status_url else {
return;
};
let client = reqwest::Client::new(); let client = reqwest::Client::new();
loop { loop {
*last_status.write_unchecked() = Some(get_status(&client, &status_url).await); *last_status.write_unchecked() = Some(imp::get_status(&client).await);
imp::sleep(std::time::Duration::from_secs_f32(1.0)).await; imp::sleep(std::time::Duration::from_secs_f32(1.0)).await;
} }
}); });
@@ -630,11 +612,16 @@ pub fn LoginView(config: Resource<ClientConfig>) -> Element {
), ),
Connected => unreachable!(), Connected => unreachable!(),
}; };
let version = option_env!("MUMBLE_WEB2_VERSION");
rsx!( rsx!(
div { div {
class: "login", class: "login",
h1 { h1 {
"Mumble Web" "Mumble Web"
match version {
Some(v) => rsx!(" " span { class: "login_version", "({v})" }),
None => rsx!(),
}
} }
if config.read().as_ref().is_some_and(|cfg| cfg.any_server) { if config.read().as_ref().is_some_and(|cfg| cfg.any_server) {
div { div {
+35 -18
View File
@@ -1,11 +1,11 @@
use crate::app::Command; use crate::app::Command;
use crate::effects::{AudioProcessor, AudioProcessorSender}; use crate::effects::{AudioProcessor, AudioProcessorSender};
use color_eyre::eyre::{eyre, Context, Error}; use color_eyre::eyre::{bail, eyre, Context, Error};
use cpal::traits::{DeviceTrait, HostTrait, StreamTrait as _}; use cpal::traits::{DeviceTrait, HostTrait, StreamTrait as _};
use dioxus::hooks::UnboundedReceiver; use dioxus::hooks::UnboundedReceiver;
use futures::io::{AsyncRead, AsyncWrite}; use futures::io::{AsyncRead, AsyncWrite};
use mumble_protocol::control::ClientControlCodec; use mumble_protocol::control::ClientControlCodec;
use mumble_web2_common::ClientConfig; use mumble_web2_common::{ClientConfig, ServerStatus};
use std::mem::replace; use std::mem::replace;
use std::net::ToSocketAddrs; use std::net::ToSocketAddrs;
use std::sync::Arc; use std::sync::Arc;
@@ -64,26 +64,34 @@ impl AudioSystem {
self.processors.store(Some(processor)) self.processors.store(Some(processor))
} }
fn choose_config(&self, configs: impl Iterator<Item=cpal::SupportedStreamConfigRange>) -> Result<cpal::StreamConfig, Error> { fn choose_config(
&self,
configs: impl Iterator<Item = cpal::SupportedStreamConfigRange>,
) -> Result<cpal::StreamConfig, Error> {
let mut supported_configs: Vec<_> = configs let mut supported_configs: Vec<_> = configs
.filter_map(|cfg| cfg.try_with_sample_rate(cpal::SampleRate(SAMPLE_RATE))) .filter_map(|cfg| cfg.try_with_sample_rate(cpal::SampleRate(SAMPLE_RATE)))
.filter(|cfg| cfg.sample_format() == cpal::SampleFormat::I16) .filter(|cfg| cfg.sample_format() == cpal::SampleFormat::I16)
.map(|cfg| { .map(|cfg| cpal::StreamConfig {
cpal::StreamConfig {
buffer_size: cpal::BufferSize::Fixed(match *cfg.buffer_size() { buffer_size: cpal::BufferSize::Fixed(match *cfg.buffer_size() {
cpal::SupportedBufferSize::Range { min, max } => 480.clamp(min, max), cpal::SupportedBufferSize::Range { min, max } => 480.clamp(min, max),
cpal::SupportedBufferSize::Unknown => 480, cpal::SupportedBufferSize::Unknown => 480,
}), }),
..cfg.config() ..cfg.config()
}
}) })
.collect(); .collect();
supported_configs.sort_by(|a, b| { supported_configs.sort_by(|a, b| {
let cpal::BufferSize::Fixed(a_buf) = a.buffer_size else { unreachable!() }; let cpal::BufferSize::Fixed(a_buf) = a.buffer_size else {
let cpal::BufferSize::Fixed(b_buf) = b.buffer_size else { unreachable!() }; unreachable!()
};
let cpal::BufferSize::Fixed(b_buf) = b.buffer_size else {
unreachable!()
};
Ord::cmp(&a.channels, &b.channels).then(Ord::cmp(&a_buf, &b_buf)) Ord::cmp(&a.channels, &b.channels).then(Ord::cmp(&a_buf, &b_buf))
}); });
supported_configs.get(0).cloned().ok_or(eyre!("no supported stream configs")) supported_configs
.get(0)
.cloned()
.ok_or(eyre!("no supported stream configs"))
} }
pub fn start_recording( pub fn start_recording(
@@ -91,7 +99,11 @@ impl AudioSystem {
mut each: impl FnMut(Vec<u8>) + Send + 'static, mut each: impl FnMut(Vec<u8>) + Send + 'static,
) -> Result<(), Error> { ) -> Result<(), Error> {
let config = self.choose_config(self.input.supported_input_configs()?)?; let config = self.choose_config(self.input.supported_input_configs()?)?;
info!("creating recording on {:?} with {:#?}", self.input.name()?, config); info!(
"creating recording on {:?} with {:#?}",
self.input.name()?,
config
);
let mut encoder = let mut encoder =
opus::Encoder::new(SAMPLE_RATE, opus::Channels::Mono, opus::Application::Voip)?; opus::Encoder::new(SAMPLE_RATE, opus::Channels::Mono, opus::Application::Voip)?;
let mut current_processor = AudioProcessor::new_plain(); let mut current_processor = AudioProcessor::new_plain();
@@ -118,12 +130,10 @@ impl AudioSystem {
} }
}; };
match self.input.build_input_stream( match self
&config, .input
data_callback, .build_input_stream(&config, data_callback, error_callback, None)
error_callback, {
None,
) {
Ok(stream) => { Ok(stream) => {
stream.play()?; stream.play()?;
self.recording_stream = Some(stream); self.recording_stream = Some(stream);
@@ -138,7 +148,11 @@ impl AudioSystem {
pub fn create_player(&mut self) -> Result<AudioPlayer, Error> { pub fn create_player(&mut self) -> Result<AudioPlayer, Error> {
let config = self.choose_config(self.input.supported_input_configs()?)?; let config = self.choose_config(self.input.supported_input_configs()?)?;
info!("creating player on {:?} with {:#?}", self.output.name().ok(), &config); info!(
"creating player on {:?} with {:#?}",
self.output.name().ok(),
&config
);
let buffer = Arc::new(Mutex::new(dasp_ring_buffer::Bounded::from_raw_parts( let buffer = Arc::new(Mutex::new(dasp_ring_buffer::Bounded::from_raw_parts(
0, 0,
0, 0,
@@ -311,12 +325,15 @@ pub fn load_username() -> Option<String> {
pub async fn load_config() -> color_eyre::Result<ClientConfig> { pub async fn load_config() -> color_eyre::Result<ClientConfig> {
Ok(ClientConfig { Ok(ClientConfig {
proxy_url: None, proxy_url: None,
status_url: None,
cert_hash: None, cert_hash: None,
any_server: true, any_server: true,
}) })
} }
pub async fn get_status(client: &reqwest::Client) -> color_eyre::Result<ServerStatus> {
bail!("status not supported on desktop yet")
}
pub fn init_logging() { pub fn init_logging() {
use tracing::level_filters::LevelFilter; use tracing::level_filters::LevelFilter;
use tracing_subscriber::filter::EnvFilter; use tracing_subscriber::filter::EnvFilter;
+10 -1
View File
@@ -6,7 +6,7 @@ use futures::{AsyncRead, AsyncWrite};
use gloo_timers::future::TimeoutFuture; use gloo_timers::future::TimeoutFuture;
use js_sys::Float32Array; use js_sys::Float32Array;
use mumble_protocol::control::ClientControlCodec; use mumble_protocol::control::ClientControlCodec;
use mumble_web2_common::ClientConfig; use mumble_web2_common::{ClientConfig, ServerStatus};
use reqwest::Url; use reqwest::Url;
use std::future::Future; use std::future::Future;
use std::time::Duration; use std::time::Duration;
@@ -426,6 +426,15 @@ pub async fn load_config() -> color_eyre::Result<ClientConfig> {
Ok(config) Ok(config)
} }
pub async fn get_status(client: &reqwest::Client) -> color_eyre::Result<ServerStatus> {
Ok(client
.get(absolute_url("status")?)
.send()
.await?
.json::<ServerStatus>()
.await?)
}
pub fn init_logging() { pub fn init_logging() {
// copied from tracing_web example usage // copied from tracing_web example usage
+1 -7
View File
@@ -1,10 +1,6 @@
use color_eyre::eyre::{anyhow, bail, Context, Result}; use color_eyre::eyre::{anyhow, bail, Context, Result};
use color_eyre::owo_colors::OwoColorize;
use mumble_web2_common::{ClientConfig, ServerStatus}; use mumble_web2_common::{ClientConfig, ServerStatus};
use once_cell::sync::OnceCell;
use rand::Rng; use rand::Rng;
use rcgen::date_time_ymd;
use rustls::server;
use salvo::conn::rustls::{Keycert, RustlsConfig}; use salvo::conn::rustls::{Keycert, RustlsConfig};
use salvo::cors::{AllowOrigin, Cors}; use salvo::cors::{AllowOrigin, Cors};
use salvo::logging::Logger; use salvo::logging::Logger;
@@ -38,7 +34,6 @@ fn default_cert_alt_names() -> Vec<String> {
#[derive(Debug, Deserialize, Serialize)] #[derive(Debug, Deserialize, Serialize)]
struct Config { struct Config {
public_url: Url,
proxy_url: Option<Url>, proxy_url: Option<Url>,
https_listen_address: SocketAddr, https_listen_address: SocketAddr,
http_listen_address: Option<SocketAddr>, http_listen_address: Option<SocketAddr>,
@@ -85,9 +80,8 @@ async fn main() -> Result<()> {
let mut client_config = ClientConfig { let mut client_config = ClientConfig {
proxy_url: match &server_config.proxy_url { proxy_url: match &server_config.proxy_url {
Some(url) => Some(url.to_string()), Some(url) => Some(url.to_string()),
None => Some(server_config.public_url.join("proxy")?.to_string()), None => None,
}, },
status_url: Some(server_config.public_url.join("status")?.to_string()),
cert_hash: None, cert_hash: None,
any_server: false, any_server: false,
}; };