move audio stuff into trait

This commit is contained in:
2026-01-24 21:19:58 -07:00
committed by Liam Warfield
parent 056a673bc0
commit 09985e6031
4 changed files with 63 additions and 50 deletions
+26 -5
View File
@@ -2,8 +2,9 @@
//!
//! This module defines traits that each platform (web, desktop, mobile) must implement.
//! The traits make the platform boundary explicit and provide compile-time verification.
#![allow(async_fn_in_trait)]
use crate::app::Command;
use crate::{app::Command, effects::AudioProcessor};
use color_eyre::eyre::Error;
use dioxus::hooks::UnboundedReceiver;
use mumble_web2_common::{ClientConfig, ServerStatus};
@@ -14,11 +15,31 @@ use std::time::Duration;
// Trait Definitions
// ============================================================================
pub trait AudioSystemInterface {
pub trait AudioSystemInterface: Sized {
type AudioPlayer: AudioPlayerInterface;
/// Initialize the audio system, including relevant state
async fn new() -> Result<Self, Error>;
/// Set the processor for the microphone input, mainly noise cancellation settings.
fn set_processor(&self, processor: AudioProcessor);
/// Begin listening to microphone input, calling the `each` function with
/// encoded opus frames.
fn start_recording(
&mut self,
each: impl FnMut(Vec<u8>, bool) + Send + 'static,
) -> Result<(), Error>;
/// Begin playback of an audio stream, returning an object that can be passed
/// with opus frames.
fn create_player(&mut self) -> Result<Self::AudioPlayer, Error>;
}
pub trait AudioPlayerInterface {}
pub trait AudioPlayerInterface {
/// Playback an opus frame.
fn play_opus(&mut self, payload: &[u8]);
}
/// This is the main trait that each platform must implement. It combines all
/// platform-specific functionality into a single interface, providing compile-time
@@ -72,9 +93,9 @@ pub trait PlatformInterface {
pub mod web;
#[cfg(any(feature = "desktop", feature = "mobile"))]
mod connect;
pub mod connect;
#[cfg(any(feature = "desktop", feature = "mobile"))]
mod native_audio;
pub mod native_audio;
#[cfg(feature = "desktop")]
pub mod desktop;