Refactor web.rs match statement.

This commit is contained in:
2026-01-19 13:29:42 -07:00
parent d4c1003f97
commit 95c7981632
+17 -27
View File
@@ -3,7 +3,6 @@ use crate::effects::{AudioProcessor, AudioProcessorSender, TransmitState};
use color_eyre::eyre::{bail, eyre, Error}; use color_eyre::eyre::{bail, eyre, Error};
use crossbeam::atomic::AtomicCell; use crossbeam::atomic::AtomicCell;
use dioxus::prelude::*; use dioxus::prelude::*;
use std::sync::Arc;
use futures::{AsyncRead, AsyncWrite}; use futures::{AsyncRead, AsyncWrite};
use gloo_timers::future::TimeoutFuture; use gloo_timers::future::TimeoutFuture;
use js_sys::Float32Array; use js_sys::Float32Array;
@@ -11,6 +10,7 @@ use mumble_protocol::control::ClientControlCodec;
use mumble_web2_common::{ClientConfig, ServerStatus}; use mumble_web2_common::{ClientConfig, ServerStatus};
use reqwest::Url; use reqwest::Url;
use std::future::Future; use std::future::Future;
use std::sync::Arc;
use std::time::Duration; use std::time::Duration;
use tracing::level_filters::LevelFilter; use tracing::level_filters::LevelFilter;
use tracing::{debug, error, info, instrument}; use tracing::{debug, error, info, instrument};
@@ -120,7 +120,10 @@ impl AudioSystem {
self.processors.store(Some(processor)) self.processors.store(Some(processor))
} }
pub fn start_recording(&mut self, each: impl FnMut(Vec<u8>, bool) + 'static) -> Result<(), Error> { pub fn start_recording(
&mut self,
each: impl FnMut(Vec<u8>, bool) + 'static,
) -> Result<(), Error> {
let audio_context_worklet = self.webctx.clone(); let audio_context_worklet = self.webctx.clone();
let processors = self.processors.clone(); let processors = self.processors.clone();
spawn(async move { spawn(async move {
@@ -312,34 +315,21 @@ async fn run_encoder_worklet(
// Don't encode or send anything // Don't encode or send anything
return; return;
} }
TransmitState::Transmitting => { TransmitState::Transmitting => (), // Normal transmission
// Normal transmission
match AudioData::new(frame.unchecked_ref()) {
Ok(data) => {
let _ = audio_encoder.encode(&data);
}
Err(err) => {
error!(
"error creating AudioData object {:?} during event {:?}",
err, event,
);
}
}
}
TransmitState::Terminator => { TransmitState::Terminator => {
// Mark this as a terminator before encoding // Mark this as a terminator before encoding
pending_terminator.store(true); pending_terminator.store(true);
match AudioData::new(frame.unchecked_ref()) { }
Ok(data) => { }
let _ = audio_encoder.encode(&data); match AudioData::new(frame.unchecked_ref()) {
} Ok(data) => {
Err(err) => { let _ = audio_encoder.encode(&data);
error!( }
"error creating AudioData object {:?} during event {:?}", Err(err) => {
err, event, error!(
); "error creating AudioData object {:?} during event {:?}",
} err, event,
} );
} }
} }
}); });