UNPKG

@logitech-mx-creative-console/webhid

Version:

An npm module for interfacing with the Logitech MX Creative Console in the browser

49 lines 1.74 kB
import { EventEmitter } from 'eventemitter3'; import Queue from 'p-queue'; /** * The wrapped browser HIDDevice. * This translates it into the common format expected by @logitech-mx-creative-console/core */ export class WebHIDDevice extends EventEmitter { device; reportQueue = new Queue({ concurrency: 1 }); constructor(device) { super(); this.device = device; // this.device.on('data', data => this.emit('data', data)) // this.device.on('error', error => this.emit('error', error)) this.device.addEventListener('inputreport', (event) => { const data = new Uint8Array(event.data.buffer, event.data.byteOffset, event.data.byteLength); this.emit('input', event.reportId, data); }); } async close() { return this.device.close(); } async forget() { return this.device.forget(); } async sendFeatureReport(data) { return this.device.sendFeatureReport(data[0], data.subarray(1)); } async getFeatureReport(reportId, _reportLength) { const view = await this.device.receiveFeatureReport(reportId); return new Uint8Array(view.buffer, view.byteOffset, view.byteLength); } async sendReports(buffers) { return this.reportQueue.add(async () => { for (const data of buffers) { await this.device.sendReport(data[0], data.subarray(1)); } }); } async getDeviceInfo() { return { path: undefined, productId: this.device.productId, vendorId: this.device.vendorId, serialNumber: undefined, // TODO - not supported? }; } } //# sourceMappingURL=hid-device.js.map