packages/frontend/native/media_capture/src/windows/README.md
This module provides Windows-specific audio recording functionality using the Windows Audio Session API (WASAPI).
The MicrophoneListener class provides real-time monitoring of microphone usage:
import { MicrophoneListener } from '@affine/native';
const listener = new MicrophoneListener((isRunning: boolean, processName: string) => {
console.log(`Microphone ${isRunning ? 'started' : 'stopped'} by ${processName}`);
});
// Check current status
console.log('Is microphone currently active:', listener.is_running());
The callback receives two parameters:
isRunning: boolean - Whether the microphone is currently activeprocessName: string - Name of the process using the microphoneThe implementation uses Windows Audio Session API to:
The module automatically initializes COM (Component Object Model) with COINIT_MULTITHREADED for proper Windows API interaction.
All Windows API errors are wrapped in WindowsAudioError enum and converted to NAPI errors for JavaScript consumption.
This Windows implementation maintains API compatibility with the macOS version, providing the same JavaScript interface while using Windows-specific APIs underneath.
windows crate v0.61 with Audio and Process featureswindows-core crate v0.61napi and napi-derive for JavaScript bindingsThe implementation uses thread-safe callbacks to JavaScript with ThreadsafeFunction<(bool, String), ()> to ensure proper communication between the Windows audio session monitoring thread and the JavaScript runtime.
Process names are resolved using Windows APIs:
GetModuleFileNameExW for full executable pathGetProcessImageFileNameW as fallbackThe implementation automatically filters out system audio sessions (like AudioSrv) to focus on user applications.