Skip to content

Sensors ​

Mini Apps support access to the device's accelerometer, gyroscope, and orientation sensors. All sensor APIs require Bot API 8.0+.

Accelerometer ​

The accelerometer measures device acceleration along three axes (including gravity). Accessed via aiaxchat.WebApp.Accelerometer.

Properties ​

PropertyTypeDescription
isStartedBooleanWhether the accelerometer is currently collecting data
xFloatX-axis acceleration (m/s²)
yFloatY-axis acceleration (m/s²)
zFloatZ-axis acceleration (m/s²)

Methods ​

start ​

javascript
aiaxchat.WebApp.Accelerometer.start(params, callback)

Starts collecting acceleration data.

ParameterTypeRequiredDescription
paramsObjectNoStart parameters
params.refresh_rateIntegerNoRefresh rate in ms, default 1000, range 20-1000
callbackFunctionNoCallback with (started) parameter

stop ​

javascript
aiaxchat.WebApp.Accelerometer.stop(callback)

Stops collecting acceleration data.

ParameterTypeRequiredDescription
callbackFunctionNoCallback with (stopped) parameter

Example ​

javascript
const accel = aiaxchat.WebApp.Accelerometer;

accel.start({ refresh_rate: 100 }, (started) => {
  if (started) {
    console.log('Accelerometer started');
  }
});

aiaxchat.WebApp.onEvent('accelerometerChanged', () => {
  console.log(`X: ${accel.x}, Y: ${accel.y}, Z: ${accel.z}`);
});

// Stop collecting
// accel.stop();

DeviceOrientation ​

The device orientation sensor provides information about the device's orientation in 3D space. Accessed via aiaxchat.WebApp.DeviceOrientation.

Properties ​

PropertyTypeDescription
isStartedBooleanWhether the sensor is currently collecting data
absoluteBooleanWhether the orientation data is absolute (relative to Earth's coordinate system)
alphaFloatZ-axis rotation angle (0-360°)
betaFloatX-axis rotation angle (-180° to 180°)
gammaFloatY-axis rotation angle (-90° to 90°)

Methods ​

start ​

javascript
aiaxchat.WebApp.DeviceOrientation.start(params, callback)

Starts collecting device orientation data.

ParameterTypeRequiredDescription
paramsObjectNoStart parameters
params.refresh_rateIntegerNoRefresh rate in ms, default 1000, range 20-1000
params.need_absoluteBooleanNoWhether absolute orientation data is needed, default false
callbackFunctionNoCallback with (started) parameter

stop ​

javascript
aiaxchat.WebApp.DeviceOrientation.stop(callback)

Stops collecting device orientation data.

ParameterTypeRequiredDescription
callbackFunctionNoCallback with (stopped) parameter

Example ​

javascript
const orientation = aiaxchat.WebApp.DeviceOrientation;

orientation.start({
  refresh_rate: 100,
  need_absolute: true
}, (started) => {
  if (started) {
    console.log('Device orientation sensor started');
  }
});

aiaxchat.WebApp.onEvent('deviceOrientationChanged', () => {
  console.log(`Alpha: ${orientation.alpha}`);
  console.log(`Beta: ${orientation.beta}`);
  console.log(`Gamma: ${orientation.gamma}`);
  console.log(`Absolute: ${orientation.absolute}`);
});

Gyroscope ​

The gyroscope measures the angular velocity of the device along three axes. Accessed via aiaxchat.WebApp.Gyroscope.

Properties ​

PropertyTypeDescription
isStartedBooleanWhether the gyroscope is currently collecting data
xFloatX-axis angular velocity (rad/s)
yFloatY-axis angular velocity (rad/s)
zFloatZ-axis angular velocity (rad/s)

Methods ​

start ​

javascript
aiaxchat.WebApp.Gyroscope.start(params, callback)

Starts collecting gyroscope data.

ParameterTypeRequiredDescription
paramsObjectNoStart parameters
params.refresh_rateIntegerNoRefresh rate in ms, default 1000, range 20-1000
callbackFunctionNoCallback with (started) parameter

stop ​

javascript
aiaxchat.WebApp.Gyroscope.stop(callback)

Stops collecting gyroscope data.

ParameterTypeRequiredDescription
callbackFunctionNoCallback with (stopped) parameter

Example ​

javascript
const gyro = aiaxchat.WebApp.Gyroscope;

gyro.start({ refresh_rate: 50 }, (started) => {
  if (started) {
    console.log('Gyroscope started');
  }
});

aiaxchat.WebApp.onEvent('gyroscopeChanged', () => {
  console.log(`Angular velocity X: ${gyro.x}, Y: ${gyro.y}, Z: ${gyro.z}`);
});

Notes ​

  • All sensor APIs require Bot API 8.0+
  • Not all devices support sensors. Listen for the corresponding *Failed events to handle unsupported cases
  • Call stop() when done to release sensor resources and save battery
  • Lower refresh_rate values mean more frequent updates but higher power consumption