UNPKG

@dderevjanik/termux-api

Version:

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

92 lines (79 loc) 1.84 kB
import { exec } from "child_process"; export interface CameraImageSize { /** * The width of the image. * @example 4608 */ width: number; /** * The height of the image. * @example 2592 */ height: number; } export interface CameraPhysicalSize { /** * The width of the sensor. * @example 6.495999813079834 */ width: number; /** * The height of the sensor. * @example 4.860799789428711 */ height: number; } export interface CameraCapabilities { /** * The ID of the camera. * @example "0" */ id: string; /** * The facing direction of the camera. * @example "back" */ facing: string; /** * The available JPEG output sizes. */ jpeg_output_sizes: CameraImageSize[]; /** * The available focal lengths. * @example [4.695000171661377] */ focal_lengths: number[]; /** * The available auto exposure modes. * @example ["CONTROL_AE_MODE_OFF", "CONTROL_AE_MODE_ON"] */ auto_exposure_modes: string[]; /** * The physical size of the camera sensor. */ physical_size: CameraPhysicalSize; /** * The capabilities of the camera. * @example ["backward_compatible", "constrained_high_speed_video"] */ capabilities: string[]; } /** * Get information about device camera(s) */ export async function cameraInfo(): Promise<CameraCapabilities[]> { return new Promise<CameraCapabilities[]>((resolve, reject) => { const command = `termux-camera-info`; exec(command, (error, stdout, stderr) => { if (error) { return reject(`Error: ${error.message}`); } if (stderr) { return reject(`Error: ${stderr}`); } const output = stdout.trim(); const cameraCapabilities: CameraCapabilities[] = JSON.parse(output); return resolve(cameraCapabilities); }); }); }