stop
stop
Info
stop terminates the current audio analysis session and releases the native capture process. It also stops any active polling started via startPolling. Returns a CommandResult confirming the stop.
Signature
function stop(): CommandResultParameters
This function takes no parameters.
Usage
Call stop when you no longer need audio analysis — for example, when the user navigates away from the visualization, the application is closing, or you want to switch to a different target process. Typical workflow:
- Start analysis with start.
- Consume data via getResult or startPolling.
- Call
stopto release resources.
Note
stop is safe to call even if no analysis is running. It will return success: true and perform no action.
Tips
If you are using startPolling, you do not need to call stopPolling separately — stop automatically stops polling before terminating the capture process.
Return Value
Returns a CommandResult object.
| Type | Description |
|---|---|
| CommandResult | Always { success: true, error: null } since stopping is always possible. |
Warning
After stop returns, getResult will return an empty result (frozen default values). Any pending polling callbacks will no longer fire. Ensure your UI handles the transition gracefully.
Example
import { start, stop, getResult, CommandResult } from '@eisland/windows-volume-analyzer';
// Start analysis
start(12345);
// ... use getResult() or startPolling() ...
// Stop analysis and clean up
const result: CommandResult = stop();
console.log(`Stopped: ${result.success}`);const { start, stop, getResult } = require('@eisland/windows-volume-analyzer');
// Start analysis
start(12345);
// ... use getResult() or startPolling() ...
// Stop analysis and clean up
const result = stop();
console.log(`Stopped: ${result.success}`);Notes
Note
The native capture process is terminated gracefully — a newline is sent to its stdin, and a 1-second kill timer is set as a fallback. In most cases, the process exits within milliseconds.
Tips
If you plan to start analyzing a different process, you can call start directly without calling stop first. The start function automatically stops any existing session before starting a new one.
Important
After stop, the getStatus function will report isRunning: false. However, the error field from the previous session persists until a new start call succeeds.
Danger Avoidance
Caution
Do not call getResult or rely on polling callbacks after stop. The result will be an empty default object with all values at zero. If your UI is still rendering based on analysis data, it will display incorrect information. Unsubscribe from polling before stopping, or guard your render logic with getStatus checks.
Changelog
bb5b2-on

