Skip to main content
Version: 1.1.0

Run ADB commands

Server

In this example, because the server didn't run any ADB commands, it only creates AdbTransports for the clients to use.

If needed, you can also run ADB commands in the server:

server/index.ts
import { Adb, AdbDaemonTransport } from "@yume-chan/adb";

const devices = new Map<string, Adb>();

// ...

const connection = await device.connect();
const transport = await AdbDaemonTransport.authenticate({
serial,
connection,
credentialStore: CredentialStore,
});

const adb = new Adb(transport);
devices.set(serial, adb);

// ...

Client

The client created an Adb instance using the custom AdbTransport, ran logcat command, and printed the output to a <div> element.

client/device.ts
import { AdbBanner, Adb } from "@yume-chan/adb";

const container = document.getElementById("app")!;

// ...

const data = await response.json();
const transport = new WebSocketTransport(
serial,
data.maxPayloadSize,
new AdbBanner(data.product, data.model, data.device, data.features),
);

const adb = new Adb(transport);
const process = await adb.subprocess.spawn("logcat");
for await (const chunk of process.stdout.pipeThrough(new TextDecoderStream())) {
container.textContent += chunk;
}

You can run other commands using the adb instance.