Skip to content

Conversation

@liminzhu
Copy link
Member

Explainer to add haptics capabilities to the web and this is in the early interest-gauging phase and trying to not over-design just yet. The current approach is to expand the navigator.vibrate API available on mobile, but very much open to suggestions to have a fresh API instead.

draggable.style.top = `${tRect.top}px`;
// Trigger the haptic feedback
if ("vibrate" in navigator) {
navigator.vibrate(0, {waveform: 'align', intensity: 1});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

navigator.vibrate(0, {waveform: 'align', intensity: 1});

Forcing the developer to always pass 0 for the first argument does not seem ideal. The first argument is supposed to be duration. Perhaps a better API shape would overload the existing function or create a new function to accept a single dictionary argument. I'd vote for a new function to make this feature detectable and also return a Promise<boolean> or void.


Relevant web APIs:
- [navigator.vibrate](https://developer.mozilla.org/en-US/docs/Web/API/Navigator/vibrate)
- [(In-progress) Gamepad Event-Driven Input API](https://github.com/MicrosoftEdge/MSEdgeExplainers/blob/6ea0b9190c7e8b0261323deaf060013d80a0b0ab/GamepadEventDrivenInputAPI/explainer.md)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure how the "Gamepad Event-Driven Input API" relates to haptics. What did you have in mind?

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.

2 participants