Server Transport
As mentioned in USB Connection, a USB device can only be exclusively accessed by one program at a time. This means if multiple ADB clients want to access the same device, only one of them can succeed.
Google ADB solves this problem by starting a server (also called "host") to manage the USB devices, and all ADB clients connect to the server, instead of the device directly. The server forwards ADB commands to devices for those clients.
The protocol between ADB Client and Server is different from the protocol between ADB Server and Daemon. AdbServerClient
class is a TypeScript re-implementation of Google ADB Client. It connects to Google ADB Server using TCP sockets, and can create AdbServerTransport
s for each device.
Installation
This class is included in the core package:
- npm
- Yarn
- pnpm
npm i @yume-chan/adb
yarn add @yume-chan/adb
pnpm add @yume-chan/adb
To support different runtime environments, AdbServerClient
uses an AdbServerConnector
implementation to create those TCP sockets. Currently, there is no built-in connector for Web platforms, as TCP sockets are not supported there. Tango provides a Node.js implementation using its net
module, and also accepts custom connector implementations for other runtime environments.
Overview
Here are the overall steps to create an Adb
instance from AdbServerClient
:
- User creates an
AdbServerClient.ServerConnector
that works on the target runtime environment. - User creates an
AdbServerClient
instance with the connector. - User queries the device list and selects an already authenticated device.
- User creates an
AdbServerTransport
instance for the selected device. - User creates an
Adb
instance with the transport object.