@touchifyapp/cpvc
v0.1.3
Published
Template project for writing node package with napi-rs
Maintainers
Readme
@touchifyapp/cpvc (Cross-Platform Volume Control)
Cross platform module for interacting with Audio Devices and handling System Audio. Node bindings for the cpvc crate.
Compatibility
- Windows
- Mac OS X
- Linux (PulseAudio only)
Important
cpvcrequires PulseAudio server to work on Linux.
Prebuilt binaries
| ✓ | Platform | arch | | --- | -------- | ------------ | | ✅ | Windows | x64 | | ✅ | Windows | x86 | | ✅ | Windows | arm64 | | ✅ | macOS | x64 | | ✅ | macOS | arm64 | | ✅ | Linux | x64 (gnu) | | ✅ | Linux | x64 (musl) | | ✅ | Linux | arm (gnu) | | ❌ | Linux | arm64 (musl) | | ❌ | FreeBSD | x64 |
Note: To build package from source,
libasound2-devandlibpulse-devlibraries are required. (eg.sudo apt install libasound2-dev libpulse-dev).
Installation
# npm
npm i @touchifyapp/cpvc
# pnpm
pnpm add @touchifyapp/cpvc
#yarn
yarn add @touchifyapp/cpvcUsage
import { getSoundDevices, getMute, setMute, getSystemVolume, setSystemVolume } from "../index.js";
// get system sound devices names
const devices = getSoundDevices();
console.log(devices); // prints ['devicename']
// check whether the system is muted
const muted = getMute();
console.log("is muted:", muted); // prints is muted: false
// set whether the system is muted
setMute(true);
const muted = getMute();
console.log("is muted:", muted); // prints is muted: true
// get current system volume
const volume = getSystemVolume();
console.log("volume:", volume); // prints volume: 30
// set system volume
setSystemVolume(50);
const volume = getSystemVolume();
console.log("volume:", volume); // prints volume: 50Contribute
Prerequistes
- Install the latest
Rust - Install
Node.js@20+which fully supportedNode-API - Run
corepack enable
Getting started
# clone repository
git clone https://github.com/touchifyapp/node-cpvc
cd node-cpvc
# install packages
pnpm i
# build and test
pnpm build
pnpm testBuild
After pnpm build command, you can see cpvc.[darwin|win32|linux].node file in project root.
This is the native addon built from lib.rs.
Test
Run pnpm test to testing native addon.
Note: a build is necessary before running
pnpm testif changes were applied on the rust code.
CI
With GitHub Actions, each commit and pull request will be built and tested automatically in [node@20, node@22, node@24] x [macOS, Linux, Windows] matrix.
