Skip to content

Demonstrates how to access Android devices using Node.js, and forward the ADB connection to Web clients.

Notifications You must be signed in to change notification settings

tango-adb/example-nodejs

Repository files navigation

Remote ADB

This repository demonstrates how to access Android devices using Node.js, and forward the ADB connection to Web clients.

Features

  • List Android devices connected to the server over USB
  • Mirror the device screen and control the device from a Web client

How does it work?

  1. The server uses Tango in Direct Connection mode to connect to Android devices over USB.
  2. It creates a custom protocol to forward ADB sockets to Web clients over WebSocket.
  3. The Web client creates a custom transport that converts WebSocket messages back to ADB sockets.
  4. The Web client creates an Adb instance to operate on the device.

The server can share a device with multiple clients, because the client operates on ADB socket level.

Data Protocol

Comlink library is used to simplify the communication between the server and the client. It allows calling functions on the server from the client as if they were local functions.

Comlink doesn't have built-in support for WebSocket connections, so a custom endpoint object is implemented to serialize and deserialize Comlink messages using MsgPack format.

Note that although Comlink is very easy to use, it's definitely not the most efficient way, due to its messaging overhead. Sending raw data on the WebSocket connection will be more efficient, for example using one WebSocket connection for each ADB socket.

Run

git clone --recurse-submodules https://github.com/tango-adb/demo-nodejs.git
pnpm recursive i
pnpm recursive run build

Start the server

cd server
pnpm start

The server listens on port 8081.

Start the client

cd web
pnpm start

The client project has its own server listening on port 3000.

Other possible architectures

In this demo, the client uses Tango to serialize and deserialize ADB commands, and the server uses Tango to send other commands to the device.

It can be safer to only use Tango on the server side, and creating API endpoints for each feature you want to expose to the client. This way, the client can't execute arbitrary ADB commands, but only the ones you expose.

About

Demonstrates how to access Android devices using Node.js, and forward the ADB connection to Web clients.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published