Skip to content

Commit

Permalink
refactor(scrcpy): simplify reverse connection
Browse files Browse the repository at this point in the history
  • Loading branch information
yume-chan committed Dec 18, 2023
1 parent b0a0de5 commit 19bb1c4
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions libraries/adb-scrcpy/src/connection.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import type { Adb } from "@yume-chan/adb";
import type { Adb, AdbSocket } from "@yume-chan/adb";
import { AdbReverseNotSupportedError, NOOP } from "@yume-chan/adb";
import { delay } from "@yume-chan/async";
import type { Disposable } from "@yume-chan/event";
import type {
Consumable,
PushReadableStreamController,
ReadableStream,
ReadableStreamDefaultReader,
ReadableWritablePair,
} from "@yume-chan/stream-extra";
import {
BufferedReadableStream,
TransformStream,
PushReadableStream,
} from "@yume-chan/stream-extra";
import type { ValueOrPromise } from "@yume-chan/struct";

Expand Down Expand Up @@ -156,16 +157,15 @@ export class AdbScrcpyReverseConnection extends AdbScrcpyConnection {
// Ignore other errors when unbinding
});

const queue = new TransformStream<
ReadableWritablePair<Uint8Array, Consumable<Uint8Array>>,
ReadableWritablePair<Uint8Array, Consumable<Uint8Array>>
>();
this.#streams = queue.readable.getReader();
const writer = queue.writable.getWriter();
let queueController: PushReadableStreamController<AdbSocket>;
const queue = new PushReadableStream<AdbSocket>((controller) => {
queueController = controller;
});
this.#streams = queue.getReader();
this.#address = await this.adb.reverse.add(
this.socketName,
(socket) => {
void writer.write(socket);
async (socket) => {
await queueController.enqueue(socket);
},
);
}
Expand Down

0 comments on commit 19bb1c4

Please sign in to comment.