Skip to content

Forward HIDInputReportEvent.timeStamp to button listeners - #59

Open
mouadennasri wants to merge 1 commit into
GoogleChromeLabs:mainfrom
mouadennasri:forward-inputreport-timestamp
Open

Forward HIDInputReportEvent.timeStamp to button listeners#59
mouadennasri wants to merge 1 commit into
GoogleChromeLabs:mainfrom
mouadennasri:forward-inputreport-timestamp

Conversation

@mouadennasri

@mouadennasri mouadennasri commented Apr 30, 2026

Copy link
Copy Markdown

Problem

Consumers of this library running real-time audio routing on top of HID button input need to know when the user actually pressed the button, not when the JS handler eventually ran.

Under main-thread starvation (long React renders, focus handlers, etc.) the inputreport event sits in the browser event queue for hundreds of ms before dispatch. Today the event's timeStamp is read off event.data and discarded inside onInputReport/handleButtonPress, so the ButtonEventListener callback has no way to recover the press time.

Symptom: under load, every nav appears to happen "now" (handler-fire time), so any logic that correlates HID input with audio frames (speech onset, transcription windows, etc.) misroutes when the queue delay exceeds the audio window. DOM events (keydown, pointerdown, etc.) all expose event.timeStamp natively, so HID is the only input modality where queue-aware back-dating isn't possible today.

Change

Forward event.timeStamp from the underlying HIDInputReportEvent through handleButtonPress to each ButtonEventListener, as a third positional argument:

export type ButtonEventListener = (
  device: DictationDevice,
  bitMask: ButtonEvent,
  eventTimeStamp: number,  // ← new
) => void | Promise<void>;

Touched: dictation_device_base.ts, speechmike_hid_device.ts (override + proxy-device propagation path).

Compatibility

The added parameter is positional and additive. Existing ButtonEventListener implementations that take (device, bitMask) are still assignable to the new type — TypeScript permits assigning a fewer-arg function where more-arg is expected, and JavaScript ignores extra arguments at runtime. No call site update is required for consumers that don't need the timestamp.

Tests

Updated check_button_mapping to assert the new arg via jasmine.any(Number). Added an explicit eventTimeStamp value to the SpeechMike proxy-device propagation test so the forwarded value is verified end-to-end. Webpack build compiles cleanly.

@google-cla

google-cla Bot commented Apr 30, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant