Gaze (Preview)
The Gaze API provides eye tracking details for supported platforms.
const gaze = require('gaze-preview');
Gaze Types
There are two types of gaze: glance and focus. Glance is used to describe an element currently being looked at by a user, while focus is when a user's eyes remain settled on an element. Both types can be refered to via the gaze.types
object. [Currently, only types.Glance
is supported]
Registration
Before we can capture gaze events, we need to register elements for gaze tracking.
var self = this;
gaze.register(self, gaze.types.Glance);
Events
Subscribe to Gaze events directly from the element. The event handlers receive no parameters. Instead, poll the gaze object's state. Handlers should be unregistered with the off
method when no longer needed.
this.on('focusupdated', onFocusUpdated);
function onFocusUpdated() {
var dir = gaze.glanceDirection;
//
}
this.off('focusstopped');
Module Events
"glancestarted"
"glanceupdated"
"glancestopped"
"focusstarted"
[Not yet supported]"focusupdated"
[Not yet supported]"focusstopped"
[Not yet supported]
Module Properties
types.Focus <int>
[Read Only] [Not yet supported]
Constant representing the Focus gaze type. Its value is 0
types.Glance <int>
[Read Only]
Constant representing the Glance gaze type. Its value is 1
glanceDirection <vec3>
[Read Only]
The direction the user is currently looking
Module Methods
register(element, type)
element <Element>
The element to be tracked.type <int>
The type of gaze to register, corresponding totypes.Focus
ortypes.Glance
above.
Notifies the eye gaze services to test wether the provided element is receiving the user's glance or focus.
unregister(element, type)
element <Element>
The element that should no longer be tracked.type <int>
The type of gaze previously registered, eithertpyes.Focus
or types.Glance`.
After removing registration, the gaze service will no longer test whether the element received the user's focus or glance.