@dderevjanik/termux-api
Version:
This library allows you to interact with your Android device from Node.js using termux-api
32 lines (31 loc) • 1.05 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.cameraPhoto = cameraPhoto;
const child_process_1 = require("child_process");
/**
* Take a photo and save it to a file in JPEG format
*
* **Requires permission** `android.permission.CAMERA`
*/
async function cameraPhoto(options = {}) {
const opts = {
cameraId: 0,
output: `${new Date().toISOString().replace(/:/g, "-")}.jpg`,
timeout: 3_000,
...options,
};
// TODO: Check if path is correct, or create it
return new Promise((resolve, reject) => {
const command = `termux-camera-photo -c ${opts.cameraId} "${opts.output}"`;
const execOptions = { timeout: opts.timeout };
(0, child_process_1.exec)(command, execOptions, (error, stdout, stderr) => {
if (error) {
return reject(`Error: ${error.message}`);
}
if (stderr) {
return reject(`Error: ${stderr}`);
}
return resolve();
});
});
}