Use [Direct Sockets API](https://wicg.github.io/direct-sockets/) 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 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.
Note: Direct Sockets API is still under development. Currently it's only available in Chrome and requires extra command line arguments to enable. This package is not ready to be used in production, thus not published to NPM registry.
Backend for `@yume-chan/adb` using WebUSB ([MDN](https://developer.mozilla.org/en-US/docs/Web/API/USB), [Spec](https://wicg.github.io/webusb)) API.
Backend for `@yume-chan/adb` using WebUSB ([MDN](https://developer.mozilla.org/en-US/docs/Web/API/USB), [Spec](https://wicg.github.io/webusb)) API.
-[Note](#note)
-[Note](#note)
-[`pickDevice`](#pickdevice)
-[Use in Node.js](#use-in-nodejs)
-[`fromDevice`](#fromdevice)
-[API](#api)
-[Constructor](#constructor)
-[`isSupported()`](#issupported)
-[`requestDevice`](#requestdevice)
-[`connect`](#connect)
-[`connect`](#connect)
## Note
## Note
WebUSB API requires [secure context](https://developer.mozilla.org/en-US/docs/Web/Security/Secure_Contexts)(basically means HTTPS).
WebUSB API requires [secure context](https://developer.mozilla.org/en-US/docs/Web/Security/Secure_Contexts)(HTTPS).
Chrome will treat `localhost` as secure, but if you want to access a dev server running on another machine, you need to add the domain to the allowlist:
Chrome will treat `localhost` as secure, but if you want to access a dev server running on another machine, follow the steps to add the domain name to allowlist:
1. Open `chrome://flags/#unsafely-treat-insecure-origin-as-secure`
1. Open `chrome://flags/#unsafely-treat-insecure-origin-as-secure`
2. Add the protocol and domain part of your url (e.g. `http://192.168.0.100:9000`) to the input box
2. Add the protocol and domain part of your url (e.g. `http://192.168.0.100:9000`) to the input box
3. Choose `Enable` from the dropdown menu
3. Choose `Enable` from the dropdown menu
4. Restart your browser
4. Restart browser
## `pickDevice`
## Use in Node.js
Node.js doesn't support WebUSB API, but you might be able to use this package with the [`usb`](https://www.npmjs.com/package/usb) package (I didn't test this. If you have any results, please open a discussion to share with us).
All static methods will not work, but the constructor only requires an object that's structurally compatible with `USBDevice` interface. The `WebUSBDevice` class in `usb` package should satisfy this requirement.
Request browser to present a list of connected Android devices to let the user choose from.
Create a new instance of `AdbWebBackend` using a `USBDevice` instance you already have.
Returns `undefined` if the user canceled the picker.
`USBDevice` type is from WebUSB API.
## `fromDevice`
The `filters` parameter specifies the `classCode`, `subclassCode` and `protocolCode` to use when searching for ADB interface. The default value is `[{ classCode: 0xff, subclassCode: 0x42, protocolCode: 0x1 }]`, defined by Google.
Request access to a connected device from browser. The browser will display a list of devices to the user and let them choose one.
Only available in browsers that support WebUSB API (When `isSupported()` returns `true`).
The `filters` parameter must have `classCode`, `subclassCode` and `protocolCode` fields for selecting the ADB interface. It can also have `vendorId`, `productId` or `serialNumber` fields to limit the displayed device list.
Returns an `AdbWebUsbBackend` instance, or `undefined` if the user cancelled the picker.
* Create a new instance of `AdbWebBackend` using a `USBDevice` instance you already have.
*
* @param device The `USBDevice` instance you already have.
* @param filters The filters to use when searching for ADB interface. The default value is `[{ classCode: 0xff, subclassCode: 0x42, protocolCode: 0x1 }]`, defined by Google.