Skip to content

[web / node] Ability to wait for the watcher initial device sweep to have completed #123

Description

@loucadufault

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions