ya-webadb/libraries/scrcpy/src/push-server.ts
2022-02-18 18:19:28 +08:00

26 lines
690 B
TypeScript

import { Adb, AdbSync, HookWritableStream, WritableStream } from "@yume-chan/adb";
import { DEFAULT_SERVER_PATH } from "./options";
export interface PushServerOptions {
path?: string;
}
export function pushServer(
device: Adb,
options: PushServerOptions = {}
) {
const { path = DEFAULT_SERVER_PATH } = options;
return new HookWritableStream<ArrayBuffer, WritableStream<ArrayBuffer>, AdbSync>({
async start() {
const sync = await device.sync();
return {
writable: sync.write(path),
state: sync,
};
},
async close(sync) {
await sync.dispose();
},
});
}