### Project Setup and Execution Commands Source: https://tangoadb.dev/tango/custom-transport/server-client Commands to clone the repository, install dependencies via PNPM, and start the server and client components. ```bash git clone https://github.com/tango-adb/example-server-client.git cd example-server-client pnpm install # To run the server: cd server npm start # To run the client: cd client npm start ``` -------------------------------- ### Start Server with @yume-chan/adb-scrcpy (Default Path) Source: https://tangoadb.dev/scrcpy/start-server This example shows how to start the scrcpy server using the @yume-chan/adb-scrcpy library with the default server path. The `AdbScrcpyClient.start()` method takes an Adb instance, the server path, and options to configure the server. It handles port forwarding, server launch, and connection establishment. ```typescript import { AdbScrcpyClient, AdbScrcpyOptions2_1 } from "@yume-chan/adb-scrcpy"; import { DefaultServerPath } from "@yume-chan/scrcpy"; const client = await AdbScrcpyClient.start( adb, DefaultServerPath, new AdbScrcpyOptions2_1({ // options }), ); ``` ```typescript import type { Adb } from "@yume-chan/adb"; import { AdbScrcpyClient, AdbScrcpyOptions2_1 } from "@yume-chan/adb-scrcpy"; import { DefaultServerPath } from "@yume-chan/scrcpy"; declare const adb: Adb; const client: AdbScrcpyClient = await AdbScrcpyClient.start( adb, DefaultServerPath, new AdbScrcpyOptions2_1({ // options }), ); ``` -------------------------------- ### Start Server with @yume-chan/adb-scrcpy (Custom Path) Source: https://tangoadb.dev/scrcpy/start-server This example demonstrates starting the scrcpy server using a custom path with the @yume-chan/adb-scrcpy library. The `AdbScrcpyClient.start()` method allows specifying a custom path to the server JAR file. This is useful if the server is not located at the default path on the device. ```typescript import { AdbScrcpyClient, AdbScrcpyOptions2_1 } from "@yume-chan/adb-scrcpy"; const client = await AdbScrcpyClient.start( adb, "/data/local/tmp/scrcpy-server.jar", new AdbScrcpyOptions2_1({ // options }), ); ``` ```typescript import type { Adb } from "@yume-chan/adb"; import { AdbScrcpyClient, AdbScrcpyOptions2_1 } from "@yume-chan/adb-scrcpy"; declare const adb: Adb; const client: AdbScrcpyClient = await AdbScrcpyClient.start( adb, "/data/local/tmp/scrcpy-server.jar", new AdbScrcpyOptions2_1({ // options }), ); ``` -------------------------------- ### Install APK using PackageManager (JavaScript) Source: https://tangoadb.dev/api/bin/pm/install Example of how to install an APK file using the PackageManager class in JavaScript. It demonstrates initializing the PackageManager with an ADB instance and calling the install method with the path to the APK. ```javascript import { PackageManager } from "@yume-chan/android-bin"; const pm = new PackageManager(adb); await pm.install(["/path/to/app.apk"]); ``` -------------------------------- ### Install @yume-chan/adb-credential-web with Bun Source: https://tangoadb.dev/tango/daemon/credential-store Installs the ADB credential web package using Bun. Bun is a fast all-in-one JavaScript runtime, bundler, transpiler, and package manager. ```bash bun add @yume-chan/adb-credential-web ``` -------------------------------- ### Install Core Packages with Bun Source: https://tangoadb.dev/1.0.0 Installs the two core Tango ADB packages, `@yume-chan/adb` and `@yume-chan/stream-extra`, using Bun. This command is used to add the essential ADB client and stream utility packages to your project for cross-platform ADB operations. ```bash bun add @yume-chan/adb @yume-chan/stream-extra ``` -------------------------------- ### Install @yume-chan/adb-credential-web with npm Source: https://tangoadb.dev/tango/daemon/credential-store Installs the ADB credential web package using npm. This is the standard package manager for Node.js and the default for many web development projects. ```bash npm i @yume-chan/adb-credential-web ``` -------------------------------- ### Install Tango ADB Core Packages (Bun) Source: https://tangoadb.dev/2.0.0 Installs the core Tango ADB client implementation and stream utilities using Bun. These packages are essential for using Tango ADB in various environments. ```bash bun add @yume-chan/adb @yume-chan/stream-extra ``` -------------------------------- ### Install Core Packages with npm Source: https://tangoadb.dev/1.0.0 Installs the two core Tango ADB packages, `@yume-chan/adb` and `@yume-chan/stream-extra`, using npm. These packages provide the platform-independent ADB client implementation and utilities for Web Streams API, respectively. ```bash npm i @yume-chan/adb @yume-chan/stream-extra ``` -------------------------------- ### Automate Scrcpy Server Download with npm postinstall Script Source: https://tangoadb.dev/scrcpy/prepare-server Configure the package.json file to automatically run the fetch-scrcpy-server script after installation using the 'postinstall' hook. This ensures the server binary is downloaded every time dependencies are installed. ```json { "name": "...", "devDependencies": { "@yume-chan/fetch-scrcpy-server": "^0.0.24" }, "scripts": { "postinstall": "fetch-scrcpy-server 2.1" } } ``` -------------------------------- ### Install WebUSB TypeScript definitions Source: https://tangoadb.dev/tango/daemon/usb Installs the necessary type definitions for the WebUSB API, required when using TypeScript with PNPM. ```shell pnpm add --save-dev @types/w3c-web-usb ``` -------------------------------- ### Install Core Packages with pnpm Source: https://tangoadb.dev/1.0.0 Installs the two core Tango ADB packages, `@yume-chan/adb` and `@yume-chan/stream-extra`, using pnpm. This command ensures that the necessary ADB client and stream utility packages are available for your project. ```bash pnpm add @yume-chan/adb @yume-chan/stream-extra ``` -------------------------------- ### Install Tango ADB Core Packages (npm) Source: https://tangoadb.dev/2.0.0 Installs the core Tango ADB client implementation and stream utilities using npm. These packages are essential for using Tango ADB in various environments. ```bash npm i @yume-chan/adb @yume-chan/stream-extra ``` -------------------------------- ### Install @yume-chan/adb-credential-web with pnpm Source: https://tangoadb.dev/tango/daemon/credential-store Installs the ADB credential web package using pnpm. pnpm is a performant, disk-space-efficient package manager that enforces a content-addressable filesystem. ```bash pnpm add @yume-chan/adb-credential-web ``` -------------------------------- ### Install Mediabunny and Scrcpy dependencies Source: https://tangoadb.dev/scrcpy/video/record Commands to install the required packages for Scrcpy stream processing and video muxing using various package managers. ```npm npm install @yume-chan/scrcpy @yume-chan/stream-extra mediabunny ``` ```yarn yarn add @yume-chan/scrcpy @yume-chan/stream-extra mediabunny ``` ```pnpm pnpm add @yume-chan/scrcpy @yume-chan/stream-extra mediabunny ``` ```bun bun add @yume-chan/scrcpy @yume-chan/stream-extra mediabunny ``` -------------------------------- ### Install @yume-chan/fetch-scrcpy-server with npm, yarn, pnpm, or bun Source: https://tangoadb.dev/scrcpy/prepare-server Install the @yume-chan/fetch-scrcpy-server package as a development dependency using different package managers. This package provides a script to download the scrcpy server binary. ```npm npm i -D @yume-chan/fetch-scrcpy-server ``` ```yarn yarn add --dev @yume-chan/fetch-scrcpy-server ``` ```pnpm pnpm add -D @yume-chan/fetch-scrcpy-server ``` ```bun bun add --dev @yume-chan/fetch-scrcpy-server ``` -------------------------------- ### Equivalent ADB Command for APK Installation Source: https://tangoadb.dev/api/bin/pm/install Shows the equivalent ADB shell command to install an APK file. This command can be executed directly from the command line and achieves the same result as the PackageManager.install method. ```bash adb shell pm install /path/to/app.apk ``` -------------------------------- ### Start Server with ADB Command Source: https://tangoadb.dev/scrcpy/start-server This ADB command starts the scrcpy server JAR file on the device. It requires the server JAR to be present at the specified path. The command executes the Java process with the server's main class and version. ```bash adb shell CLASSPATH=/data/local/tmp/scrcpy-server.jar app_process / com.genymobile.scrcpy.Server 2.1 ``` -------------------------------- ### Install Core Packages with Yarn Source: https://tangoadb.dev/1.0.0 Installs the two core Tango ADB packages, `@yume-chan/adb` and `@yume-chan/stream-extra`, using Yarn. These packages are essential for using Tango's ADB client functionalities in web browsers and Node.js environments. ```bash yarn add @yume-chan/adb @yume-chan/stream-extra ``` -------------------------------- ### Equivalent ADB Command for Installation Source: https://tangoadb.dev/api/bin/pm/install-stream Provides the equivalent ADB command for installing an APK. This serves as a reference for users familiar with ADB commands and helps understand the underlying operation performed by installStream. ```bash adb install /path/to/app.apk ``` -------------------------------- ### Install APK using installStream in JavaScript Source: https://tangoadb.dev/api/bin/pm/install-stream Demonstrates how to install an APK from a file stream using the installStream method in JavaScript. It requires an Adb instance and a File object with size and stream properties. ```javascript import { PackageManager } from "@yume-chan/android-bin"; const pm = new PackageManager(adb); await pm.installStream(file.size, file.stream()); ``` -------------------------------- ### Generate Server Command Line Arguments with @yume-chan/scrcpy Source: https://tangoadb.dev/scrcpy/start-server This snippet demonstrates how to use the @yume-chan/scrcpy library to generate command-line arguments for starting the server. The `ScrcpyOptions2_1` class is used to configure options, and the `serialize()` method outputs the arguments as a string array. This library focuses on message serialization and deserialization, not server startup. ```typescript import { ScrcpyOptions2_1 } from "@yume-chan/scrcpy"; const options = ScrcpyOptions2_1({ // options }); const commandLineArguments = options.serialize(); ``` ```typescript import { ScrcpyOptions2_1 } from "@yume-chan/scrcpy"; const options = ScrcpyOptions2_1({ // options }); const commandLineArguments: string[] = options.serialize(); ``` -------------------------------- ### Install 'usb' package (Yarn) Source: https://tangoadb.dev/tango/daemon/usb/device-manager Installs the 'usb' package using Yarn, a popular JavaScript package manager. This command is equivalent to the npm installation for Node.js environments. ```bash yarn add usb ``` -------------------------------- ### Install 'usb' package (Bun) Source: https://tangoadb.dev/tango/daemon/usb/device-manager Installs the 'usb' package using Bun, a fast all-in-one JavaScript runtime. This command adds the necessary package for WebUSB support in Node.js. ```bash bun add usb ``` -------------------------------- ### Install @yume-chan/adb-credential-web with Yarn Source: https://tangoadb.dev/tango/daemon/credential-store Installs the ADB credential web package using Yarn. Yarn is an alternative package manager for JavaScript that offers performance and security improvements. ```bash yarn add @yume-chan/adb-credential-web ``` -------------------------------- ### ScrcpyOptions.serialize Source: https://tangoadb.dev/scrcpy/start-server Serializes Scrcpy configuration options into command-line arguments for manual server execution. ```APIDOC ## POST ScrcpyOptions#serialize ### Description Generates the command-line arguments required to start the Scrcpy server manually via `app_process`. ### Method Method ### Parameters #### Request Body - **options** (Object) - Required - Configuration settings for the Scrcpy session. ### Request Example ```javascript const options = ScrcpyOptions2_1({ /* options */ }); const args = options.serialize(); ``` ### Response #### Success Response (200) - **args** (string[]) - An array of command-line arguments to be passed to the server process. ``` -------------------------------- ### Install APK using PackageManager (TypeScript) Source: https://tangoadb.dev/api/bin/pm/install Example of how to install an APK file using the PackageManager class in TypeScript. This version includes type imports for Adb and PackageManager, ensuring type safety during development. ```typescript import type { Adb } from "@yume-chan/adb"; import { PackageManager } from "@yume-chan/android-bin"; declare const adb: Adb; const pm = new PackageManager(adb); await pm.install(["/path/to/app.apk"]); ``` -------------------------------- ### Spawn Processes with Commands Source: https://tangoadb.dev/api/adb/subprocess/shell-protocol Demonstrates how to execute shell commands using either a single string or an array of arguments. ```JavaScript await adb.subprocess.shellProtocol.spawn("ls -al /"); // same as await adb.subprocess.shellProtocol.spawn(["ls", "-al", "/"]); ``` ```TypeScript import type { Adb } from "@yume-chan/adb"; import { TextDecoderStream } from "@yume-chan/stream-extra"; declare const adb: Adb; await adb.subprocess.shellProtocol!.spawn("ls -al /"); // same as await adb.subprocess.shellProtocol!.spawn(["ls", "-al", "/"]); ``` -------------------------------- ### Get Connected Devices (JavaScript) Source: https://tangoadb.dev/tango/server/devices Example of how to call the `getDevices` method using JavaScript and handle the response. It retrieves all connected devices and selects the first one if available. ```javascript const devices = await client.getDevices(); if (devices.length === 0) { alert("No device connected"); return; } const device = devices[0]; ``` -------------------------------- ### Get Connected Devices (TypeScript) Source: https://tangoadb.dev/tango/server/devices Example of how to call the `getDevices` method using TypeScript, including type imports. It retrieves all connected devices and selects the first one if available. ```typescript import type { AdbServerClient } from "@yume-chan/adb"; const devices: AdbServerClient.Device[] = await client.getDevices(); if (devices.length === 0) { alert("No device connected"); return; } const device = devices[0]; ``` -------------------------------- ### Spawning Processes with Command Array (JavaScript) Source: https://tangoadb.dev/api/adb/subprocess/none-protocol Demonstrates how to spawn an ADB process using the AdbNoneProtocolSubprocessService. It shows two equivalent ways to specify the command: as a single string or as an array of strings. ```javascript await adb.subprocess.noneProtocol.spawn("ls -al /"); // same as await adb.subprocess.noneProtocol.spawn(["ls", "-al", "/"]); ``` -------------------------------- ### Spawning Process with AbortSignal (JavaScript) Source: https://tangoadb.dev/api/adb/subprocess/none-protocol Shows how to spawn an ADB process and provide an AbortSignal to terminate it. The example sets a timeout to abort the process after 1 second, demonstrating graceful termination. ```javascript const abortController = new AbortController(); setTimeout(() => abortController.abort(), 1000); const process = await adb.subprocess.noneProtocol.spawn("logcat", abortController.signal); ``` -------------------------------- ### Install Tango ADB Core Packages (pnpm) Source: https://tangoadb.dev/2.0.0 Installs the core Tango ADB client implementation and stream utilities using pnpm. These packages are essential for using Tango ADB in various environments. ```bash pnpm add @yume-chan/adb @yume-chan/stream-extra ``` -------------------------------- ### Initialize Scrcpy Options Source: https://tangoadb.dev/scrcpy/options Demonstrates how to instantiate a version-specific options class from @yume-chan/scrcpy to configure server parameters. ```TypeScript import { ScrcpyOptions2_2 } from "@yume-chan/scrcpy"; const options = new ScrcpyOptions2_2({ videoSource: "camera", // ... }); ``` -------------------------------- ### Install Tango ADB Core Packages (Yarn) Source: https://tangoadb.dev/2.0.0 Installs the core Tango ADB client implementation and stream utilities using Yarn. These packages are essential for using Tango ADB in various environments. ```bash yarn add @yume-chan/adb @yume-chan/stream-extra ``` -------------------------------- ### Execute commands with spawnWait and spawnWaitText Source: https://tangoadb.dev/api/adb/subprocess/shell-protocol Executes a command, waits for completion, and returns the output buffered in memory. spawnWait returns binary data as Uint8Array, while spawnWaitText returns decoded string output. ```JavaScript const { exitCode, stdout, stderr } = await adb.subprocess.shellProtocol.spawnWait("ls -al /"); const { exitCode: textExit, stdout: textStdout, stderr: textStderr } = await adb.subprocess.shellProtocol.spawnWaitText("ls -al /"); ``` ```TypeScript import type { Adb } from "@yume-chan/adb"; declare const adb: Adb; const { exitCode, stdout, stderr } = await adb.subprocess.shellProtocol!.spawnWait("ls -al /"); const { exitCode: textExit, stdout: textStdout, stderr: textStderr } = await adb.subprocess.shellProtocol!.spawnWaitText("ls -al /"); ``` -------------------------------- ### Initialize Adb Instance on Server Source: https://tangoadb.dev/tango/custom-transport/server-client/adb Demonstrates how to create an Adb instance on the server using AdbDaemonTransport. This is useful for managing ADB connections and executing commands from the server-side. It requires the 'adb' and 'adb-daemon-transport' packages. ```typescript import { Adb, AdbDaemonTransport } from "@yume-chan/adb"; const devices = new Map(); // ... const connection = await device.connect(); const transport = await AdbDaemonTransport.authenticate({ serial, connection, credentialStore: CredentialStore, }); const adb = new Adb(transport); devices.set(serial, adb); // ... ``` ```javascript import { Adb, AdbDaemonTransport } from "@yume-chan/adb"; const devices = new Map(); // ... const connection = await device.connect(); const transport = await AdbDaemonTransport.authenticate({ serial, connection, credentialStore: CredentialStore, }); const adb = new Adb(transport); devices.set(serial, adb); // ... ``` -------------------------------- ### Log Device State (JavaScript) Source: https://tangoadb.dev/tango/server/devices Example of how to access and log the connection state of a retrieved ADB device object in JavaScript. ```javascript console.log(device.state); // "unauthorized" | "offline" | "device" export {}; ``` -------------------------------- ### Initialize WebCodecs Video Decoder Source: https://tangoadb.dev/scrcpy/video/web-codecs Demonstrates how to instantiate a WebCodecsVideoDecoder by providing the required codec ID and a pre-configured video renderer. ```typescript import { WebCodecsVideoDecoder } from "@yume-chan/scrcpy-decoder-webcodecs"; const decoder = new WebCodecsVideoDecoder({ codec: videoMetadata.codec, renderer: renderer, }); ``` -------------------------------- ### JavaScript Example for Getting File Stat Source: https://tangoadb.dev/api/adb/sync/stat Demonstrates how to use the `stat` method from the `AdbSync` class to retrieve file information. This asynchronous operation fetches the stat object for a given path and logs it to the console. It requires an initialized `sync` object. ```javascript const stat = await sync.stat("/sdcard/Download"); console.log(stat); ``` -------------------------------- ### Execute ADB Commands Source: https://tangoadb.dev/tango/custom-transport/usage Demonstrates how to initialize the Adb client with a transport and perform a property lookup. Supports both JavaScript and TypeScript implementations. ```javascript import { Adb } from "@yume-chan/adb"; const adb = new Adb(transport); console.log(await adb.getProp("ro.build.version.sdk")); ``` ```typescript import type { AdbTransport } from "@yume-chan/adb"; import { Adb } from "@yume-chan/adb"; declare const transport: AdbTransport; const adb = new Adb(transport); console.log(await adb.getProp("ro.build.version.sdk")); ``` -------------------------------- ### Initialize Adb-Scrcpy Options Source: https://tangoadb.dev/scrcpy/options Demonstrates how to instantiate an Adb-specific options class from @yume-chan/adb-scrcpy, which includes support for client-side options like custom spawners. ```TypeScript import { AdbScrcpyOptions2_1 } from "@yume-chan/adb-scrcpy"; const options = new AdbScrcpyOptions2_1({ videoSource: "camera", // ... }); ``` -------------------------------- ### Log Device State (TypeScript) Source: https://tangoadb.dev/tango/server/devices Example of how to access and log the connection state of a retrieved ADB device object in TypeScript, including type annotations. ```typescript import type { AdbServerClient } from "@yume-chan/adb"; declare const device: AdbServerClient.Device; console.log(device.state); // "unauthorized" | "offline" | "device" ``` -------------------------------- ### Enqueue Typed Data to a ReadableStream Later in TypeScript Source: https://tangoadb.dev/tango/web-stream Shows an example in TypeScript where a `ReadableStream` is created, and data is enqueued asynchronously. The `controller` is captured in the `start` method, and values are added after a delay. ```typescript let controller: ReadableStreamDefaultController; const stream: ReadableStream = new ReadableStream({ start(_controller) { controller = _controller; }, }); setTimeout(() => { controller.enqueue(1); controller.enqueue(2); controller.enqueue(3); controller.close(); }, 1000); ``` -------------------------------- ### Traditional ADB Pull Command Source: https://tangoadb.dev/2.0.0 Demonstrates the traditional method of using the Google ADB executable to pull files from an Android device. This requires the ADB executable to be installed and accessible in the system's PATH. ```bash adb pull /sdcard/DCIM/Camera . ``` -------------------------------- ### Spawning Processes with Command Array (TypeScript) Source: https://tangoadb.dev/api/adb/subprocess/none-protocol Illustrates spawning an ADB process with the AdbNoneProtocolSubprocessService in TypeScript. It highlights that the command can be provided either as a single string or as an array of strings for flexibility. ```typescript import type { Adb } from "@yume-chan/adb"; import { TextDecoderStream } from "@yume-chan/stream-extra"; declare const adb: Adb; await adb.subprocess.noneProtocol.spawn("ls -al /"); // same as await adb.subprocess.noneProtocol.spawn(["ls", "-al", "/"]); ``` -------------------------------- ### Handle Video Stream from AdbScrcpyClient Source: https://tangoadb.dev/scrcpy/start-server This code shows how to access and process the video stream from an AdbScrcpyClient if the `video: true` option was specified. It retrieves video metadata, including the codec, and pipes the video packet stream for further processing. This example is available in both JavaScript and TypeScript. ```javascript import { WritableStream } from "@yume-chan/stream-extra"; if (client.videoStream) { const { metadata: videoMetadata, stream: videoPacketStream } = await client.videoStream; console.log(videoMetadata.codec); void videoPacketStream.pipeTo( new WritableStream({ write(chunk) { console.log(chunk.type); }, }), ); } ``` ```typescript import type { AdbScrcpyClient } from "@yume-chan/adb-scrcpy"; import { WritableStream } from "@yume-chan/stream-extra"; declare const client: AdbScrcpyClient; if (client.videoStream) { const { metadata: videoMetadata, stream: videoPacketStream } = await client.videoStream; console.log(videoMetadata.codec); void videoPacketStream.pipeTo( new WritableStream({ write(chunk) { console.log(chunk.type); }, }), ); } ``` -------------------------------- ### PackageManager Install Options Interface (TypeScript) Source: https://tangoadb.dev/api/bin/pm/install Defines the interface for options available when installing an APK file using the PackageManager. These options control various aspects of the installation process, such as skipping existing installations, allowing downgrades, and managing permissions. ```typescript export interface PackageManagerInstallOptions { /** * `-R` */ skipExisting: boolean; /** * `-i` */ installerPackageName: string; /** * `-t` */ allowTest: boolean; /** * `-f` */ internalStorage: boolean; /** * `-d` */ requestDowngrade: boolean; /** * `-g` */ grantRuntimePermissions: boolean; /** * `--restrict-permissions` */ restrictPermissions: boolean; /** * `--dont-kill` */ doNotKill: boolean; /** * `--originating-uri` */ originatingUri: string; /** * `--referrer` */ refererUri: string; /** * `-p` */ inheritFrom: string; /** * `--pkg` */ packageName: string; /** * `--abi` */ abi: string; /** * `--ephemeral`/`--instant`/`--instantapp` */ instantApp: boolean; /** * `--full` */ full: boolean; /** * `--preload` */ preload: boolean; /** * `--user` */ user: SingleUserOrAll; /** * `--install-location` */ installLocation: PackageManagerInstallLocation; /** * `--install-reason` */ installReason: PackageManagerInstallReason; /** * `--force-uuid` */ forceUuid: string; /** * `--apex` */ apex: boolean; /** * `--force-non-staged` */ forceNonStaged: boolean; /** * `--staged` */ staged: boolean; /** * `--force-queryable` */ forceQueryable: boolean; /** * `--enable-rollback` */ enableRollback: boolean; /** * `--staged-ready-timeout` */ stagedReadyTimeout: number; /** * `--skip-verification` */ skipVerification: boolean; /** * `--bypass-low-target-sdk-block` */ bypassLowTargetSdkBlock: boolean; } declare class PackageManager { async install( apks: string[], options?: Partial ): Promise; } ``` -------------------------------- ### PackageManagerInstallOptions Interface Definition Source: https://tangoadb.dev/api/bin/pm/install-stream Defines the options available for installing an Android package. These options correspond to various ADB install command flags, allowing fine-grained control over the installation process, such as skipping existing installations, allowing downgrades, and managing permissions. ```typescript export interface PackageManagerInstallOptions { /** * `-R` */ skipExisting: boolean; /** * `-i` */ installerPackageName: string; /** * `-t` */ allowTest: boolean; /** * `-f` */ internalStorage: boolean; /** * `-d` */ requestDowngrade: boolean; /** * `-g` */ grantRuntimePermissions: boolean; /** * `--restrict-permissions` */ restrictPermissions: boolean; /** * `--dont-kill` */ doNotKill: boolean; /** * `--originating-uri` */ originatingUri: string; /** * `--referrer` */ refererUri: string; /** * `-p` */ inheritFrom: string; /** * `--pkg` */ packageName: string; /** * `--abi` */ abi: string; /** * `--ephemeral`/`--instant`/`--instantapp` */ instantApp: boolean; /** * `--full` */ full: boolean; /** * `--preload` */ preload: boolean; /** * `--user` */ user: SingleUserOrAll; /** * `--install-location` */ installLocation: PackageManagerInstallLocation; /** * `--install-reason` */ installReason: PackageManagerInstallReason; /** * `--force-uuid` */ forceUuid: string; /** * `--apex` */ apex: boolean; /** * `--force-non-staged` */ forceNonStaged: boolean; /** * `--staged` */ staged: boolean; /** * `--force-queryable` */ forceQueryable: boolean; /** * `--enable-rollback` */ enableRollback: boolean; /** * `--staged-ready-timeout` */ stagedReadyTimeout: number; /** * `--skip-verification` */ skipVerification: boolean; /** * `--bypass-low-target-sdk-block` */ bypassLowTargetSdkBlock: boolean; } ``` -------------------------------- ### POST /package_manager/install Source: https://tangoadb.dev/api/bin/pm/install Installs one or more APK files onto the device's filesystem. If the APK file is not on the device yet, installStream can upload and install it in parallel. ```APIDOC ## POST /package_manager/install ### Description Installs one or more APK files onto the device's filesystem. This method supports uploading and installing APKs in parallel if they are not already present on the device. ### Method POST ### Endpoint /package_manager/install ### Parameters #### Query Parameters - **apks** (string[]) - Required - An array of paths to the APK files to install. - **options** (PackageManagerInstallOptions) - Optional - An object containing various options to customize the installation process. #### Request Body ```json { "apks": [ "/path/to/app.apk" ], "options": { "skipExisting": false, "installerPackageName": "string", "allowTest": false, "internalStorage": false, "requestDowngrade": false, "grantRuntimePermissions": false, "restrictPermissions": false, "doNotKill": false, "originatingUri": "string", "refererUri": "string", "inheritFrom": "string", "packageName": "string", "abi": "string", "instantApp": false, "full": false, "preload": false, "user": "string | number | Array", "installLocation": "string", "installReason": "string", "forceUuid": "string", "apex": false, "forceNonStaged": false, "staged": false, "forceQueryable": false, "enableRollback": false, "stagedReadyTimeout": 0, "skipVerification": false, "bypassLowTargetSdkBlock": false } } ``` ### Request Example ```json { "apks": [ "/sdcard/Download/my_app.apk" ], "options": { "grantRuntimePermissions": true, "skipExisting": true } } ``` ### Response #### Success Response (200) - **string** - A success message or status indicating the result of the installation. #### Response Example ```json "Success" ``` ``` -------------------------------- ### Initialize MediaBunny Output and Video Track Source: https://tangoadb.dev/scrcpy/video/record This snippet sets up the MediaBunny output stream for recording video. It initializes an Output object with MKV format and a BufferTarget, then creates an EncodedVideoPacketSource for the specified video codec and adds it to the muxer. Finally, it starts the muxer. ```typescript const muxer = new Output({ format: new MkvOutputFormat(), target: new BufferTarget(), }); const videoTrack = new EncodedVideoPacketSource(VideoCodecMap[videoCodec]); muxer.addVideoTrack(videoTrack); await muxer.start(); ``` -------------------------------- ### Writing to Process Stdin (JavaScript) Source: https://tangoadb.dev/api/adb/subprocess/none-protocol Illustrates writing data to the stdin of an ADB process using the `cat` command. The example sends 'Hello World!' to the process's stdin and then reads the output, demonstrating bidirectional communication. ```javascript import { encodeUtf8 } from "@yume-chan/adb"; import { TextDecoderStream } from "@yume-chan/stream-extra"; // `cat` will output whatever is written to its `stdin` const process = await adb.subprocess.noneProtocol.spawn("cat"); const writer = process.stdin.getWriter(); await writer.write(encodeUtf8("Hello World!")); for await (const chunk of process.output.pipeThrough(new TextDecoderStream())) { console.log(chunk); // "Hello World!" await process.exit(); } ``` -------------------------------- ### Extract H.265 Configuration Parameters Source: https://tangoadb.dev/scrcpy/video/record Demonstrates how to iterate through a video packet stream to identify configuration packets and extract the Video Parameter Set (VPS), Sequence Parameter Set (SPS), and Picture Parameter Set (PPS) using h265SearchConfiguration. ```typescript import { h265SearchConfiguration } from "@yume-chan/scrcpy"; for await (const packet of videoPacketStream) { if (packet.type === "configuration") { const { videoParameterSet, sequenceParameterSet, pictureParameterSet } = h265SearchConfiguration(packet.data); console.log(videoParameterSet, sequenceParameterSet, pictureParameterSet); } } ``` -------------------------------- ### Write Symbolic Link to Device Source: https://tangoadb.dev/api/adb/sync/write Shows how to create a symbolic link on the device by setting the file type to LinuxFileType.SymbolicLink. ```typescript import { encodeUtf8 } from "@yume-chan/adb"; await sync.write({ filename: "/sdcard/Download/hello.txt", file: new ReadableStream({ start(controller) { controller.enqueue(encodeUtf8("/sdcard/Download/target.txt")); controller.close(); }, }), type: LinuxFileType.SymbolicLink, }); ``` -------------------------------- ### Install WebCodecs Decoder Package Source: https://tangoadb.dev/scrcpy/video/web-codecs Commands to install the @yume-chan/scrcpy-decoder-webcodecs package using various JavaScript package managers. ```bash npm install @yume-chan/scrcpy-decoder-webcodecs ``` ```bash yarn add @yume-chan/scrcpy-decoder-webcodecs ``` ```bash pnpm add @yume-chan/scrcpy-decoder-webcodecs ``` ```bash bun add @yume-chan/scrcpy-decoder-webcodecs ``` -------------------------------- ### Install TinyH264 Decoder package Source: https://tangoadb.dev/scrcpy/video/tiny-h264 Commands to install the @yume-chan/scrcpy-decoder-tinyh264 package using various Node.js package managers. ```bash npm install @yume-chan/scrcpy-decoder-tinyh264 ``` ```bash yarn add @yume-chan/scrcpy-decoder-tinyh264 ``` ```bash pnpm add @yume-chan/scrcpy-decoder-tinyh264 ``` ```bash bun add @yume-chan/scrcpy-decoder-tinyh264 ``` -------------------------------- ### Fetch Scrcpy Server Binary using npx Source: https://tangoadb.dev/scrcpy/prepare-server Execute the fetch-scrcpy-server script using npx to download the server binary for a specified version. Note that npx may not work if the package is not installed due to differing package and script names. A workaround for Scrcpy 2.2 is available by prefixing the version with 'v'. ```bash npx fetch-scrcpy-server npx fetch-scrcpy-server v2.2 ``` -------------------------------- ### AdbScrcpyClient.start Source: https://tangoadb.dev/scrcpy/start-server Starts the Scrcpy server on a connected Android device, handling port forwarding and connection establishment automatically. ```APIDOC ## POST AdbScrcpyClient.start ### Description Starts the Scrcpy server on the device using the provided ADB connection and server path. It automatically manages port forwarding and connection logic. ### Method Static Async Method ### Parameters #### Arguments - **adb** (Adb) - Required - An active Adb instance to run commands. - **path** (string) - Required - The filesystem path on the device where the scrcpy-server.jar is located. - **options** (AdbScrcpyOptions) - Required - Configuration options for the server session. ### Request Example ```javascript const client = await AdbScrcpyClient.start( adb, "/data/local/tmp/scrcpy-server.jar", new AdbScrcpyOptions2_1({}) ); ``` ### Response #### Success Response (Promise) - **client** (AdbScrcpyClient) - Returns an instance of the client once the connection is established. #### Error Handling - **AdbScrcpyExitedError** - Thrown if the server process exits before the connection is established. Contains an `output` field with the process logs. ``` -------------------------------- ### Install AdbServerNodeTcpConnector dependency Source: https://tangoadb.dev/tango/server/client Commands to install the required package for Node.js TCP connectivity using various package managers. ```bash npm i @yume-chan/adb-server-node-tcp ``` ```bash yarn add @yume-chan/adb-server-node-tcp ``` ```bash pnpm add @yume-chan/adb-server-node-tcp ``` ```bash bun add @yume-chan/adb-server-node-tcp ```