Overview
TCP Streamer is built with Tauri v2, combining a Rust backend for high-performance audio streaming with a modern web frontend for the user interface.Technology Stack
- Frontend: HTML, CSS, JavaScript with Vite
- Backend: Rust with Tauri framework
- Audio: cpal (cross-platform audio library)
- Storage: tauri-plugin-store (settings persistence)
- Build Tool: Vite (frontend), Cargo (backend)
Directory Layout
Frontend Architecture (src/)
The frontend is a single-page application built with vanilla JavaScript and Vite.
Key Files
index.html (42KB)
The main UI layout containing:
- Tabbed interface (Audio, Profiles, Stats, Advanced, Logs)
- Audio device selection and configuration
- Profile management UI
- Real-time statistics display
- Network quality indicators
- Activity log viewer
- System tray integration
main.js (30KB)
Application logic handling:
- Tauri API integration
- Event listeners for user interactions
- State management and persistence
- Real-time UI updates from backend events
- Profile CRUD operations
- Audio device enumeration
- Streaming control (start/stop)
- Statistics visualization
startStream()- Initiates audio streamingstopStream()- Stops streaming and cleanuploadDevices()- Enumerates audio devicessaveProfile()- Persists configurationupdateStats()- Updates real-time statistics
styles.css (19KB)
Modern, responsive styling:
- Dark theme UI
- Tabbed navigation
- Custom buttons and inputs
- Volume meters and progress bars
- Status indicators
- Log viewer styling
- Responsive layout
Backend Architecture (src-tauri/)
The Rust backend handles audio capture, streaming, and system integration.
Key Files
lib.rs (3.8KB)
Application setup and system integration:
- Tauri app initialization
- System tray icon and menu
- Window management
- App lifecycle management
- Command registration
audio.rs (52KB)
Core audio streaming implementation:
- Audio device management
- Audio capture with cpal
- Lock-free ring buffer
- TCP connection handling
- Silence detection
- Adaptive buffer resizing
- Precision timing with token bucket algorithm
- Real-time statistics calculation
- Network quality monitoring
main.rs (187 bytes)
Simple entry point:
Cargo Dependencies (Cargo.toml)
Core dependencies:
tauri = "2"- Application frameworkcpal = "0.15"- Audio captureringbuf = "0.3"- Lock-free ring buffersocket2 = "0.5"- TCP networking
serde = "1"- Serialization frameworkserde_json = "1"- JSON support
tauri-plugin-autostart = "2"- Auto-start on boottauri-plugin-store = "2"- Settings persistencetauri-plugin-single-instance = "2"- Single instance enforcementtauri-plugin-log = "2.7.1"- Loggingtauri-plugin-opener = "2"- File/URL opening
chrono = "0.4"- Date/time handlingthread-priority = "3.0.0"- Thread priority controlhostname = "0.4"- Hostname retrievalmac_address = "1.1"- MAC address retrievallog = "0.4.28"- Logging facade
Audio Pipeline Architecture
The audio streaming pipeline is designed for low-latency, high-reliability performance.Data Flow
Key Components
1. Audio Capture (cpal)- Cross-platform audio input
- Native support for WASAPI (Windows), CoreAudio (macOS), ALSA (Linux)
- Configurable sample rate (44.1kHz, 48kHz)
- Configurable buffer size (256-2048 samples)
- Lock-free SPSC (Single Producer Single Consumer)
- Absorbs network jitter
- Adaptive sizing based on network conditions
- Prevents audio dropouts
- Token bucket algorithm
- Sub-millisecond timing with spin-wait
- Eliminates micro-bursts
- Drift-aware for long-term stability
- Separate thread for TCP operations
- Non-blocking I/O
- 5-second write timeout
- Auto-reconnect on failure
- Real-time statistics
Build System
Frontend Build (Vite)
vite.config.js configures the frontend build:
- Development server with hot-reload
- Production optimization and bundling
- Asset handling
- Integration with Tauri
Backend Build (Cargo)
build.rs runs during compilation:
- Generates platform-specific resources
- Embeds application icons
- Configures Tauri build settings
Build Output
Development:- Frontend:
http://localhost:5173(dev server) - Backend:
src-tauri/target/debug/tcp-streamer
- Frontend: Bundled into Tauri app
- Backend:
src-tauri/target/release/tcp-streamer - Installers:
src-tauri/target/release/bundle/
Configuration Files
package.json
Node.js project configuration:
tauri.conf.json
Tauri application configuration:
- App metadata (name, version)
- Window settings (size, title, decorations)
- Build settings (target platforms)
- Plugin configuration
- Security settings (CSP, allowlists)
State Management
Settings Persistence
User settings are persisted usingtauri-plugin-store:
- Location: Platform-specific app data directory
- Format: JSON
- Auto-save on change
- Audio device selection
- Network configuration (IP, port)
- Audio settings (sample rate, buffer size)
- Silence detection settings
- Automation preferences
- User profiles
Extension Points
Adding New Features
Frontend:- Add UI components in
index.html - Add event handlers in
main.js - Style with
styles.css
- Define Tauri commands in
lib.rs - Implement logic in appropriate module
- Emit events to frontend if needed
Adding Dependencies
JavaScript:Architecture Principles
- Separation of Concerns: Frontend handles UI, backend handles audio/networking
- Performance: Lock-free data structures, dedicated threads for I/O
- Reliability: Auto-reconnect, adaptive buffering, error handling
- Cross-platform: Tauri provides unified API across macOS/Windows/Linux
- Modern Stack: Rust for safety and performance, web tech for flexible UI