@yume-chan/adb-daemon-webusb
Advanced tools
Comparing version 0.0.20 to 0.0.21
@@ -5,2 +5,8 @@ { | ||
{ | ||
"version": "0.0.21", | ||
"tag": "@yume-chan/adb-daemon-webusb_v0.0.21", | ||
"date": "Fri, 25 Aug 2023 14:05:18 GMT", | ||
"comments": {} | ||
}, | ||
{ | ||
"version": "0.0.20", | ||
@@ -7,0 +13,0 @@ "tag": "@yume-chan/adb-daemon-webusb_v0.0.20", |
# Change Log - @yume-chan/adb-daemon-webusb | ||
This log was last generated on Mon, 05 Jun 2023 02:51:41 GMT and should not be manually modified. | ||
This log was last generated on Fri, 25 Aug 2023 14:05:18 GMT and should not be manually modified. | ||
## 0.0.21 | ||
Fri, 25 Aug 2023 14:05:18 GMT | ||
_Version update only_ | ||
## 0.0.20 | ||
@@ -6,0 +11,0 @@ Mon, 05 Jun 2023 02:51:41 GMT |
import { ADB_DEFAULT_DEVICE_FILTER, AdbDaemonWebUsbDevice } from "./device.js"; | ||
import { findUsbAlternateInterface, isErrorName } from "./utils.js"; | ||
class AdbDaemonWebUsbDeviceManager { | ||
export class AdbDaemonWebUsbDeviceManager { | ||
/** | ||
@@ -35,2 +35,5 @@ * Gets the instance of {@link AdbDaemonWebUsbDeviceManager} using browser WebUSB implementation. | ||
async requestDevice(filters = [ADB_DEFAULT_DEVICE_FILTER]) { | ||
if (filters.length === 0) { | ||
throw new TypeError("filters must not be empty"); | ||
} | ||
try { | ||
@@ -63,2 +66,5 @@ const device = await this.#usbManager.requestDevice({ | ||
async getDevices(filters = [ADB_DEFAULT_DEVICE_FILTER]) { | ||
if (filters.length === 0) { | ||
throw new TypeError("filters must not be empty"); | ||
} | ||
const devices = await this.#usbManager.getDevices(); | ||
@@ -93,3 +99,2 @@ return devices | ||
} | ||
export { AdbDaemonWebUsbDeviceManager }; | ||
//# sourceMappingURL=manager.js.map |
@@ -6,5 +6,3 @@ /// <reference types="w3c-web-usb" /> | ||
dispose(): void; | ||
private handleConnect; | ||
private handleDisconnect; | ||
} | ||
//# sourceMappingURL=watcher.d.ts.map |
@@ -7,13 +7,13 @@ export class AdbDaemonWebUsbDeviceWatcher { | ||
this.#usbManager = usb; | ||
this.#usbManager.addEventListener("connect", this.handleConnect); | ||
this.#usbManager.addEventListener("disconnect", this.handleDisconnect); | ||
this.#usbManager.addEventListener("connect", this.#handleConnect); | ||
this.#usbManager.addEventListener("disconnect", this.#handleDisconnect); | ||
} | ||
dispose() { | ||
this.#usbManager.removeEventListener("connect", this.handleConnect); | ||
this.#usbManager.removeEventListener("disconnect", this.handleDisconnect); | ||
this.#usbManager.removeEventListener("connect", this.#handleConnect); | ||
this.#usbManager.removeEventListener("disconnect", this.#handleDisconnect); | ||
} | ||
handleConnect = (e) => { | ||
#handleConnect = (e) => { | ||
this.#callback(e.device.serialNumber); | ||
}; | ||
handleDisconnect = () => { | ||
#handleDisconnect = () => { | ||
this.#callback(); | ||
@@ -20,0 +20,0 @@ }; |
{ | ||
"name": "@yume-chan/adb-daemon-webusb", | ||
"version": "0.0.20", | ||
"version": "0.0.21", | ||
"description": "Adb daemon transport connection for `@yume-chan/adb` using WebUSB API.", | ||
@@ -29,6 +29,6 @@ "keywords": [ | ||
"@types/w3c-web-usb": "^1.0.6", | ||
"@yume-chan/adb": "^0.0.20", | ||
"@yume-chan/stream-extra": "^0.0.20", | ||
"@yume-chan/struct": "^0.0.20", | ||
"tslib": "^2.5.2" | ||
"@yume-chan/adb": "^0.0.21", | ||
"@yume-chan/stream-extra": "^0.0.21", | ||
"@yume-chan/struct": "^0.0.21", | ||
"tslib": "^2.6.0" | ||
}, | ||
@@ -38,5 +38,5 @@ "devDependencies": { | ||
"@yume-chan/tsconfig": "^1.0.0", | ||
"eslint": "^8.41.0", | ||
"prettier": "^2.8.8", | ||
"typescript": "^5.0.3" | ||
"eslint": "^8.44.0", | ||
"prettier": "^3.0.0", | ||
"typescript": "^5.1.6" | ||
}, | ||
@@ -43,0 +43,0 @@ "scripts": { |
@@ -80,7 +80,7 @@ import type { | ||
public get position() { | ||
get position() { | ||
return this.#position; | ||
} | ||
public constructor(data: Uint8Array) { | ||
constructor(data: Uint8Array) { | ||
this.#data = data; | ||
@@ -90,6 +90,6 @@ this.#position = 0; | ||
public readExactly(length: number): Uint8Array { | ||
readExactly(length: number): Uint8Array { | ||
const result = this.#data.subarray( | ||
this.#position, | ||
this.#position + length | ||
this.#position + length, | ||
); | ||
@@ -105,3 +105,3 @@ this.#position += length; | ||
#readable: ReadableStream<AdbPacketData>; | ||
public get readable() { | ||
get readable() { | ||
return this.#readable; | ||
@@ -111,11 +111,11 @@ } | ||
#writable: WritableStream<Consumable<AdbPacketInit>>; | ||
public get writable() { | ||
get writable() { | ||
return this.#writable; | ||
} | ||
public constructor( | ||
constructor( | ||
device: USBDevice, | ||
inEndpoint: USBEndpoint, | ||
outEndpoint: USBEndpoint, | ||
usbManager: USB | ||
usbManager: USB, | ||
) { | ||
@@ -140,3 +140,3 @@ let closed = false; | ||
"disconnect", | ||
handleUsbDisconnect | ||
handleUsbDisconnect, | ||
); | ||
@@ -163,3 +163,3 @@ }, | ||
inEndpoint.endpointNumber, | ||
24 | ||
24, | ||
); | ||
@@ -175,3 +175,3 @@ | ||
const packet = AdbPacketHeader.deserialize( | ||
stream | ||
stream, | ||
) as AdbPacketHeader & { payload: Uint8Array }; | ||
@@ -181,6 +181,6 @@ if (packet.payloadLength !== 0) { | ||
inEndpoint.endpointNumber, | ||
packet.payloadLength | ||
packet.payloadLength, | ||
); | ||
packet.payload = new Uint8Array( | ||
result.data!.buffer | ||
result.data!.buffer, | ||
); | ||
@@ -214,3 +214,3 @@ } else { | ||
}, | ||
}) | ||
}), | ||
); | ||
@@ -226,3 +226,3 @@ | ||
outEndpoint.endpointNumber, | ||
chunk | ||
chunk, | ||
); | ||
@@ -240,3 +240,3 @@ | ||
outEndpoint.endpointNumber, | ||
EMPTY_UINT8_ARRAY | ||
EMPTY_UINT8_ARRAY, | ||
); | ||
@@ -251,5 +251,5 @@ } | ||
}, | ||
}) | ||
}), | ||
), | ||
new AdbPacketSerializeStream() | ||
new AdbPacketSerializeStream(), | ||
); | ||
@@ -264,11 +264,11 @@ } | ||
#raw: USBDevice; | ||
public get raw() { | ||
get raw() { | ||
return this.#raw; | ||
} | ||
public get serial(): string { | ||
get serial(): string { | ||
return this.#raw.serialNumber!; | ||
} | ||
public get name(): string { | ||
get name(): string { | ||
return this.#raw.productName!; | ||
@@ -283,6 +283,6 @@ } | ||
*/ | ||
public constructor( | ||
constructor( | ||
device: USBDevice, | ||
filters: AdbDeviceFilter[] = [ADB_DEFAULT_DEVICE_FILTER], | ||
usbManager: USB | ||
usbManager: USB, | ||
) { | ||
@@ -298,3 +298,3 @@ this.#raw = device; | ||
*/ | ||
public async connect(): Promise< | ||
async connect(): Promise< | ||
ReadableWritablePair<AdbPacketData, Consumable<AdbPacketInit>> | ||
@@ -316,3 +316,3 @@ > { | ||
await this.#raw.selectConfiguration( | ||
configuration.configurationValue | ||
configuration.configurationValue, | ||
); | ||
@@ -330,3 +330,3 @@ } | ||
interface_.interfaceNumber, | ||
alternate.alternateSetting | ||
alternate.alternateSetting, | ||
); | ||
@@ -336,3 +336,3 @@ } | ||
const { inEndpoint, outEndpoint } = findUsbEndpoints( | ||
alternate.endpoints | ||
alternate.endpoints, | ||
); | ||
@@ -343,5 +343,5 @@ return new AdbDaemonWebUsbConnection( | ||
outEndpoint, | ||
this.#usbManager | ||
this.#usbManager, | ||
); | ||
} | ||
} |
@@ -11,3 +11,3 @@ import { ADB_DEFAULT_DEVICE_FILTER, AdbDaemonWebUsbDevice } from "./device.js"; | ||
*/ | ||
public static readonly BROWSER = | ||
static readonly BROWSER = | ||
typeof globalThis.navigator !== "undefined" && | ||
@@ -24,3 +24,3 @@ !!globalThis.navigator.usb | ||
*/ | ||
public constructor(usbManager: USB) { | ||
constructor(usbManager: USB) { | ||
this.#usbManager = usbManager; | ||
@@ -42,5 +42,9 @@ } | ||
*/ | ||
public async requestDevice( | ||
filters: AdbDeviceFilter[] = [ADB_DEFAULT_DEVICE_FILTER] | ||
async requestDevice( | ||
filters: AdbDeviceFilter[] = [ADB_DEFAULT_DEVICE_FILTER], | ||
): Promise<AdbDaemonWebUsbDevice | undefined> { | ||
if (filters.length === 0) { | ||
throw new TypeError("filters must not be empty"); | ||
} | ||
try { | ||
@@ -73,5 +77,9 @@ const device = await this.#usbManager.requestDevice({ | ||
*/ | ||
public async getDevices( | ||
filters: AdbDeviceFilter[] = [ADB_DEFAULT_DEVICE_FILTER] | ||
async getDevices( | ||
filters: AdbDeviceFilter[] = [ADB_DEFAULT_DEVICE_FILTER], | ||
): Promise<AdbDaemonWebUsbDevice[]> { | ||
if (filters.length === 0) { | ||
throw new TypeError("filters must not be empty"); | ||
} | ||
const devices = await this.#usbManager.getDevices(); | ||
@@ -111,5 +119,9 @@ return devices | ||
(device) => | ||
new AdbDaemonWebUsbDevice(device, filters, this.#usbManager) | ||
new AdbDaemonWebUsbDevice( | ||
device, | ||
filters, | ||
this.#usbManager, | ||
), | ||
); | ||
} | ||
} |
@@ -21,3 +21,3 @@ export function isErrorName(e: unknown, name: string): boolean { | ||
alternate: USBAlternateInterface, | ||
filters: AdbDeviceFilter[] | ||
filters: AdbDeviceFilter[], | ||
) { | ||
@@ -28,3 +28,3 @@ return filters.some( | ||
alternate.interfaceSubclass === filter.subclassCode && | ||
alternate.interfaceProtocol === filter.protocolCode | ||
alternate.interfaceProtocol === filter.protocolCode, | ||
); | ||
@@ -35,3 +35,3 @@ } | ||
device: USBDevice, | ||
filters: AdbDeviceFilter[] | ||
filters: AdbDeviceFilter[], | ||
) { | ||
@@ -38,0 +38,0 @@ for (const configuration of device.configurations) { |
@@ -5,25 +5,25 @@ export class AdbDaemonWebUsbDeviceWatcher { | ||
public constructor(callback: (newDeviceSerial?: string) => void, usb: USB) { | ||
constructor(callback: (newDeviceSerial?: string) => void, usb: USB) { | ||
this.#callback = callback; | ||
this.#usbManager = usb; | ||
this.#usbManager.addEventListener("connect", this.handleConnect); | ||
this.#usbManager.addEventListener("disconnect", this.handleDisconnect); | ||
this.#usbManager.addEventListener("connect", this.#handleConnect); | ||
this.#usbManager.addEventListener("disconnect", this.#handleDisconnect); | ||
} | ||
public dispose(): void { | ||
this.#usbManager.removeEventListener("connect", this.handleConnect); | ||
dispose(): void { | ||
this.#usbManager.removeEventListener("connect", this.#handleConnect); | ||
this.#usbManager.removeEventListener( | ||
"disconnect", | ||
this.handleDisconnect | ||
this.#handleDisconnect, | ||
); | ||
} | ||
private handleConnect = (e: USBConnectionEvent) => { | ||
#handleConnect = (e: USBConnectionEvent) => { | ||
this.#callback(e.device.serialNumber); | ||
}; | ||
private handleDisconnect = () => { | ||
#handleDisconnect = () => { | ||
this.#callback(); | ||
}; | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
91459
32
1125
+ Added@yume-chan/adb@0.0.21(transitive)
+ Added@yume-chan/dataview-bigint-polyfill@0.0.21(transitive)
+ Added@yume-chan/event@0.0.21(transitive)
+ Added@yume-chan/stream-extra@0.0.21(transitive)
+ Added@yume-chan/struct@0.0.21(transitive)
- Removed@yume-chan/adb@0.0.20(transitive)
- Removed@yume-chan/dataview-bigint-polyfill@0.0.20(transitive)
- Removed@yume-chan/event@0.0.20(transitive)
- Removed@yume-chan/stream-extra@0.0.20(transitive)
- Removed@yume-chan/struct@0.0.20(transitive)
Updated@yume-chan/adb@^0.0.21
Updated@yume-chan/struct@^0.0.21
Updatedtslib@^2.6.0