@ginden/blinkstick-v2
Version:
Improved Blickstick API for Node.js
26 lines • 1.26 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.createBlinkstickAsync = createBlinkstickAsync;
const node_hid_1 = require("node-hid");
const blinkstick_finalization_registry_1 = require("../../core/blinkstick-finalization-registry");
const blinkstick_async_1 = require("../../core/blinkstick.async");
/**
* This function creates a BlinkStick object from a USB device.
* It also registers the BlinkStick object in a FinalizationRegistry to increase chance that the device will be closed
* when the object is garbage collected.
*
* This function is unlikely to be needed by end users, but you are an adult.
*
* @param device
* @category Discovery
*/
async function createBlinkstickAsync(device) {
const hidDevice = device.path
? await node_hid_1.HIDAsync.open(device.path)
: await node_hid_1.HIDAsync.open(device.vendorId, device.productId);
const blinkstick = new blinkstick_async_1.BlinkstickAsync(hidDevice, await hidDevice.getDeviceInfo());
const hidTransport = blinkstick.getTransport();
blinkstick_finalization_registry_1.blinkstickFinalizationRegistry.register(blinkstick, hidTransport, blinkstick);
return blinkstick;
}
//# sourceMappingURL=create-blinkstick-async.js.map