From 65c9049b60d16a629ace312b0ba0085acae22a92 Mon Sep 17 00:00:00 2001 From: Simon Chan <1330321+yume-chan@users.noreply.github.com> Date: Tue, 12 Dec 2023 17:44:31 +0800 Subject: [PATCH] chore: add discord link to README --- README.md | 9 +- libraries/adb-credential-web/README.md | 85 ++-- libraries/adb-credential-web/package.json | 2 +- libraries/adb-daemon-webusb/README.md | 176 +++------ libraries/adb/README.md | 412 +++----------------- libraries/scrcpy-decoder-tinyh264/README.md | 2 +- 6 files changed, 145 insertions(+), 541 deletions(-) diff --git a/README.md b/README.md index c0984e629..3b905f34c 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,5 @@

- - Tango - + Tango

Tango

@@ -15,11 +13,14 @@ MIT License - GitHub release + GitHub release npm + + Discord +

Tango is a TypeScript re-implementation of ADB (Android Debugging Bridge) client that works in Chromium-based browsers (including Chrome for Android), Node.js, and Electron. diff --git a/libraries/adb-credential-web/README.md b/libraries/adb-credential-web/README.md index f49d02305..9437b8e83 100644 --- a/libraries/adb-credential-web/README.md +++ b/libraries/adb-credential-web/README.md @@ -1,39 +1,46 @@ -# `@yume-chan/adb-credential-web` - -Generate RSA keys using Web Crypto API ([MDN](https://developer.mozilla.org/en-US/docs/Web/API/Web_Crypto_API)) and store them in IndexedDB ([MDN](https://developer.mozilla.org/en-US/docs/Web/API/IndexedDB_API)). - -Local storage is not available in Web Workers (for example WebUSB API is supported in Chrome extension service workers), so IndexedDB is used instead. - -- [Constructor](#constructor) -- [`generateKey`](#generatekey) -- [`iterateKeys`](#iteratekeys) - -## Constructor - -```ts -public constructor(); -``` - -Create a new instance of `AdbWebCredentialStore`. - -## `generateKey` - -```ts -async generateKey(): Promise -``` - -Generate a RSA private key and store it into LocalStorage. - -Calling this method multiple times will overwrite the previous key. - -The returned `Uint8Array` is the private key in PKCS #8 format. - -## `iterateKeys` - -```ts -async *iterateKeys(): AsyncGenerator -``` - -Yield the stored RSA private key. `AdbWebCredentialStore` only stores one key, so only one value will be yielded. - -This method returns a generator, so `for await...of...` loop should be used to read the key. +

+ Tango +

+ +

@yume-chan/adb-credential-web

+ +

+ Credential Store for `@yume-chan/adb` using WebCrypto and IndexedDB APIs. +

+ +

+ + MIT License + + + GitHub release + + + npm + + + Discord + +

