feat: rename childprocess to subprocess

This commit is contained in:
Simon Chan 2022-02-15 23:18:39 +08:00
parent 443190e22a
commit 1a8891d4fc
22 changed files with 185 additions and 211 deletions

View file

@ -1,5 +1,5 @@
# `@yume-chan/adb-backend-direct-sockets`
Use Direct Sockets API for plugin-free ADB over WiFi connection.
Use [Direct Sockets API](https://wicg.github.io/direct-sockets/) for plugin-free ADB over WiFi connection.
Note: Direct Sockets API is still under developement in Chrome and requries extra command line arguments to enable. This package is not intended to be used in production, thus not published to NPM registry.
Note: Direct Sockets API is still under development in Chrome and requires extra command line arguments to enable. This package is not intended to be used in production, thus not published to NPM registry.

View file

@ -7,8 +7,8 @@ declare global {
readonly remoteAddress: string;
readonly remotePort: number;
readonly readable: ReadableStream;
readonly writable: WritableStream;
readonly readable: ReadableStream<Uint8Array>;
readonly writable: WritableStream<BufferSource>;
}
interface SocketOptions {
@ -45,22 +45,19 @@ export default class AdbDirectSocketsBackend implements AdbBackend {
private socket: TCPSocket | undefined;
private _readablePassthrough = new TransformStream<Uint8Array, ArrayBuffer>({
private _readableTransformStream = new TransformStream<Uint8Array, ArrayBuffer>({
transform(chunk, controller) {
// Although spec didn't say,
// the chunk always has `byteOffset` of 0 and `byteLength` same as its buffer
controller.enqueue(chunk.buffer);
},
});
public get readable(): ReadableStream<ArrayBuffer> {
return this._readablePassthrough.readable;
return this._readableTransformStream.readable;
}
private _writablePassthrough = new TransformStream<ArrayBuffer, Uint8Array>({
transform(chunk, controller) {
controller.enqueue(new Uint8Array(chunk));
},
});
public get writable(): WritableStream<ArrayBuffer> {
return this._writablePassthrough.writable;
public get writable(): WritableStream<ArrayBuffer> | undefined {
return this.socket?.writable;
}
private _connected = false;
@ -84,8 +81,13 @@ export default class AdbDirectSocketsBackend implements AdbBackend {
});
this.socket = socket;
this.socket.readable.pipeTo(this._readablePassthrough.writable);
this._writablePassthrough.readable.pipeTo(this.socket.writable);
this.socket.readable
.pipeThrough(new TransformStream<Uint8Array, Uint8Array>({
flush: () => {
this.disconnectEvent.fire();
},
}))
.pipeTo(this._readableTransformStream.writable);
this._connected = true;
}