@dderevjanik/termux-api
Version:
This library allows you to interact with your Android device from Node.js using termux-api
87 lines (75 loc) • 1.6 kB
text/typescript
import { exec } from "child_process";
/**
* Represents the signal information for a cellular network.
*/
export interface CellularNetworkInfo {
/**
* The type of the network.
* @example "lte"
*/
type: string;
/**
* Indicates if the network is registered.
* @example true
*/
registered: boolean;
/**
* The ASU (Arbitrary Strength Unit) level of the network.
* @example 39
*/
asu: number;
/**
* The signal strength in dBm.
* @example -101
*/
dbm: number;
/**
* The signal level.
* @example 2
*/
level: number;
/**
* The Cell Identity (optional).
* @example 7948075
*/
ci?: number;
/**
* The Physical Cell Identity.
* @example 143
*/
pci: number;
/**
* The Tracking Area Code (optional).
* @example 21040
*/
tac?: number;
/**
* The Mobile Country Code (optional).
* @example 231
*/
mcc?: number;
/**
* The Mobile Network Code (optional).
* @example 1
*/
mnc?: number;
}
/**
* Call a telephony number
*/
export async function telephonyCellInfo(): Promise<CellularNetworkInfo> {
return new Promise<CellularNetworkInfo>((resolve, reject) => {
const command = `termux-telephony-cellinfo`;
exec(command, (error, stdout, stderr) => {
if (error) {
return reject(`Error: ${error.message}`);
}
if (stderr) {
return reject(`Error: ${stderr}`);
}
const output = stdout.trim();
const cameraCapabilities: CellularNetworkInfo = JSON.parse(output);
return resolve(cameraCapabilities);
});
});
}