Update Electron
This commit is contained in:
parent
cae6d582ac
commit
c84ee948f5
22 changed files with 763 additions and 152 deletions
57
client-electron/electron/adbaemonDirectSocketsDevice.ts
Normal file
57
client-electron/electron/adbaemonDirectSocketsDevice.ts
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
import type { AdbDaemonDevice } from '@yume-chan/adb'
|
||||
import { AdbPacket, AdbPacketSerializeStream } from '@yume-chan/adb'
|
||||
import {
|
||||
StructDeserializeStream,
|
||||
UnwrapConsumableStream,
|
||||
WrapReadableStream,
|
||||
WrapWritableStream
|
||||
} from '@yume-chan/stream-extra'
|
||||
import { TCPSocket } from './socketToTCPSocket'
|
||||
|
||||
export interface AdbDaemonDirectSocketDeviceOptions {
|
||||
host: string
|
||||
port?: number
|
||||
name?: string
|
||||
unref?: boolean
|
||||
}
|
||||
|
||||
export class AdbDaemonDirectSocketsDevice implements AdbDaemonDevice {
|
||||
static isSupported(): boolean {
|
||||
return true
|
||||
}
|
||||
|
||||
#options: AdbDaemonDirectSocketDeviceOptions
|
||||
|
||||
readonly serial: string
|
||||
|
||||
get host(): string {
|
||||
return this.#options.host
|
||||
}
|
||||
|
||||
readonly port: number
|
||||
|
||||
get name(): string | undefined {
|
||||
return this.#options.name
|
||||
}
|
||||
|
||||
constructor(options: AdbDaemonDirectSocketDeviceOptions) {
|
||||
this.#options = options
|
||||
this.port = options.port ?? 5555
|
||||
this.serial = `${this.host}:${this.port}`
|
||||
}
|
||||
|
||||
async connect() {
|
||||
const socket = new TCPSocket(this.host, this.port, {
|
||||
noDelay: true,
|
||||
unref: this.#options.unref
|
||||
})
|
||||
const { readable, writable } = await socket.opened
|
||||
|
||||
return {
|
||||
readable: new WrapReadableStream(readable).pipeThrough(new StructDeserializeStream(AdbPacket)),
|
||||
writable: new WrapWritableStream(writable)
|
||||
.bePipedThroughFrom(new UnwrapConsumableStream())
|
||||
.bePipedThroughFrom(new AdbPacketSerializeStream())
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue