npm package: @dderevjanik/termux-api
Description: This library allows you to interact with your Android device from Node.js using termux-api
Author: Daniel Derevjanik
Latest version: 0.1.2

# Termux API

A wrapper for [Termux API](https://wiki.termux.com/wiki/Termux:API) in Node.js. This library allows you to interact with your Android device from Node.js using termux-api. This library is a work in progress and not all termux-api commands are implemented.

![overview](./docs/overview.png)

## Usage

Install library `npm i termux-api` in your **Termux instance**.

Naming convention follows termux-api commands. For example, `termux-battery-status` becomes `batteryStatus`.

```typescript
import { torch } from "./termux-api";

await torch("on");
await toch("off");
```

## Termux API Progress

- ✅ **termux-battery-status** (`batteryStatus`) ([wiki](https://wiki.termux.com/wiki/Termux-battery-status)) (source)
- ✅ **termux-brightness** (`brightness`) ([wiki](https://wiki.termux.com/wiki/Termux-brightness)) (source)
- ✅ **termux-call-log** (`callLog`) ([wiki](https://wiki.termux.com/wiki/Termux-call-log)) (source)
- ✅ **termux-camera-info** (`cameraInfo`) ([wiki](https://wiki.termux.com/wiki/Termux-camera-info)) (source)
- ✅ **termux-camera-photo** (`cameraPhoto`) ([wiki](https://wiki.termux.com/wiki/Termux-camera-photo)) (source)
- ✅ **termux-clipboard-get** (`clipboardGet`) ([wiki](https://wiki.termux.com/wiki/Termux-clipboard-get)) (source)
- ✅ **termux-clipboard-set** (`clipboardSet`) ([wiki](https://wiki.termux.com/wiki/Termux-clipboard-set)) (source)
- ✅ **termux-contact-list** (`contactList`) ([wiki](https://wiki.termux.com/wiki/Termux-contact-list)) (source)
- ⏳ **termux-dialog** (`dialog`) (wiki) (source)
- ⏳ **termux-download** (`download`) (wiki) (source)
- ✅ **termux-fingerprint** (`fingerprint`) ([wiki](https://wiki.termux.com/wiki/Termux-fingerprint)) (source)
- ✅ **termux-infrared-frequencies** (`infraredFrequencies`) ([wiki](https://wiki.termux.com/wiki/Termux-infrared-frequencies)) (source)
- ✅ **termux-infrared-transmit** (`infraredTransmit`) ([wiki](https://wiki.termux.com/wiki/Termux-infrared-transmit)) (source)
- ⏳ **termux-job-scheduler** (`jobScheduler`) (wiki) (source)
- ⏳ **termux-keystore** (`keystore`) (wiki) (source)
- ✅ **termux-location** (`location`) ([wiki](https://wiki.termux.com/wiki/Termux-location)) (source)
- ✅ **termux-media-player** (`mediaPlayer`) ([wiki](https://wiki.termux.com/wiki/Termux-media-player)) (source)
- ⏳ **termux-media-scan** (`mediaScan`) (wiki) (source)
- ⏳ **termux-microphone-record** (`microphoneRecord`) (wiki) (source)
- ⏳ **termux-nfc** (`nfc`) (wiki) (source)
- ⏳ **termux-notification-channel** (`notificationChannel`) (wiki) (source)
- ⏳ **termux-notification-list** (`notificationList`) (wiki) (source)
- ⏳ **termux-notification-remove** (`notificationRemove`) (wiki) (source)
- ⏳ **termux-notification** (`notification`) (wiki) (source)
- ⏳ **termux-sensor** (`sensor`) (wiki) (source)
- ⏳ **termux-share** (`share`) (wiki) (source)
- ✅ **termux-sms-inbox** (`smsInbox`) ([wiki](https://wiki.termux.com/wiki/Termux-sms-inbox)) (source)
- ✅ **termux-sms-list** (`smsList`) ([wiki](https://wiki.termux.com/wiki/Termux-sms-list)) (source)
- ✅ **termux-sms-send** (`smsSend`) ([wiki](https://wiki.termux.com/wiki/Termux-sms-send)) (source)
- ⏳ **termux-speech-to-text** (`speechToText`) (wiki) (source)
- ⏳ **termux-storage-get** (`storageGet`) (wiki) (source)
- ⏳ **termux-telephony-call** (`telephonyCall`) (wiki) (source)
- ✅ **termux-telephony-cellinfo** (`telephonyCellInfo`) ([wiki](https://wiki.termux.com/wiki/Termux-telephony-cellinfo)) (source)
- ✅ **termux-telephony-deviceinfo** (`telephonyDeviceInfo`) ([wiki](https://wiki.termux.com/wiki/Termux-telephony-deviceinfo)) (source)
- ⏳ **termux-toast** (`toast`) (wiki) (source)
- ✅ **termux-torch** (`torch`) ([wiki](https://wiki.termux.com/wiki/Termux-torch)) (source)
- ⏳ **termux-tts-engines** (`ttsEngines`) (wiki) (source)
- ⏳ **termux-tts-speak** (`ttsSpeak`) (wiki) (source)
- ⏳ **termux-usb** (`usb`) (wiki) (source)
- ✅ **termux-vibrate** (`vibrate`) ([wiki](https://wiki.termux.com/wiki/Termux-vibrate)) (source)
- ✅ **termux-volume** (`volume`) ([wiki](https://wiki.termux.com/wiki/Termux-volume)) (source)
- ⏳ **termux-wallpaper** (`wallpaper`) (wiki) (source)
- ✅ **termux-wifi-connectioninfo** (`wifiConnectionInfo`) ([wiki](https://wiki.termux.com/wiki/Termux-wifi-connectioninfo)) (source)
- ✅ **termux-wifi-enable** (`wifiEnable`) ([wiki](https://wiki.termux.com/wiki/Termux-wifi-enable)) (source)
- ✅ **termux-wifi-scaninfo** (`wifiScanInfo`) ([wiki](https://wiki.termux.com/wiki/Termux-wifi-scaninfo)) (source)

## Development

- Set up remote access control to Termux instance <https://wiki.termux.com/wiki/Remote_Access>
- Generate `.pem` key <https://serverfault.com/questions/706336/how-to-get-a-pem-file-from-ssh-key-pair>
- Put `.pem` key to `deploy/termux.pem`

### On remote machine

```sh
ssh user@remote_machine_ip
sudo apt update
sudo apt install openssh-server
ssh-keygen -t rsa -b 2048 -m PEM -f ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
chmod 600 ~/.ssh/authorized_keys
```

### On local machine

```sh
scp user@remote_machine_ip:~/.ssh/id_rsa ~/path_to_save/id_rsa.pem
chmod 400 ~/path_to_save/id_rsa.pem
ssh -i ~/path_to_save/id_rsa.pem user@remote_machine_ip
```

## TODO

- [ ] Timeout for exec (sometimes termux-api hangs)
- [ ] Use `zod` for validation (e.g. Contact, Location, Message, etc.)
- [ ] Add jsdoc to termux-api functions
  - Include requirements (permission, min. android version, hardware)