Motivation
With more than one XKeys device remembered by the browser, on page load the HID object fires multiple connect events for each one. However, the timing between these events means there is a delay (where other code can run) even though the devices are all connected from the start of the app.
With the current Watcher API, it makes it difficult for the app to consider the set of initially connected devices at startup. The workaround would be to expect a certain number of connect events (if the expected number of devices is known), or to wait a small delay to capture all the initial connect events (probably 100ms would suffice).
Proposal
However, a better approach would be to be able to request from the library the initial set. The watcher abstract contract already requires:
|
protected abstract getConnectedDevices(): Promise<Set<HID_Identifier>> |
|
protected abstract setupXkeysPanel(device: HID_Identifier): Promise<XKeys> |
We can thus add a public method to the abstract Watcher to:
public async getConnectedPanels(): Promise<XKeys> {
// call `this.getConnectedDevices()` and map through `this.setupXkeysPanel()`
}
This would also allow the usage of requesting the panels from the Watcher on demand (rather than keeping track via watcher events). It's obviously possible to do so with the more fundamental library API, but doing so via watcher will keep my application code simpler.
Motivation
With more than one XKeys device remembered by the browser, on page load the
HIDobject fires multipleconnectevents for each one. However, the timing between these events means there is a delay (where other code can run) even though the devices are all connected from the start of the app.With the current Watcher API, it makes it difficult for the app to consider the set of initially connected devices at startup. The workaround would be to expect a certain number of
connectevents (if the expected number of devices is known), or to wait a small delay to capture all the initialconnectevents (probably 100ms would suffice).Proposal
However, a better approach would be to be able to request from the library the initial set. The watcher abstract contract already requires:
xkeys/packages/core/src/watcher.ts
Lines 124 to 125 in 3830730
We can thus add a public method to the abstract
Watcherto:This would also allow the usage of requesting the panels from the Watcher on demand (rather than keeping track via watcher events). It's obviously possible to do so with the more fundamental library API, but doing so via watcher will keep my application code simpler.