@xkeys-lib/core
Version:
NPM package to interact with the X-keys panels
60 lines • 2.99 kB
TypeScript
/// <reference types="node" />
import { EventEmitter } from 'events';
import { XKeys } from './xkeys';
export interface XKeysWatcherOptions {
/**
* This activates the "Automatic UnitId mode", which enables several features:
* First, any x-keys panel with unitId===0 will be issued a (pseudo unique) unitId upon connection, in order for it to be uniquely identified.
* This allows for the connection-events to work a bit differently, mainly enabling the "reconnected"-event for when a panel has been disconnected, then reconnected again.
*/
automaticUnitIdMode?: boolean;
/** If set, will use polling for devices instead of watching for them directly. Might be a bit slower, but is more compatible. */
usePolling?: boolean;
/** If usePolling is set, the interval to use for checking for new devices. */
pollingInterval?: number;
}
export interface XKeysWatcherEvents {
connected: (xkeysPanel: XKeys) => void;
error: (err: any) => void;
}
export declare interface GenericXKeysWatcher<HID_Identifier> {
on<U extends keyof XKeysWatcherEvents>(event: U, listener: XKeysWatcherEvents[U]): this;
emit<U extends keyof XKeysWatcherEvents>(event: U, ...args: Parameters<XKeysWatcherEvents[U]>): boolean;
}
/**
* Set up a watcher for newly connected X-keys panels.
* Note: It is highly recommended to set up a listener for the disconnected event on the X-keys panel, to clean up after a disconnected device.
*/
export declare abstract class GenericXKeysWatcher<HID_Identifier> extends EventEmitter {
private _options?;
private updateConnectedDevicesTimeout;
private updateConnectedDevicesIsRunning;
private updateConnectedDevicesRunAgain;
private seenDevices;
private setupXkeys;
/** A value that is incremented whenever we expect to find a new or removed device in updateConnectedDevices(). */
private shouldFindChangedReTries;
protected isActive: boolean;
debug: boolean;
/** A list of the devices we've called setupNewDevice() for */
private prevConnectedIdentifiers;
/** Unique unitIds grouped into productId groups. */
private uniqueIds;
constructor(_options?: XKeysWatcherOptions | undefined);
protected get options(): Required<XKeysWatcherOptions>;
/**
* Stop the watcher
* @param closeAllDevices Set to false in order to NOT close all devices. Use this if you only want to stop the watching. Defaults to true
*/
stop(closeAllDevices?: boolean): Promise<void>;
protected triggerUpdateConnectedDevices(somethingWasAddedOrRemoved: boolean): void;
protected abstract getConnectedDevices(): Promise<Set<HID_Identifier>>;
protected abstract setupXkeysPanel(device: HID_Identifier): Promise<XKeys>;
private updateConnectedDevices;
private handleNewDevice;
private handleRemovedDevice;
private setupNewDevice;
private _getNextUniqueId;
protected debugLog(...args: any[]): void;
}
//# sourceMappingURL=watcher.d.ts.map