Skip to main content

Haptics

Beta

Haptics are in beta. The iPhone support relies on how iOS plays the native switch tick, which Apple could change in a future iOS release.

Vibrate​

JestSDK.haptics.vibrate(pattern)

Same as the browser's navigator.vibrate(): pattern is a duration in milliseconds or an array of alternating vibrate and pause durations, 0 cancels, and it returns true when the request was accepted. Unlike navigator.vibrate(), it also works on iPhone.

canvas.addEventListener("pointerdown", () => {
JestSDK.haptics.vibrate(10);
});

Haptics are best effort. A phone in silent, Do Not Disturb or battery-saving mode, or with haptics turned off, may not vibrate even when the call returns true. If nothing vibrates while you test, check those first.

iPhone​

iPhone has no vibration API. Instead, the SDK plays the system's native tick when the player lifts their finger from a tap on your game canvas:

  • The tick ignores the pattern: there is one strength and no duration.
  • Only a call made during a tap counts: while the finger is down, or synchronously in your canvas touchend, pointerup or click handler. Calls from timers, or from input your engine handles on a later frame, do nothing. In Unity, call it from the frame that sees the touch begin.
  • Drags and multi-finger gestures don't tick.

To make this work, the first vibrate() call places an invisible layer over your canvas, so the first tap never ticks. The layer passes the player's touches on to the canvas as copies. Keep in mind:

  • Load the SDK before your engine adds its input listeners, so those listeners only see the copies.
  • isTrusted is false on the copies.
  • The layer sits right after the canvas, so selectors such as canvas + .hud stop matching.

If your game doesn't work with the layer, skip vibrate() on iPhone:

if (JestSDK.haptics.getCapability() !== "tap") {
JestSDK.haptics.vibrate(10);
}

Check the capability​

JestSDK.haptics.getCapability() (Unity: JestSDK.Instance.Haptics.GetCapability())

  • "vibrate" (HapticsCapability.Vibrate): the browser has navigator.vibrate (Android, and desktop Chromium, which has nothing to vibrate).
  • "tap" (HapticsCapability.Tap): iPhone on iOS 18 or later.
  • "none" (HapticsCapability.None): no haptics (Safari and Firefox on desktop, older iOS).

You don't need to check it before calling vibrate(). Haptics run on the device, so mock mode behaves like production.