feat(adb): support connect to adb server (#549)

This commit is contained in:
Simon Chan 2023-05-14 03:54:03 +08:00 committed by GitHub
parent c34eef1d89
commit 3beaad2055
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
111 changed files with 2926 additions and 1701 deletions

View file

@ -38,10 +38,6 @@ import {
import type { AdbScrcpyConnection } from "./connection.js";
import type { AdbScrcpyOptions } from "./options/index.js";
const NOOP = () => {
// no-op
};
function arrayToStream<T>(array: T[]): ReadableStream<T> {
return new PushReadableStream(async (controller) => {
for (const item of array) {
@ -53,13 +49,14 @@ function arrayToStream<T>(array: T[]): ReadableStream<T> {
function concatStreams<T>(...streams: ReadableStream<T>[]): ReadableStream<T> {
return new PushReadableStream(async (controller) => {
for (const stream of streams) {
await stream.pipeTo(
new WritableStream({
async write(chunk) {
await controller.enqueue(chunk);
},
})
);
const reader = stream.getReader();
while (true) {
const { done, value } = await reader.read();
if (done) {
break;
}
await controller.enqueue(value);
}
}
});
}
@ -178,7 +175,13 @@ export class AdbScrcpyClient {
preventCancel: true,
}
)
.catch(NOOP);
.catch((e) => {
if (abortController.signal.aborted) {
return;
}
throw e;
});
const streams = await Promise.race([
process.exit.then(() => {