UNPKG

@dderevjanik/termux-api

Version:

This library allows you to interact with your Android device from Node.js using termux-api

71 lines (64 loc) 1.62 kB
import { exec } from "child_process"; export interface VolumeSettings { /** * The type of audio stream. * @example "music" */ stream: string; /** * The current volume level of the audio stream. * @example 43 */ volume: number; /** * The maximum volume level of the audio stream. * @example 150 */ max_volume: number; } export interface VolumeOptions { /** * Audio stream to change the volume of */ stream: "alarm|" | "music" | "notification" | "ring" | "system" | "call"; /** * Volume level to set the stream to */ volume: number; } /** * Show information about each audio stream */ export async function volumeInfo(): Promise<VolumeSettings[]> { return new Promise<VolumeSettings[]>((resolve, reject) => { const command = `termux-volume`; exec(command, (error, stdout, stderr) => { if (error) { return reject(`Error: ${error.message}`); } if (stderr) { return reject(`Error: ${stderr}`); } const output = stdout.trim(); const settings: VolumeSettings[] = JSON.parse(stdout); return resolve(settings); }); }); } /** * Change volume of audio stream */ export async function volume(options: VolumeOptions): Promise<void> { return new Promise<void>((resolve, reject) => { const command = `termux-volume ${options.stream} ${options.volume}`; exec(command, (error, stdout, stderr) => { if (error) { return reject(`Error: ${error.message}`); } if (stderr) { return reject(`Error: ${stderr}`); } return resolve(); }); }); }