### Install APK Usage Source: https://tangoadb.dev/next/api/bin/pm/install Examples for initializing the PackageManager and installing an APK file. ```javascript import { PackageManager } from "@yume-chan/android-bin"; const pm = new PackageManager(adb); await pm.install(["/path/to/app.apk"]); ``` ```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"]); ``` -------------------------------- ### Start App by Name Source: https://tangoadb.dev/next/scrcpy/control/start-app Examples for launching an application by searching for its label. ```javascript // Using `ScrcpyControlMessageSerializer` const message = serializer.startApp("Chrome", { forceStop: false, searchByName: true, }); // Using `ScrcpyControlMessageWriter` await writer.startApp("Chrome", { forceStop: false, searchByName: true, }); // Using `AdbScrcpyClient` await client.controller.startApp("Chrome", { forceStop: false, searchByName: true, }); ``` ```typescript // Using `ScrcpyControlMessageSerializer` const message: Uint8Array = serializer.startApp("Chrome", { forceStop: false, searchByName: true, }); // Using `ScrcpyControlMessageWriter` await writer.startApp("Chrome", { forceStop: false, searchByName: true, }); // Using `AdbScrcpyClient` await client.controller!.startApp("Chrome", { forceStop: false, searchByName: true, }); ``` -------------------------------- ### Start App by Package Name Source: https://tangoadb.dev/next/scrcpy/control/start-app Examples for launching an application using its package name. ```javascript // Using `ScrcpyControlMessageSerializer` const message = serializer.startApp("com.android.chrome", { forceStop: true, searchByName: false, }); // Using `ScrcpyControlMessageWriter` await writer.startApp("com.android.chrome", { forceStop: true, searchByName: false, }); // Using `AdbScrcpyClient` await client.controller.startApp("com.android.chrome", { forceStop: true, searchByName: false, }); ``` ```typescript // Using `ScrcpyControlMessageSerializer` const message: Uint8Array = serializer.startApp("com.android.chrome", { forceStop: true, searchByName: false, }); // Using `ScrcpyControlMessageWriter` await writer.startApp("com.android.chrome", { forceStop: true, searchByName: false, }); // Using `AdbScrcpyClient` await client.controller!.startApp("com.android.chrome", { forceStop: true, searchByName: false, }); ``` -------------------------------- ### Install @yume-chan/adb-credential-web Source: https://tangoadb.dev/next/tango/daemon/credential-store Installation commands for various package managers. ```bash npm i @yume-chan/adb-credential-web ``` ```bash yarn add @yume-chan/adb-credential-web ``` ```bash pnpm add @yume-chan/adb-credential-web ``` ```bash bun add @yume-chan/adb-credential-web ``` -------------------------------- ### Install @yume-chan/adb-compression-zstd Source: https://tangoadb.dev/next/api/adb/sync/compression/adb-compression-zstd Installation commands for various package managers. ```bash npm install @yume-chan/adb-compression-zstd ``` ```bash yarn add @yume-chan/adb-compression-zstd ``` ```bash pnpm add @yume-chan/adb-compression-zstd ``` ```bash bun add @yume-chan/adb-compression-zstd ``` -------------------------------- ### Install dependencies Source: https://tangoadb.dev/next/tango/custom-transport/server-client Install project dependencies using pnpm. ```bash pnpm install ``` -------------------------------- ### Run server and client Source: https://tangoadb.dev/next/tango/custom-transport/server-client Commands to start the server and client applications. ```bash cd server npm start ``` ```bash cd client npm start ``` -------------------------------- ### PackageManager.installStream(size, stream, options) Source: https://tangoadb.dev/next/api/bin/pm/install-stream Installs a single APK from a ReadableStream. If the device supports streaming install, the APK is uploaded, parsed, and installed in parallel. Otherwise, it uploads the file to the device first. ```APIDOC ## Method: installStream ### Description Installs an APK from a `ReadableStream`. It uses streaming install if supported by the device; otherwise, it uploads the file to a temporary folder on the device before installing. ### Signature `installStream(size: number, stream: ReadableStream, options?: Partial): Promise` ### Parameters - **size** (number) - Required - The size of the APK file. - **stream** (ReadableStream) - Required - The stream containing the APK data. - **options** (Partial) - Optional - Configuration options for the installation process (e.g., skipExisting, installerPackageName, allowTest, etc.). ### Usage Example ```typescript import { PackageManager } from "@yume-chan/android-bin"; const pm = new PackageManager(adb); await pm.installStream(file.size, file.stream()); ``` ``` -------------------------------- ### Install @yume-chan/fetch-scrcpy-server Source: https://tangoadb.dev/next/scrcpy/prepare-server Commands to install the package as a development dependency using various package managers. ```bash npm i -D @yume-chan/fetch-scrcpy-server ``` ```bash yarn add --dev @yume-chan/fetch-scrcpy-server ``` ```bash pnpm add -D @yume-chan/fetch-scrcpy-server ``` ```bash bun add --dev @yume-chan/fetch-scrcpy-server ``` -------------------------------- ### Launching an Activity Source: https://tangoadb.dev/next/api/bin/am/start-activity Example of calling startActivity with an intent and user specification. ```typescript await activityManager.startActivity({ intent: { action: "android.intent.action.MAIN", component: { packageName: "com.android.settings", className: "com.android.settings.Settings", }, }, user: 0, }); ``` -------------------------------- ### Initialize WebCodecsVideoDecoder Source: https://tangoadb.dev/next/scrcpy/video/webcodecs/decoder Example of instantiating the decoder with specific configuration options. ```typescript import { WebCodecsVideoDecoder } from "@yume-chan/scrcpy-decoder-webcodecs"; const decoder = new WebCodecsVideoDecoder({ codec: videoMetadata.codec, renderer: renderer, hardwareAcceleration: "no-preference", optimizeForLatency: true, }); ``` -------------------------------- ### Create Adb instance examples Source: https://tangoadb.dev/next/api/server/create-adb Usage examples for creating an Adb instance using a transport ID in JavaScript and TypeScript. ```javascript const adb = await client.createAdb({ transportId: 123n, }); ``` ```typescript import type { AdbServerClient, Adb } from "@yume-chan/adb"; declare const client: AdbServerClient; const adb: Adb = await client.createAdb({ transportId: 123n, }); ``` -------------------------------- ### Install usb package Source: https://tangoadb.dev/next/tango/daemon/usb/device-manager Commands to install the usb package for Node.js environments. ```bash npm i usb ``` ```bash yarn add usb ``` ```bash pnpm add usb ``` ```bash bun add usb ``` -------------------------------- ### Usage Examples for installStream Source: https://tangoadb.dev/next/api/bin/pm/install-stream Demonstrates how to initialize the PackageManager and invoke the installStream method using JavaScript and TypeScript. ```javascript import { PackageManager } from "@yume-chan/android-bin"; const pm = new PackageManager(adb); await pm.installStream(file.size, file.stream()); ``` ```typescript import type { Adb } from "@yume-chan/adb"; import { PackageManager } from "@yume-chan/android-bin"; declare const adb: Adb; const pm = new PackageManager(adb); declare const file: File; await pm.installStream(file.size, file.stream()); ``` -------------------------------- ### Clone project repository Source: https://tangoadb.dev/next/tango/custom-transport/server-client Commands to clone the example server-client project from GitHub. ```bash git clone https://github.com/tango-adb/example-server-client.git cd example-server-client ``` -------------------------------- ### Install Mediabunny and dependencies Source: https://tangoadb.dev/next/scrcpy/video/record Install the required packages for handling Scrcpy streams and muxing using various package managers. ```npm npm install @yume-chan/media-codec @yume-chan/scrcpy @yume-chan/stream-extra mediabunny ``` ```yarn yarn add @yume-chan/media-codec @yume-chan/scrcpy @yume-chan/stream-extra mediabunny ``` ```pnpm pnpm add @yume-chan/media-codec @yume-chan/scrcpy @yume-chan/stream-extra mediabunny ``` ```bun bun add @yume-chan/media-codec @yume-chan/scrcpy @yume-chan/stream-extra mediabunny ``` -------------------------------- ### Install @yume-chan/adb package Source: https://tangoadb.dev/next/tango/daemon Install the core package using your preferred package manager. ```bash npm i @yume-chan/adb ``` ```bash yarn add @yume-chan/adb ``` ```bash pnpm add @yume-chan/adb ``` ```bash bun add @yume-chan/adb ``` -------------------------------- ### UHID Create Usage Examples Source: https://tangoadb.dev/next/scrcpy/control/uhid Examples showing how to use the UHID create message with different serializers, writers, and clients. ```javascript // Using `ScrcpyControlMessageSerializer` const message = serializer.uHidCreate({ id: 1, data: new Uint8Array([ // Sample keyboard HID descriptor (usage page 0x01, usage 0x06 - keyboard) 0x05, 0x01, // Usage Page (Generic Desktop) 0x09, 0x06, // Usage (Keyboard) 0xa1, 0x01, // Collection (Application) 0x05, 0x07, // Usage Page (Key Codes) 0x19, 0xe0, // Usage Minimum (224) 0x29, 0xe7, // Usage Maximum (231) 0x15, 0x00, // Logical Minimum (0) 0x25, 0x01, // Logical Maximum (1) 0x75, 0x01, // Report Size (1) 0x95, 0x08, // Report Count (8) 0x81, 0x02, // Input (Data, Variable, Absolute) ; Modifier byte 0x95, 0x01, // Report Count (1) 0x75, 0x08, // Report Size (8) 0x81, 0x01, // Input (Constant) ; Reserved byte 0x95, 0x05, // Report Count (5) 0x75, 0x01, // Report Size (1) 0x05, 0x08, // Usage Page (LEDs) 0x19, 0x01, // Usage Minimum (1) 0x29, 0x05, // Usage Maximum (5) 0x91, 0x02, // Output (Data, Variable, Absolute) ; LED report 0x95, 0x01, // Report Count (1) 0x75, 0x03, // Report Size (3) 0x91, 0x01, // Output (Constant) ; LED report padding 0x95, 0x06, // Report Count (6) 0x75, 0x08, // Report Size (8) 0x15, 0x00, // Logical Minimum (0) 0x25, 0x65, // Logical Maximum (101) 0x05, 0x07, // Usage Page (Key Codes) 0x19, 0x00, // Usage Minimum (0) 0x29, 0x65, // Usage Maximum (101) 0x81, 0x00, // Input (Data, Array, Absolute) 0xc0, // End Collection ]), }); // Using `ScrcpyControlMessageWriter` await writer.uHidCreate({ id: 1, data: new Uint8Array([/* HID descriptor bytes */]), }); // Using `AdbScrcpyClient` await client.controller.uHidCreate({ id: 1, data: new Uint8Array([/* HID descriptor bytes */]), }); ``` ```typescript // Using `ScrcpyControlMessageSerializer` const message: Uint8Array = serializer.uHidCreate({ id: 1, data: new Uint8Array([ // Sample keyboard HID descriptor (usage page 0x01, usage 0x06 - keyboard) 0x05, 0x01, // Usage Page (Generic Desktop) 0x09, 0x06, // Usage (Keyboard) 0xa1, 0x01, // Collection (Application) 0x05, 0x07, // Usage Page (Key Codes) 0x19, 0xe0, // Usage Minimum (224) 0x29, 0xe7, // Usage Maximum (231) 0x15, 0x00, // Logical Minimum (0) 0x25, 0x01, // Logical Maximum (1) 0x75, 0x01, // Report Size (1) 0x95, 0x08, // Report Count (8) 0x81, 0x02, // Input (Data, Variable, Absolute) ; Modifier byte 0x95, 0x01, // Report Count (1) 0x75, 0x08, // Report Size (8) 0x81, 0x01, // Input (Constant) ; Reserved byte 0x95, 0x05, // Report Count (5) 0x75, 0x01, // Report Size (1) 0x05, 0x08, // Usage Page (LEDs) 0x19, 0x01, // Usage Minimum (1) 0x29, 0x05, // Usage Maximum (5) 0x91, 0x02, // Output (Data, Variable, Absolute) ; LED report 0x95, 0x01, // Report Count (1) 0x75, 0x03, // Report Size (3) 0x91, 0x01, // Output (Constant) ; LED report padding 0x95, 0x06, // Report Count (6) 0x75, 0x08, // Report Size (8) 0x15, 0x00, // Logical Minimum (0) 0x25, 0x65, // Logical Maximum (101) 0x05, 0x07, // Usage Page (Key Codes) 0x19, 0x00, // Usage Minimum (0) 0x29, 0x65, // Usage Maximum (101) 0x81, 0x00, // Input (Data, Array, Absolute) 0xc0, // End Collection ]), }); // Using `ScrcpyControlMessageWriter` await writer.uHidCreate({ id: 1, data: new Uint8Array([/* HID descriptor bytes */]), }); // Using `AdbScrcpyClient` await client.controller!.uHidCreate({ id: 1, data: new Uint8Array([/* HID descriptor bytes */]), }); ``` -------------------------------- ### ADB Socket Spec Command Examples Source: https://tangoadb.dev/next/tango/server/client Examples of using the -L flag or environment variables to specify an ADB socket. ```bash # Using the -L flag to specify the socket adb -L tcp:localhost:5037 devices # Or set environment variable export ADB_SERVER_SOCKET=tcp:localhost:5037 adb devices ``` -------------------------------- ### PackageManager.install(apks, options?) Source: https://tangoadb.dev/next/api/bin/pm/install Installs an APK file on the device filesystem. If the APK is not on the device, use installStream to upload and install in parallel. ```APIDOC ## install(apks: string[], options?: Partial): Promise ### Description Installs one or more APK files on the device filesystem. Returns a promise that resolves with the installation result. ### Parameters - **apks** (string[]) - Required - An array of paths to the APK files on the device. - **options** (Partial) - Optional - Configuration options for the installation process, mapping to standard ADB pm install flags. ### Usage Example ```typescript import { PackageManager } from "@yume-chan/android-bin"; const pm = new PackageManager(adb); await pm.install(["/path/to/app.apk"]); ``` ``` -------------------------------- ### Initialize Credential Manager Source: https://tangoadb.dev/next/tango/upgrade Example of setting up the AdbWebCryptoCredentialManager with IndexedDB storage. ```typescript import type { AdbCredentialManager, TangoKeyStorage, } from "@yume-chan/adb-credential-web"; import { AdbWebCryptoCredentialManager, TangoIndexedDbStorage, } from "@yume-chan/adb-credential-web"; const storage: TangoKeyStorage = new TangoIndexedDbStorage(); const credentialManager: AdbCredentialManager = new AdbWebCryptoCredentialManager(storage); ``` -------------------------------- ### Listing Packages Example Source: https://tangoadb.dev/next/api/bin/pm/list-packages Demonstrates how to list all packages or filter by third-party status using the PackageManager. ```typescript import { PackageManager } from "@yume-chan/android-bin"; const packageManager = new PackageManager(adb); // List all packages for await (const pkg of packageManager.listPackages()) { console.log(pkg.packageName); } // List only third-party packages for await (const pkg of packageManager.listPackages({ listThirdParty: true })) { console.log(pkg.packageName); } ``` -------------------------------- ### Equivalent ADB Command Source: https://tangoadb.dev/next/api/bin/pm/install The standard shell command equivalent to the library's install method. ```bash adb shell pm install /path/to/app.apk ``` -------------------------------- ### Configure ADB_VENDOR_KEYS Source: https://tangoadb.dev/next/tango/daemon/credential-store/node-storage Examples of setting the ADB_VENDOR_KEYS environment variable for different scenarios. ```bash # Single file export ADB_VENDOR_KEYS=/path/to/vendor.key # Multiple files/directories export ADB_VENDOR_KEYS=/path/to/vendor1.key:/path/to/vendor2.key # Mixed files and directories export ADB_VENDOR_KEYS=/path/to/single.key:/path/to/key/directory ``` -------------------------------- ### Initialize BitmapVideoFrameRenderer Source: https://tangoadb.dev/next/scrcpy/video/webcodecs/renderer Examples showing how to initialize the renderer with an automatic canvas, an existing HTMLCanvasElement, or an OffscreenCanvas. ```javascript // 1. Create canvas automatically const bitmapRenderer1 = new BitmapVideoFrameRenderer(); // Access the automatically created canvas // In main thread: canvas is HTMLCanvasElement, can be added to DOM // In worker: canvas is OffscreenCanvas, use transferToImageBitmap to send frames to main thread if (bitmapRenderer1.canvas instanceof HTMLCanvasElement) { // Main thread context document.body.appendChild(bitmapRenderer1.canvas); } else { // Worker context - use transferToImageBitmap to send frames to main thread // See "Web Workers" for detailed example } // 2. Use an external HTML canvas element const canvasElement = document.getElementById('myCanvas'); const bitmapRenderer2 = new BitmapVideoFrameRenderer({ canvas: canvasElement }); // 3. Use an external OffscreenCanvas const offscreenCanvas = new OffscreenCanvas(1920, 1080); const bitmapRenderer3 = new BitmapVideoFrameRenderer({ canvas: offscreenCanvas }); ``` -------------------------------- ### Equivalent ADB command Source: https://tangoadb.dev/next/api/adb/sync/write The shell command equivalent to the provided write example. ```bash echo "Hello, world!" > hello.txt adb push hello.txt /sdcard/Download/hello.txt ``` -------------------------------- ### Configure video codec in Scrcpy v2.0 Source: https://tangoadb.dev/next/scrcpy/options/v2.0/video-codec Example demonstrating how to initialize ScrcpyOptions2_0 with the H.265 codec. ```typescript import { ScrcpyOptions2_0 } from "@yume-chan/scrcpy"; const options = new ScrcpyOptions2_0({ videoCodec: "h265", // Use H.265 codec }); ``` -------------------------------- ### Write file example Source: https://tangoadb.dev/next/api/adb/sync/write Demonstrates writing a string to a file on the device using a ReadableStream. ```typescript import { encodeUtf8 } from "@yume-chan/adb"; const readable = new ReadableStream({ start(controller) { controller.enqueue(encodeUtf8("Hello, world!")); controller.close(); }, }); await sync.write({ path: "/sdcard/Download/hello.txt", readable, }); ``` -------------------------------- ### Handling video stream consumers Source: https://tangoadb.dev/next/scrcpy/control/reset-video Example implementation for managing new consumers when resetting the video stream. ```javascript let consumers = []; let pendingConsumers = []; // New decoders, muxers, or remote clients waiting for the next `configuration` packet function addNewConsumer(consumer) { // For example when a new client connected pendingConsumers.add(consumer); await controller.resetVideo(); } for await (const packet of videoPacketStream) { switch (packet.type) { case "configuration": if (pendingConsumers.length) { // Start new consumers consumers = consumers.concat(pendingConsumers); pendingConsumers = []; } for (const consumer of consumers) { // Send the configuration to consumer } break; case "data": for (const consumer of consumers) { // Send the frame to consumer } break; } } ``` ```typescript import type { ScrcpyMediaStreamPacket } from "@yume-chan/scrcpy"; declare const videoPacketStream: ReadableStream; declare const controller: ScrcpyControlMessageWriter; let consumers: unknown[] = []; let pendingConsumers: unknown[] = []; // New decoders, muxers, or remote clients waiting for the next `configuration` packet function addNewConsumer(consumer: unknown) { // For example when a new client connected pendingConsumers.add(consumer); await controller.resetVideo(); } for await (const packet of videoPacketStream) { switch (packet.type) { case "configuration": if (pendingConsumers.length) { // Start new consumers consumers = consumers.concat(pendingConsumers); pendingConsumers = []; } for (const consumer of consumers) { // Send the configuration to consumer } break; case "data": for (const consumer of consumers) { // Send the frame to consumer } break; } } ``` -------------------------------- ### Start server with default path Source: https://tangoadb.dev/next/scrcpy/start-server Initialize the Scrcpy client using the default server path. ```javascript 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 }), ); ``` -------------------------------- ### Enable listApps in ScrcpyOptions3_0 Source: https://tangoadb.dev/next/scrcpy/options/v3.0/list-apps Configures the ScrcpyOptions3_0 instance to list installed applications on the device. ```typescript import { ScrcpyOptions3_0 } from "@yume-chan/scrcpy"; const options = new ScrcpyOptions3_0({ listApps: true, // List installed apps on device }); ``` -------------------------------- ### AdbScrcpyClient.start Source: https://tangoadb.dev/next/scrcpy/start-server Starts the Scrcpy server on the device, automatically handling port forwarding and connection. ```APIDOC ## AdbScrcpyClient.start ### Description Starts the Scrcpy server on the device using the provided ADB instance, server path, and configuration options. It automatically manages port forwarding and establishes the connection. ### Signature `static async start(adb: Adb, path: string, options: TOptions): Promise>` ### Parameters - **adb** (Adb) - Required - An Adb instance to run ADB commands. - **path** (string) - Required - The path on the device where the server file is located. - **options** (TOptions) - Required - The configuration options to start the server. ### Example ```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 }) ); ``` ``` -------------------------------- ### Initializing Adb with a Custom Transport Source: https://tangoadb.dev/next/tango/custom-transport/usage Examples showing how to initialize the Adb instance and execute a command using JavaScript and TypeScript. ```javascript import { Adb } from "@yume-chan/adb"; const adb = new Adb(transport); console.log(await adb.getProp("ro.build.version.sdk")); // Example ADB command ``` ```typescript import type { AdbTransport } from "@yume-chan/adb"; import { Adb } from "@yume-chan/adb"; declare const transport: AdbTransport; // Your custom transport instance const adb = new Adb(transport); console.log(await adb.getProp("ro.build.version.sdk")); // Example ADB command ``` -------------------------------- ### Authenticate with default processor Source: https://tangoadb.dev/next/tango/daemon/connect-device/default-processor Examples showing how to use the default authentication flow with a credential manager. ```javascript import { adbDaemonAuthenticate } from "@yume-chan/adb"; const transport = await adbDaemonAuthenticate({ serial: device.serial, connection, credentialManager: CredentialManager, }); ``` ```typescript import type { AdbDaemonTransport, AdbPacketData, AdbPacketInit } from "@yume-chan/adb"; import type { Consumable, ReadableWritablePair } from "@yume-chan/stream-extra"; import { adbDaemonAuthenticate, AdbWebCryptoCredentialManager } from "@yume-chan/adb"; import { AdbDaemonWebUsbDevice } from "@yume-chan/adb-daemon-webusb"; declare const device: AdbDaemonWebUsbDevice; declare const connection: ReadableWritablePair>; declare const CredentialManager: AdbWebCryptoCredentialManager; const transport: AdbDaemonTransport = await adbDaemonAuthenticate({ serial: device.serial, connection, credentialManager: CredentialManager, }); ``` -------------------------------- ### Check WebCodecs Support Source: https://tangoadb.dev/next/scrcpy/video/webcodecs Example usage to verify if the current browser environment supports the WebCodecs API. ```javascript import { WebCodecsVideoDecoder } from "@yume-chan/scrcpy-decoder-webcodecs"; console.log(WebCodecsVideoDecoder.isSupported); ``` -------------------------------- ### Automate Server Download in package.json Source: https://tangoadb.dev/next/scrcpy/prepare-server Add a postinstall script to automatically fetch the server binary during package installation. ```json { "name": "...", "devDependencies": { "@yume-chan/fetch-scrcpy-server": "^0.0.24" }, "scripts": { "postinstall": "fetch-scrcpy-server 2.1" } } ``` -------------------------------- ### Disconnect Example Source: https://tangoadb.dev/next/tango/server/wireless Usage examples for disconnecting a device in JavaScript and TypeScript. ```javascript await client.wireless.disconnect("192.168.1.100:5555"); ``` ```typescript import type { AdbServerClient } from "@yume-chan/adb"; declare const client: AdbServerClient; await client.wireless.disconnect("192.168.1.100:5555"); ``` -------------------------------- ### Initialize AdbServerClient in Node.js Source: https://tangoadb.dev/next/tango/upgrade Compare the legacy manual connector setup with the new recommended wrapper class approach. ```typescript import { AdbServerClient, AdbServerNodeTcpConnector } from "@yume-chan/adb-server-node-tcp"; const connector = new AdbServerNodeTcpConnector({ host: "localhost", port: 5037, }); const client = new AdbServerClient(connector); ``` ```typescript import { AdbServerNodeJsClient } from "@yume-chan/adb-server-node-tcp"; // Recommended: Use the wrapper class directly const client = new AdbServerNodeJsClient(); // Advanced: Use the connector directly for low-level control const connector = new AdbServerNodeTcpConnector({ host: "localhost", port: 5037, }); const client2 = new AdbServerClient(connector); ``` -------------------------------- ### Initialize WebGLVideoFrameRenderer Source: https://tangoadb.dev/next/scrcpy/video/webcodecs/renderer Examples showing how to check for support, use internal or external canvases, and enable capture features. ```javascript // 1. Check compatibility before creating renderer if (WebGLVideoFrameRenderer.isSupported) { const webglRenderer1 = new WebGLVideoFrameRenderer(); // Access the automatically created canvas // In main thread: canvas is HTMLCanvasElement, can be added to DOM // In worker: canvas is OffscreenCanvas, use transferToImageBitmap to send frames to main thread if (webglRenderer1.canvas instanceof HTMLCanvasElement) { // Main thread context document.body.appendChild(webglRenderer1.canvas); } else { // Worker context - use transferToImageBitmap to send frames to main thread // See "Web Workers" for detailed example } } else { console.warn("WebGL is not supported, consider using BitmapVideoFrameRenderer instead"); } // 2. Use an external HTML canvas element with capture enabled const canvasElement = document.getElementById('myCanvas'); if (WebGLVideoFrameRenderer.isSupported) { const webglRenderer2 = new WebGLVideoFrameRenderer({ canvas: canvasElement, enableCapture: true }); } else { console.warn("WebGL is not supported, consider using BitmapVideoFrameRenderer instead"); } // 3. Use an external OffscreenCanvas const offscreenCanvas = new OffscreenCanvas(1920, 1080); if (WebGLVideoFrameRenderer.isSupported) { const webglRenderer3 = new WebGLVideoFrameRenderer({ canvas: offscreenCanvas }); } else { console.warn("WebGL is not supported, consider using BitmapVideoFrameRenderer instead"); } ``` -------------------------------- ### Push server to default path Source: https://tangoadb.dev/next/scrcpy/push-server Example of using pushServer to upload the server binary to the default device path. ```javascript import { AdbScrcpyClient } from "@yume-chan/adb-scrcpy"; import { ReadableStream } from "@yume-chan/stream-extra"; await AdbScrcpyClient.pushServer( adb, new ReadableStream({ start(controller) { controller.enqueue(new Uint8Array(server)); controller.close(); }, }), ); ``` ```typescript import type { Adb } from "@yume-chan/adb"; import { AdbScrcpyClient } from "@yume-chan/adb-scrcpy"; import { ReadableStream } from "@yume-chan/stream-extra"; declare const adb: Adb; declare const server: ArrayBuffer; await AdbScrcpyClient.pushServer( adb, new ReadableStream({ start(controller) { controller.enqueue(new Uint8Array(server)); controller.close(); }, }), ); ``` -------------------------------- ### Initialize and use InsertableStreamVideoFrameRenderer Source: https://tangoadb.dev/next/scrcpy/video/webcodecs/renderer Examples showing how to instantiate the renderer with or without an existing video element, enable automatic resizing, and check for browser compatibility. ```javascript // 1. Create video element automatically const streamRenderer1 = new InsertableStreamVideoFrameRenderer(); document.body.appendChild(streamRenderer1.element); // 2. Use an existing video element const videoElement = document.getElementById('myVideo'); const streamRenderer2 = new InsertableStreamVideoFrameRenderer(videoElement); // 3. Enable automatic size updates const streamRenderer3 = new InsertableStreamVideoFrameRenderer(videoElement, { updateSize: true }); // 4. Check compatibility before using if (InsertableStreamVideoFrameRenderer.isSupported) { const compatibleRenderer = new InsertableStreamVideoFrameRenderer(); document.body.appendChild(compatibleRenderer.element); } else { console.warn("Insertable streams not supported, consider using WebGL or Bitmap renderers"); } ``` -------------------------------- ### Install TangoNodeStorage dependencies Source: https://tangoadb.dev/next/tango/daemon/credential-store/node-storage Commands to install the package using various Node.js package managers. ```bash npm i @yume-chan/adb-credential-nodejs ``` ```bash yarn add @yume-chan/adb-credential-nodejs ``` ```bash pnpm add @yume-chan/adb-credential-nodejs ``` ```bash bun add @yume-chan/adb-credential-nodejs ``` -------------------------------- ### Install android-bin package Source: https://tangoadb.dev/next/api Commands to install the @yume-chan/android-bin package using various package managers. ```shell npm i @yume-chan/android-bin ``` ```shell yarn add @yume-chan/android-bin ``` ```shell pnpm add @yume-chan/android-bin ``` ```shell bun add @yume-chan/android-bin ``` -------------------------------- ### Initialize ADB Server Client in Node.js Source: https://tangoadb.dev/next/tango/upgrade Demonstrates the recommended high-level wrapper class and the advanced low-level connector approach. ```typescript import { AdbServerNodeJsClient } from "@yume-chan/adb-server-node-tcp"; // Recommended: Use the wrapper class directly const client: AdbServerNodeJsClient = new AdbServerNodeJsClient(); // Advanced: Use the connector directly for low-level control import { AdbServerNodeTcpConnector, AdbServerClient } from "@yume-chan/adb-server-node-tcp"; const connector = new AdbServerNodeTcpConnector(); const client2: AdbServerClient = new AdbServerClient(connector); ``` -------------------------------- ### Install H264BSD decoder package Source: https://tangoadb.dev/next/scrcpy/video/tiny-h264 Commands to install the decoder package using various package managers. ```bash npm install @yume-chan/scrcpy-decoder-h264bsd ``` ```bash yarn add @yume-chan/scrcpy-decoder-h264bsd ``` ```bash pnpm add @yume-chan/scrcpy-decoder-h264bsd ``` ```bash bun add @yume-chan/scrcpy-decoder-h264bsd ``` -------------------------------- ### Install WebCodecs Decoder Package Source: https://tangoadb.dev/next/scrcpy/video/webcodecs Commands to install the @yume-chan/scrcpy-decoder-webcodecs package using various 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 ``` -------------------------------- ### Initialize Default Client and Connector Source: https://tangoadb.dev/next/tango/server/client Basic initialization of the client and connector using default settings. ```javascript import { AdbServerNodeTcpConnector } from "@yume-chan/adb-server-node-tcp"; import { AdbServerNodeJsClient } from "@yume-chan/adb-server-node-tcp"; const connector = new AdbServerNodeTcpConnector(); // OR const client = new AdbServerNodeJsClient(); ``` ```typescript import { AdbServerNodeTcpConnector } from "@yume-chan/adb-server-node-tcp"; import { AdbServerNodeJsClient } from "@yume-chan/adb-server-node-tcp"; const connector: AdbServerNodeTcpConnector = new AdbServerNodeTcpConnector(); // OR const client: AdbServerNodeJsClient = new AdbServerNodeJsClient(); ``` -------------------------------- ### Install Scrcpy Core Package Source: https://tangoadb.dev/next/scrcpy Install the core package for low-level Scrcpy message serialization and deserialization. ```npm npm install @yume-chan/scrcpy ``` ```yarn yarn add @yume-chan/scrcpy ``` ```pnpm pnpm add @yume-chan/scrcpy ``` ```bun bun add @yume-chan/scrcpy ``` -------------------------------- ### Configuring Crop Options Source: https://tangoadb.dev/next/scrcpy/options/v1.15/crop Examples showing how to configure the crop option using either a class instance or a string format. ```typescript import { ScrcpyOptions1_15, ScrcpyCrop } from "@yume-chan/scrcpy"; // Using ScrcpyCrop class instance const options1 = new ScrcpyOptions1_15({ crop: new ScrcpyCrop(1080, 1920, 0, 0), // Crop to 1080x1920 from position (0,0) }); ``` ```typescript // Using string format const options2 = new ScrcpyOptions1_15({ crop: "1080:1920:0:0", // Same as above but using string format }); ``` -------------------------------- ### Install @types/node package Source: https://tangoadb.dev/next/tango/daemon/tcp/create-connection Install the Node.js type definitions for development to enable code suggestions and type checking. ```bash npm i -D @types/node ``` ```bash yarn add --dev @types/node ``` ```bash pnpm add -D @types/node ``` ```bash bun add --dev @types/node ``` -------------------------------- ### PackageManagerInstallOptions Interface Source: https://tangoadb.dev/next/api/bin/pm/install Defines the configuration options available for the install process, mapping to standard ADB install flags. ```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; } ``` -------------------------------- ### Create an echo server with adb.reverse.add Source: https://tangoadb.dev/next/api/adb/reverse/add This example demonstrates setting up an echo server on TCP port 1234 on the device. The handler should not await the pipeTo promise to avoid blocking the transport. ```javascript const address = await adb.reverse.add("tcp:1234", (socket) => { const writer = socket.writable.getWriter(); // Don't await the promise, otherwise the transport will block socket.readable .pipeTo( new WritableStream({ async write(chunk) { await writer.write(chunk); }, }) ) .then( () => { // The socket is closed }, (error) => { // An error occurred } ); }); ``` -------------------------------- ### TCP device serial number examples Source: https://tangoadb.dev/next/tango/server/devices Examples of serial number formats for different types of TCP-connected devices. ```text 192.168.0.123:5555 ``` ```text adb-12345678-ABCDEF._adb-tls-connect._tcp ``` ```text emulator-5554 ``` -------------------------------- ### Initialize AdbScrcpyOptions2_1 Source: https://tangoadb.dev/next/scrcpy/options Demonstrates initializing the options class for server version 2.1. ```javascript import { AdbScrcpyOptions2_1 } from "@yume-chan/adb-scrcpy"; const options = new AdbScrcpyOptions2_1({ videoSource: "camera", // ... }); ``` ```typescript import { AdbScrcpyOptions2_1 } from "@yume-chan/adb-scrcpy"; import { ScrcpyOptions2_2 } from "@yume-chan/scrcpy"; const options = new AdbScrcpyOptions2_1({ videoSource: "camera", // ... }); ``` -------------------------------- ### Install ADB Server Node TCP package Source: https://tangoadb.dev/next/tango/server/client Commands to install the required package 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 ``` -------------------------------- ### Configure cameraFacing in ScrcpyOptions2_2 Source: https://tangoadb.dev/next/scrcpy/options/v2.2/camera-facing Demonstrates how to initialize ScrcpyOptions2_2 with the videoSource set to camera and the cameraFacing option set to front. ```typescript import { ScrcpyOptions2_2 } from "@yume-chan/scrcpy"; const options = new ScrcpyOptions2_2({ videoSource: "camera", // Enable camera source cameraFacing: "front", // Use front-facing camera }); ```