mirror of
https://github.com/yume-chan/ya-webadb.git
synced 2025-10-05 02:39:26 +02:00
fix: make direct sockets backend work again
This commit is contained in:
parent
4f4096444e
commit
4c4580e2d7
7 changed files with 348 additions and 299 deletions
|
@ -1,4 +1,4 @@
|
|||
import type { AdbBackend, ReadableStream, WritableStream } from '@yume-chan/adb';
|
||||
import { AdbBackend, ReadableStream, WrapReadableStream, WrapWritableStream, WritableStream } from '@yume-chan/adb';
|
||||
|
||||
declare global {
|
||||
interface TCPSocket {
|
||||
|
@ -50,10 +50,29 @@ export default class AdbDirectSocketsBackend implements AdbBackend {
|
|||
}
|
||||
|
||||
public async connect() {
|
||||
return await navigator.openTCPSocket({
|
||||
const { readable, writable } = await navigator.openTCPSocket({
|
||||
remoteAddress: this.host,
|
||||
remotePort: this.port,
|
||||
noDelay: true,
|
||||
});
|
||||
// Native streams can't `pipeTo()` or `pipeThrough()` polyfilled streams, so we need to wrap them
|
||||
return {
|
||||
readable: new WrapReadableStream<Uint8Array, ReadableStream<Uint8Array>, void>({
|
||||
async start() {
|
||||
return {
|
||||
readable,
|
||||
state: undefined,
|
||||
};
|
||||
}
|
||||
}),
|
||||
writable: new WrapWritableStream({
|
||||
async start() {
|
||||
return {
|
||||
writable,
|
||||
state: undefined,
|
||||
};
|
||||
}
|
||||
}),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue