Body-presence API
chevron down
 

Body-presence API

Variable: BodyPresenceSensor

Type: [IBodyPresenceSensor | undefined]

Interface: IBodyPresenceSensor

New in SDK 2.0

The BodyPresenceSensor API is used to determine whether the device is on the user's wrist or not.

Note, unlike other sensors, the body presence sensor does not allow a developer to set its frequency.

import { BodyPresenceSensor } from "body-presence";

if (BodyPresenceSensor) {
   console.log("This device has a BodyPresenceSensor!");
   const bodyPresence = new BodyPresenceSensor();
   bodyPresence.addEventListener("reading", () => {
     console.log(`The device is ${bodyPresenceSensor.present ? '' : 'not'} on the user's body.`);
   });
   bodyPresence.start();
} else {
   console.log("This device does NOT have a BodyPresenceSensor!");
}

Properties

readonly activated

boolean

Flag that indicates if the sensor is activated or not. When a sensor is created, the sensor is not activated, thus the initial value of this property equals false.

onactivate

((this: Sensor, event: Event) => any) or undefined

Event handler that is called when the sensor is activated.

onerror

((this: Sensor, event: SensorErrorEvent) => any) or undefined

Event handler that is called when an error occurs. When an error occurs, the sensor is automatically stopped, and the activated property equals false.

onreading

((this: Sensor, event: Event) => any) or undefined

Event handler that is called whenever a new reading is available.

readonly present

boolean

Indicates whether a users body is present, or not.