Move navigator.usb.requestDevice to package

This commit is contained in:
ICheered
2023-08-04 17:59:42 +02:00
parent f93004f8e7
commit 8b10757e92
3 changed files with 53 additions and 31 deletions

View File

@@ -40,6 +40,9 @@ export function rethrowIfCritical(err) {
}
}
const INTERFACE_CLASS = 6; // PTP
const INTERFACE_SUBCLASS = 1; // MTP
class Camera {
constructor() {
/** @type {Promise<unknown>} */
@@ -49,6 +52,18 @@ class Camera {
this.ModulePromise = null;
}
async showCameraPicker() {
// @ts-ignore
await navigator.usb.requestDevice({
filters: [
{
classCode: INTERFACE_CLASS,
subclassCode: INTERFACE_SUBCLASS,
},
],
});
}
async connect() {
if (!this.ModulePromise) {
this.ModulePromise = initializeModule().then((initModule) => {