UNPKG

shuttle-webhid

Version:

An npm module for interfacing with the Contour Shuttle devices in Node.js

46 lines 1.9 kB
"use strict"; /* eslint-disable n/no-unsupported-features/node-builtins */ Object.defineProperty(exports, "__esModule", { value: true }); exports.requestAccess = requestAccess; exports.getOpenedDevices = getOpenedDevices; exports.setupShuttle = setupShuttle; const core_1 = require("@shuttle-lib/core"); const web_hid_wrapper_js_1 = require("./web-hid-wrapper.js"); /** Prompts the user for which Shuttle device to select */ async function requestAccess() { return navigator.hid.requestDevice({ filters: Object.values(core_1.PRODUCTS).map((product) => ({ vendorId: product.vendorId, productId: product.productId, })), }); } /** * Reopen previously selected devices. * The browser remembers what the user previously allowed your site to access, and this will open those without the request dialog */ async function getOpenedDevices() { return await navigator.hid.getDevices(); } /** Sets up a connection to a HID device (the Shuttle device) */ async function setupShuttle(browserDevice) { var _a; if (!((_a = browserDevice === null || browserDevice === void 0 ? void 0 : browserDevice.collections) === null || _a === void 0 ? void 0 : _a.length)) throw Error(`device collections is empty`); if (!browserDevice.productId) throw Error(`Device has no productId!`); if (!browserDevice.opened) { await browserDevice.open(); } const deviceWrap = new web_hid_wrapper_js_1.WebHIDDevice(browserDevice); const shuttle = new core_1.Shuttle(deviceWrap, { product: browserDevice.productName, vendorId: browserDevice.vendorId, productId: browserDevice.productId, interface: null, // todo: Check what to use here (collection.usage?) }, undefined); // Wait for the device to initialize: await shuttle.init(); return shuttle; } //# sourceMappingURL=methods.js.map