@cldmv/droidsock
v2.2.1
Published
Complete Node.js implementation of the Android Debug Bridge (ADB) protocol
Maintainers
Readme
@cldmv/droidsock
DroidSock is a complete, from-scratch implementation of the Android Debug Bridge (ADB) protocol in Node.js. This library provides full ADB functionality including device connection, RSA authentication, shell command execution, and file transfers - eliminating clicking sounds on Android TV devices!
It talks to devices directly over TCP, with no adb binary or ADB server in between, and composes its protocol layers into a single API tree with @cldmv/slothlet, so every connected device becomes its own persistent API leaf.
ADB over the wire, in pure Node.js - no adb binary required.
[!NOTE] Current status:
- Shell + streaming: Stable - command execution, interactive shells, and log / process streaming all work over the real ADB protocol.
- File transfer:
mkdir/remove/move/copy/chmod/diskUsage/find/statwork today via shell commands.listprefers a binary-safe SYNC-based implementation with automatic shell fallback.- Experimental:
push/pull/pushV2/pullV2/listSync/listV2/statV2(real ADB SYNC sub-protocol usage, both the legacy 32-bit and newer 64-bit variants),device.reboot(),device.forward()/device.reverse(),device.install()(both the classic push-then-install and modern streaming install paths), andpairing.pair()(Wi-Fi pairing) are all implemented - built from the ADB protocol spec and covered by unit tests (several exercised against real loopback TCP / TLS servers, not purely mocks) - but none of them have been run against a real device yet. See #1.
✨ What's New
Latest: v2.2.1 (November 2026)
@cldmv/slothletkept below 3.24.0 - slothlet 3.24.0 hands sockets back as proxies, sodevice.connect()threwTypeError: Illegal invocationon any install that resolved it (slothlet#708). The range is now>=3.22.1 <3.24.0; no droidsock code changed (#112).- Suite runs against the build -
npm run test:distruns the Vitest suite againstdist/, andnpm testincludes it (#107). - View full v2.2.1 Changelog
Recent Releases
- v2.2.0 (November 2026) - CLDMV library layout (
src/index.mjs/src/index.cjsentries, tsup-builtdist/);@cldmv/droidsock/mainis a deprecated alias of the root (Changelog) - v2.1.0 (October 2026) - device lifecycle events, opt-in auto-reconnect with backoff, TCP keepalive and an optional heartbeat;
engines.noderose to>=22.15.0(Changelog) - v2.0.3 (October 2026) -
index.cjsloads the ESM entry with a plainrequire()and fails clearly withoutrequire(esm);@cldmv/droidsock/devcheckis no longer exported or published (Changelog) - v2.0.2 (October 2026) - Dev tooling only: shared CLDMV fix-headers config and a required PR check that never reports as skipped, no runtime change (Changelog)
📚 For complete version history and detailed release notes, see the docs/changelog/ folder.
🚀 Key Features
- ✅ Complete ADB Protocol: TCP connection, CNXN / AUTH handshake, and stream multiplexing implemented from scratch
- ✅ RSA Authentication: Automatic key generation and ADB-specific signature / public-key formatting
- ✅ Stream Multiplexing: Multiple concurrent operations over a single connection
- ✅ Shell Commands: Execute commands, stream output, interactive sessions
- ✅ File Operations: Shell-based
mkdir/remove/move/copy/chmod/diskUsage/find, plus binary-safe SYNC-basedlist, and experimentalpush/pull(legacy 32-bit) /pushV2/pullV2/listV2/statV2(64-bit) - ✅ Reboot (experimental): Real
reboot:service, including bootloader / recovery / sideload modes - ✅ Port Forwarding (experimental):
adb forward/adb reverse-equivalent TCP tunneling, both directions - ✅ APK Install (experimental):
adb install-equivalent local APK installation - classic push-then-install and modern streaming (exec:cmd package install) paths - ✅ Wi-Fi Pairing (experimental):
adb pair-equivalent PIN-based pairing (SPAKE2-over-Ed25519 + TLS 1.3) for Android 11+ wireless debugging - ✅ Device Discovery (experimental):
discover.subnet()CIDR sweep anddiscover.mdns()for devices advertising wireless debugging, plus support for multiple devices via configuration - ✅ Error Handling: Robust error handling and connection recovery
📦 Installation
Requirements
- Node.js v22.15.0 or higher (the package's
engines.nodefloor, set by its@cldmv/slothletdependency) - Both
importandrequire()are supported.require()loads the ESM entry through Node's synchronousrequire(esm), which every supported Node.js version (22.15+) provides; on older versions, load the package withimport()instead. - Developing this package needs Node.js 22.22.0 or later (
devEngines).
Install
npm install @cldmv/droidsock🚀 Quick Start
import droidsock from "@cldmv/droidsock";
// Create the API instance
const api = await droidsock();
// Connect to a device
const device = await api.device.connect("10.6.0.108", 5555);
// Execute a shell command
const output = await device.shell("ls -la");
console.log(output);
// Convenience getters
const model = await device.getModel();
const version = await device.getAndroidVersion();
// Stream commands
const logcat = device.logcat({
onData: (data) => console.log(data)
});
// Clean up
await device.disconnect();CommonJS works the same way: const droidsock = require("@cldmv/droidsock") (also available as createDroidSock).
@cldmv/droidsock/main is a deprecated alias of @cldmv/droidsock: it exports the same functions and prints a DeprecationWarning (code CLDMV_DROIDSOCK_MAIN) once per process. Import @cldmv/droidsock instead; the alias is removed in the next major version.
⚙️ Device Configuration
The example scripts read device addresses from references/devices.json. The folder is git-ignored, so create the file yourself:
{
"livingroom": {
"name": "Living Room TV",
"host": "10.6.0.108",
"port": 5555,
"description": "Main living room Android TV"
},
"bedroom": {
"name": "Master Bedroom TV",
"host": "10.6.0.118",
"port": 5555,
"description": "Master bedroom Android TV"
},
"default": "livingroom"
}📘 API Reference
droidsock(options) (also createDroidSock) creates the API instance; api.device.connect(host, port, options) connects to a device (IPv4 or IPv6) and returns its live leaf - also reachable afterward at api.devices["<host>_<port>"] (a . becomes _, a : becomes __) - exposing connection state, shell execution / streaming, file operations (push / pull / list / stat), reboot, port forwarding, and APK install. api.device.disconnect(host, port) tears down one device's connection without forgetting it - reconnect later with connect() on the same host:port, no need to re-supply options; api.device.remove(host, port) forgets it entirely. api.devices.list() / disconnect() (all) / remove() (all) / get(idOrLeaf) manage the set of known devices as a whole.
📚 See docs/API.md for the full method reference, including every option and the experimental / scope caveats on push / pull / list / forward / reverse / install.
💡 Examples
Basic Usage
# Run basic example with default device
node --conditions=droidsock-dev examples/basic-usage.mjs
# Run with specific device
node --conditions=droidsock-dev examples/basic-usage.mjs livingroomThe examples import @cldmv/droidsock by name. --conditions=droidsock-dev runs them against src/; without it they load the build in dist/ (run npm run build first). See Development.
Streaming Commands
# Stream logcat
node --conditions=droidsock-dev examples/streaming-example.mjs logcat
# Stream top command
node --conditions=droidsock-dev examples/streaming-example.mjs top
# File transfer demo
node --conditions=droidsock-dev examples/streaming-example.mjs files🏗️ Architecture
src/index.mjs is the package entry (src/index.cjs is the CommonJS entry, which loads it through require(esm)) and re-exports the factory from src/droidsock.mjs, which composes the layers below into a single api tree via @cldmv/slothlet:
- Connection Layer (
src/api/connection.mjs): TCP socket + CNXN / AUTH handshake - Authentication Layer (
src/api/auth.mjs): RSA key management and ADB signature / public-key formatting - Stream Layer (
src/api/stream.mjs): ADB stream multiplexing (OPEN / WRTE / OKAY / CLSE) - Shell Layer (
src/api/shell.mjs): Command execution, streaming, and interactive shell APIs - Files Layer (
src/api/files.mjs): Shell-based file operations, a binary-safe SYNCLISTimplementation with automatic shell fallback, and an experimental ADB SYNC sub-protocol implementation for real binary transfer (push/pull) - not yet validated against a real device - Reboot Layer (
src/api/reboot.mjs): Real ADBreboot:service - Forward Layer (
src/api/forward.mjs): TCP port forwarding (host → device) via thetcp:service - Reverse Layer (
src/api/reverse.mjs): TCP port forwarding (device → host) viareverse:forward:/reverse:killforward:and the Stream layer's device-initiated stream handling - Install Layer (
src/api/install.mjs): Local APK install, composed from the Files and Shell layers - Pairing Layer (
src/api/pairing.mjs): Wi-Fi pairing (adb pairequivalent) - a separate TLS 1.3 + SPAKE2 protocol reusing the Authentication layer's persistent RSA identity, not composed with any of the layers above - Device / Devices Layers (
src/api/device.mjs,src/api/devices.mjs): High-level per-device API composing the layers above, split by single-target (device.connect/disconnect/remove) vs. collection-wide (devices.list/disconnect/remove/get) operations. Each device is a real, persistent slothlet leaf atapi.devices.<sanitized host_port>, assigned there byconnect()rather than held in a private module variable, so its methods keep workingself/context access exactly like any other leaf - the leaf outlives any one connection, and onlyremove()unmounts it - Config / Log Layers (
src/api/config.mjs,src/api/log.mjs): Shared configuration and logging
📚 See docs/PROTOCOL.md for wire-level protocol details (packet structure, auth flow, SYNC sub-protocol framing, reboot / forward service usage).
🛠 Troubleshooting
Connection Issues
- Ensure device is on same network
- Enable "ADB over network" in developer options
- Check firewall settings
- Verify IP address and port
Authentication Issues
- Delete existing keys to force re-authorization:
rm -rf ~/.adb - Ensure device shows authorization dialog
- Check device storage permissions
Common Errors
- "Command timeout": Increase timeout in options
- "Stream not open": Ensure connection is established
- "File not found": Check paths and permissions
🧪 Development
The implementation is built directly from the public ADB protocol documentation (AOSP SYNC.TXT and the wire-protocol references), cross-checked against Google's own reference client (google/python-adb) where the public docs are ambiguous, and covered by a mocked Vitest suite. The core connection / shell / stream-multiplexing path has real device usage behind it; the newer SYNC-protocol and service additions (push / pull / listSync / reboot / forward / install) have not yet been run against a real device - see the status note at the top of this README and #1.
The source lives in src/: src/index.mjs is the ESM entry and src/index.cjs the CommonJS entry. npm run build (tsup) writes dist/, which mirrors src/ file by file because slothlet scans dist/api/ at runtime; dist/index.cjs is a verbatim copy of src/index.cjs. Only dist/ and types/ are published.
In a checkout, @cldmv/droidsock resolves to dist/ by default. The droidsock-dev export condition switches it to src/:
| Run | Resolves to |
| ------------------------------------------------ | --------------------------------------------------------------- |
| node app.mjs | dist/index.mjs (ERR_MODULE_NOT_FOUND until npm run build) |
| node --conditions=droidsock-dev app.mjs | src/index.mjs |
| require("@cldmv/droidsock") with the condition | src/index.cjs → src/index.mjs |
Set it once per shell with export NODE_OPTIONS=--conditions=droidsock-dev. npm test runs the Vitest suite against src/ (the Vitest config passes the condition) and then npm run test:cjs, which builds dist/ and checks it with node --test, and npm run test:dist builds dist/ and runs the Vitest suite against it (npm test includes both).
📚 Documentation
- API Reference - every method and option, with the experimental and scope caveats
- Protocol Details - packet structure, auth flow, SYNC sub-protocol framing, reboot / forward service usage
- Changelog - per-version release notes
🤝 Contributing
This is a complete implementation of the ADB protocol. For improvements or bug fixes, please submit issues or pull requests.
🔗 Links
- npm: @cldmv/droidsock
- GitHub: CLDMV/droidsock
- Issues: GitHub Issues
- Changelog: docs/changelog/
📄 License
Apache-2.0 - see LICENSE for details.