+ +This package is part of [Tango ADB](https://github.com/yume-chan/ya-webadb). Generally you need multiple packages to build a complete ADB client that can run on Web browsers and Node.js. Read the documentation for more information. + +## Documentation + +Check the latest documentation at https://tango-adb.github.io/docs/ + +## Sponsors + +[Become a backer](https://opencollective.com/ya-webadb) and get your image on our README on Github with a link to your site. + + + + + + + + + + + + diff --git a/libraries/adb-credential-web/package.json b/libraries/adb-credential-web/package.json index 1f52ee280..2c3764ec3 100644 --- a/libraries/adb-credential-web/package.json +++ b/libraries/adb-credential-web/package.json @@ -1,7 +1,7 @@ { "name": "@yume-chan/adb-credential-web", "version": "0.0.21", - "description": "Credential Store for `@yume-chan/adb` using Web LocalStorage API.", + "description": "Credential Store for `@yume-chan/adb` using WebCrypto and IndexedDB APIs.", "keywords": [ "adb" ], diff --git a/libraries/adb-daemon-webusb/README.md b/libraries/adb-daemon-webusb/README.md index 1ecc180c7..bf2e3676f 100644 --- a/libraries/adb-daemon-webusb/README.md +++ b/libraries/adb-daemon-webusb/README.md @@ -1,130 +1,46 @@ -# @yume-chan/adb-daemon-webusb - -ADB daemon transport device for `@yume-chan/adb` using WebUSB ([MDN](https://developer.mozilla.org/en-US/docs/Web/API/USB), [Spec](https://wicg.github.io/webusb)) API. - -- [Use in browser](#use-in-browser) -- [Use in Node.js](#use-in-nodejs) -- [`AdbDaemonWebUsbDevice`](#adbdaemonwebusbdevice) - - [constructor](#constructor) - - [`raw`](#raw) - - [`connect`](#connect) -- [`AdbDaemonWebUsbDeviceManager`](#adbdaemonwebusbdevicemanager) - - [`BROWSER`](#browser) - - [constructor](#constructor-1) - - [`requestDevice`](#requestdevice) - - [`getDevices`](#getdevices) -- [Note on secure context](#note-on-secure-context) - -## Use in browser - -| Chrome | Edge | Firefox | Internet Explorer | Safari | -| -------------- | -------------- | ------- | ----------------- | ------ | -| 611 | 791 | No | No | No | - -1: Chrome for Android is supported, Chrome for iOS is NOT supported. - -## Use in Node.js - -| Node.js | `usb` NPM Package | -| ------- | ----------------- | -| 10.5 | 2.8.1 | - -Node.js doesn't have native support for WebUSB API, but the [`usb`](https://www.npmjs.com/package/usb) NPM package provides a WebUSB compatible API. - -To use a custom WebUSB API implementation, pass it to the constructor of `AdbDaemonWebUsbDevice`, `AdbDaemonWebUsbDeviceManager` and `AdbDaemonWebUsbConnectionWatcher` via the `usbManager` parameter. - -## `AdbDaemonWebUsbDevice` - -### constructor - -```ts -public constructor( - device: USBDevice, - filters: AdbDeviceFilter[] = [ADB_DEFAULT_DEVICE_FILTER] - usbManager: USB -); -``` - -Create a new instance of `AdbDaemonWebUsbDevice` using a specified `USBDevice` instance. - -`USBDevice` and `USB` types are from WebUSB API. - -The `filters` parameter specifies the `classCode`, `subclassCode` and `protocolCode` to use when searching for ADB interface. The default value is `[{ classCode: 0xff, subclassCode: 0x42, protocolCode: 0x1 }]`, defined by Google. - -### `raw` - -```ts -public get raw(): USBDevice; -``` - -Gets the raw `USBDevice` from the device. Allow sending/receiving USB packets to other interfaces/endpoints. For example can be used with `@yume-chan/aoa` package. - -### `connect` - -```ts -public async connect(): Promise< - ReadableWritablePair> -> -``` - -Claim the device and create a pair of `AdbPacket` streams to the ADB interface. - -## `AdbDaemonWebUsbDeviceManager` - -A helper class that wraps the WebUSB API. - -### `BROWSER` - -```ts -public static readonly BROWSER: AdbDaemonWebUsbDeviceManager | undefined; -``` - -Gets the instance of `AdbDaemonWebUsbDeviceManager` using browser WebUSB implementation. - -May be `undefined` if the browser does not support WebUSB. - -### constructor - -```ts -public constructor(usbManager: USB); -``` - -Create a new instance of `AdbDaemonWebUsbDeviceManager` using the specified WebUSB API implementation. - -### `requestDevice` - -```ts -public async requestDevice( - filters: AdbDeviceFilter[] = [ADB_DEFAULT_DEVICE_FILTER] -): Promise -``` - -Request access to a connected device. -This is a convince method for `usb.requestDevice()`. - -The `filters` parameter must have `classCode`, `subclassCode` and `protocolCode` fields for selecting the ADB interface. It can also have `vendorId`, `productId` or `serialNumber` fields to limit the displayed device list. - -Returns an `AdbDaemonWebUsbDevice` instance, or `undefined` if the user cancelled the picker. - -### `getDevices` - -```ts -public async getDevices( - filters: AdbDeviceFilter[] = [ADB_DEFAULT_DEVICE_FILTER] -): Promise -``` - -Get all connected and authenticated devices. - -This is a convince method for `usb.getDevices()`. - -## Note on secure context - -WebUSB requires a [secure context](https://developer.mozilla.org/en-US/docs/Web/Security/Secure_Contexts) (HTTPS). - -`localhost` is considered secure, so local development works. But to access a self-hosted server running on another machine, either add a certificate, or add the domain name to the allowlist on each client machine: - -1. Open `chrome://flags/#unsafely-treat-insecure-origin-as-secure` -2. Add the protocol and domain part of your url (e.g. `http://192.168.0.100:9000`) to the input box -3. Choose `Enable` from the dropdown menu -4. Restart browser +

+ Tango +

+ +

@yume-chan/adb-daemon-webusb

+ +

+ Adb daemon transport connection for `@yume-chan/adb` using WebUSB API. +

+ +

+ + MIT License + + + GitHub release + + + npm + + + Discord + +

+ +This package is part of [Tango ADB](https://github.com/yume-chan/ya-webadb). Generally you need multiple packages to build a complete ADB client that can run on Web browsers and Node.js. Read the documentation for more information. + +## Documentation + +Check the latest documentation at https://tango-adb.github.io/docs/ + +## Sponsors + +[Become a backer](https://opencollective.com/ya-webadb) and get your image on our README on Github with a link to your site. + + + + + + + + + + + + diff --git a/libraries/adb/README.md b/libraries/adb/README.md index 443db95dc..d5150393d 100644 --- a/libraries/adb/README.md +++ b/libraries/adb/README.md @@ -1,366 +1,46 @@ -# @yume-chan/adb - -TypeScript implementation of Android Debug Bridge (ADB) protocol. - -**WARNING:** The public API is UNSTABLE. Open a GitHub discussion if you have any questions. - -- [Compatibility](#compatibility) - - [Basic usage](#basic-usage) - - [Use without bundlers](#use-without-bundlers) -- [Transport](#transport) - - [`AdbDaemonTransport`](#adbdaemontransport) - - [`AdbCredentialStore`](#adbcredentialstore) - - [`generateKey`](#generatekey) - - [`iterateKeys`](#iteratekeys) - - [`AdbAuthenticator`](#adbauthenticator) - - [`authenticate`](#authenticate) - - [`addReverseTunnel`](#addreversetunnel) - - [`AdbServerTransport`](#adbservertransport) - - [`AdbServerClient`](#adbserverclient) - - [`getVersion`](#getversion) - - [`kill`](#kill) - - [`getServerFeatures`](#getserverfeatures) - - [`getDevices`](#getdevices) - - [`AdbServerDeviceSelector`](#adbserverdeviceselector) - - [`getDeviceFeatures`](#getdevicefeatures) - - [`waitFor`](#waitfor) -- [Commands](#commands) - - [subprocess](#subprocess) - - [raw mode](#raw-mode) - - [pty mode](#pty-mode) - - [usb](#usb) - - [tcpip](#tcpip) - - [sync](#sync) - - [`lstat`](#lstat) - - [`stat`](#stat) - - [`isDirectory`](#isdirectory) - - [`opendir`](#opendir) - - [`readdir`](#readdir) -- [Useful links](#useful-links) - -## Compatibility - -Here is a list of features, their used APIs, and their compatibilities. If an optional feature is not actually used, its requirements can be ignored. - -Some features can be polyfilled to support older runtimes, but this library doesn't ship with any polyfills. - -Each transport and connection may have different requirements. - -### Basic usage - -| | Chrome | Edge | Firefox | Internet Explorer | Safari | Node.js | -| -------------------------------- | ------ | ---- | ------- | ----------------- | ------ | ------------------- | -| `@yume-chan/struct`1 | 67 | 79 | 68 | No | 14 | 8.32, 11 | -| Private class fields3 | 74 | 79 | 90 | No | 14.1 | 12.0.0 | -| _Overall_ | 74 | 79 | 90 | No | 14.1 | 16.5 | - -1 `uint64` and `string` are used. - -2 `TextEncoder` and `TextDecoder` are only available in `util` module. Need to be assigned to `globalThis`. - -3 Can be down-level compiled using Babel. - -### Use without bundlers - -| | Chrome | Edge | Firefox | Internet Explorer | Safari | Node.js | -| --------------- | ------ | ---- | ------- | ----------------- | ------ | ------- | -| Top-level await | 89 | 89 | 89 | No | 15 | 14.8 | - -## Transport - -This library doesn't tie to a specific transportation method. - -Instead, an implementation of the `AdbTransport` interface is responsible for creating ADB sockets when requested. Each implementation might have different methods to discover, connect and authenticate devices. - -### `AdbDaemonTransport` - -`AdbDaemonTransport` connects to an ADB daemon directly. - -It requires a `ReadableWritablePair>` to send and receive ADB packets to the daemon. - -Usually an implementation of `AdbDaemonConnection` will provide that along with other useful information about the device. Possible implementations includes: - -- WebUSB API -- `usb` package for Node.js -- Node.js' `net` module (for ADB over WiFi) -- Though a WebSockify wrapper (also for ADB over WiFi). - -ADB daemon requires authentication unless built in debug mode. For how ADB authentication work, see https://chensi.moe/blog/2020/09/30/webadb-part2-connection/#auth. - -Authentication requires two extra components: - -#### `AdbCredentialStore` - -An interface to generate, store and iterate ADB private keys on each runtime. (Because Node.js and Browsers have different APIs to do that) - -The `@yume-chan/adb-credential-web` package contains a `AdbWebCredentialStore` implementation using Web Crypto API for generating keys and IndexedDB for storing keys. - -##### `generateKey` - -```ts -generateKey(): ValueOrPromise -``` - -Generate and store a RSA private key with modulus length `2048` and public exponent `65537`. - -The returned `Uint8Array` is the private key in PKCS #8 format. - -##### `iterateKeys` - -```ts -iterateKeys(): Iterator | AsyncIterator -``` - -Synchronously or asynchronously iterate through all stored RSA private keys. - -Each call to `iterateKeys` must return a different iterator that iterate through all stored keys. - -#### `AdbAuthenticator` - -An `AdbAuthenticator` generates `AUTH` responses for each `AUTH` request from server. - -This package contains `AdbSignatureAuthenticator` and `AdbPublicKeyAuthenticator` classes for the two basic modes, they all uses the `AdbCredentialStore` to get the private key. - -#### `authenticate` - -```ts -static async authenticate(options: { - connection: ReadableWritablePair, - credentialStore: AdbCredentialStore, - authenticators?: AdbAuthenticator[], -}): Promise -``` - -Authenticates the connection and creates an `AdbDaemonTransport` instance that can be used by `Adb` class. - -If an authentication process failed, it's possible to call `authenticate` again on the same connection. Because every time the device receives a `CNXN` packet, it resets all internal state, and starts a new authentication process. - -#### `addReverseTunnel` - -```ts -public addReverseTunnel( - handler: AdbIncomingSocketHandler, - address?: string -): string -``` - -Adds a reverse tunnel handler to the transport. It doesn't register the reverse tunnel to the device, for that use `AdbReverseCommand#add` instead. Because the process for ADB to create a tunnel is same as calling a command, `address` can be any string that the ADB daemon might call as a command. - -### `AdbServerTransport` - -`AdbServerTransport` connects to an ADB server. Because a USB device can only be used by one process at a time, the ADB server is the process that manages all connected devices. The server proxies and multiplexes connections from ADB clients so multiple adb commands can be executed on one device at the same time. `AdbServerTransport` instances can be retrieved from `AdbServerClient` class. - -#### `AdbServerClient` - -The `AdbServerClient` class implements the client-server protocol to interact with the ADB server. It can query the list of connected devices, detect device connections and disconnections, and invoke other server commands. - -It needs an implementation of `AdbServerConnection` interface to actually connects to the ADB server using each runtime's API. - -##### `getVersion` - -```ts -public async getVersion(): Promise; -``` - -Get the version number of the ADB server. This version is not related to the ADB server-daemon protocol version nor device Android version, it increases when a breaking change is introduced into the client-server protocol. - -##### `kill` - -```ts -public async kill(): Promise; -``` - -Kill the ADB server, for example if you want to connect to the ADB daemon directly over USB. - -##### `getServerFeatures` - -```ts -public async getServerFeatures(): Promise; -``` - -Get the list of ADB features supported by the server. - -Generally it's not that useful because most ADB commands only cares about what features the device supports. - -##### `getDevices` - -```ts -public async getDevices(): Promise; -``` - -Get the list of connected devices. - -The returned `AdbServerTransport` instance can be supplied to `new Adb` to operate on that device. - -##### `AdbServerDeviceSelector` - -Some commands target a specific device. `AdbServerDeviceSelector` chooses a device from the list of connected devices. - -It can be one of: - -- `undefined`: any one device, will throw an error if there are multiple devices connected. Same as no argument are given to `adb` command. -- `{ serial: string }`: a device with the given serial number. Note that multiple devices can have the same serial number (if the manufacturer is lazy), usually it's enough to identify a device. Same as the `-s` argument for the `adb` command. -- `{ transportId: number }`: a device with the given transport ID. The transport ID is from the order devices connect. It can be obtained from `getDevices` method. Same as the `-t` argument for the `adb` command. -- `{ usb: true }`: any one USB device, will throw an error if there are multiple devices connected via USB. Same as the `-d` argument for the `adb` command. -- `{ emulator: true }`: any one TCP device (including emulators and devices connected via ADB over WiFi), will throw an error if there are multiple TCP devices. Same as the `-e` argument for the `adb` command. Same as the `-e` argument for the `adb` command. - -The selector will be sent to ADB server and resolved there. - -##### `getDeviceFeatures` - -```ts -public async getDeviceFeatures( - device: AdbServerDeviceSelector -): Promise -``` - -Gets the list of ADB features supported by the device. `Adb` class requires this information to choose the correct commands to use. - -##### `waitFor` - -```ts -public async waitFor( - device: AdbServerDeviceSelector, - state: "device" | "disconnect", - signal?: AbortSignal -): Promise -``` - -Wait for a specific device to be connected or disconnected. The `AdbServerTransport` instance uses this method to detect device disconnects. - -## Commands - -### subprocess - -ADB has two subprocess invocation modes and two data protocols (4 combinations). The Shell protocol was added in Android 8 and can be identified by the `shell_v2` feature flag. - -#### raw mode - -In raw mode, Shell protocol transfers `stdout` and `stderr` separately, and supports returning exit code. - -| | Legacy protocol | Shell Protocol | -| --------------------------- | --------------------------- | ---------------------------- | -| Feature flag | - | `shell_v2` | -| Implementation | `AdbNoneSubprocessProtocol` | `AdbShellSubprocessProtocol` | -| Splitting stdout and stderr | No | Yes | -| Returning exit code | No | Yes | - -Use `spawn` method to create a subprocess in raw mode. - -#### pty mode - -In PTY mode, the subprocess has a pseudo-terminal, so it can send special control sequences like clear screen and set cursor position. The two protocols both send data in `stdout`, but Shell Protocol also supports resizing the terminal from client and returning the exit code. - -| | Legacy protocol | Shell Protocol | -| --------------------------- | --------------------------- | ---------------------------- | -| Feature flag | - | `shell_v2` | -| Implementation | `AdbNoneSubprocessProtocol` | `AdbShellSubprocessProtocol` | -| Resizing window | No | Yes | -| Splitting stdout and stderr | No | No | -| Returning exit code | No | Yes | - -Use `shell` method to create a subprocess in PTY mode. - -### usb - -Disable ADB over WiFi. - -### tcpip - -Enable ADB over WiFi. - -### sync - -Sync protocol is a sub-protocol of the server-daemon protocol, it allows interacting with the device's filesystem. - -```ts -public async sync(): Promise; -``` - -Creates an `AdbSync` client. The client can send multiple command in sequence, and multiple clients can be created to send commands in parallel. - -#### `lstat` - -```ts -public async lstat(path: string): Promise; -``` - -Gets the information of a file or folder. If `path` points to a symbolic link, the returned information is about the link itself. - -This uses the `STAT` or `LST2` (when supported) sync commands, notice that despite the name of `STAT`, it doesn't resolve symbolic links. - -Same as the [`lstat`](https://linux.die.net/man/2/lstat) system call in Linux. - -#### `stat` - -```ts -public async stat(path: string): Promise; -``` - -Gets the information of a file or folder. If `path` points to a symbolic link, it will be resolved and the returned information is about the target. - -Uses the `STA2` sync command, which requires the `stat_v2` feature flag. Will throw an error if device doesn't support that. - -Same as the `stat` system call in Linux. - -#### `isDirectory` - -```ts -public async isDirectory(path: string): Promise -``` - -Checks if `path` is a directory, or a symbolic link to a directory. - -This uses `lstat` internally, thus works on all Android versions. - -#### `opendir` - -```ts -public opendir(path: string): AsyncGenerator; -``` - -Returns an async generator that yields the content of a folder. - -Example: - -```ts -for await (const entry of this.opendir(path)) { - console.log(entry.name, entry.size); -} -``` - -#### `readdir` - -```ts -public async readdir(path: string): Promise -``` - -Collects the result of `opendir` into an array. Useful if you want to send other commands using the same `AdbSync` instance while iterating the folder. - -#### `read` - -```ts -public read(filename: string): ReadableStream -``` - -Reads the content of a file on device. - -#### `write` - -```ts -public async write(options: { - filename: string; - file: ReadableStream>; - type?: LinuxFileType; - permission?: number; - mtime?: number; - dryRun?: boolean; -}) -``` - -Writes a file on device. If the file name already exists, it will be overwritten. - -## Useful links - -- [ADB protocol overview](https://android.googlesource.com/platform/packages/modules/adb/+/2fd69306184634c6d90db3ed3be5349e71dcc471/OVERVIEW.TXT) -- [ADB commands](https://android.googlesource.com/platform/packages/modules/adb/+/2fd69306184634c6d90db3ed3be5349e71dcc471/SERVICES.TXT#145) +

+ Tango +

+ +

@yume-chan/adb

+ +

+ TypeScript implementation of Android Debug Bridge (ADB) protocol. +

+ +

+ + MIT License + + + GitHub release + + + npm + + + Discord + +

+ +This package is part of [Tango ADB](https://github.com/yume-chan/ya-webadb). Generally you need multiple packages to build a complete ADB client that can run on Web browsers and Node.js. Read the documentation for more information. + +## Documentation + +Check the latest documentation at https://tango-adb.github.io/docs/ + +## Sponsors + +[Become a backer](https://opencollective.com/ya-webadb) and get your image on our README on Github with a link to your site. + + + + + + + + + + + + diff --git a/libraries/scrcpy-decoder-tinyh264/README.md b/libraries/scrcpy-decoder-tinyh264/README.md index dce9ffc8b..79936055c 100644 --- a/libraries/scrcpy-decoder-tinyh264/README.md +++ b/libraries/scrcpy-decoder-tinyh264/README.md @@ -1,6 +1,6 @@ # @yume-chan/scrcpy-decoder-tinyh264 -Decode and render H.264 streams using TinyH264, the old Android H.264 software decoder (now deprecated and removed), compiled into WebAssembly, and wrapped in Web Worker to prevent blocking the main thread. +Decode and render H.264 streams using TinyH264, the old Android H.264 software decoder (now deprecated and removed), compiled into WebAssembly and wrapped in a Web Worker. The video stream will be decoded into YUV frames on CPU, then converted to RGB using a WebGL shader (using GPU). It's slow, but works on most browsers.