1 | import { SyntheticPlatformEmitter } from '@unimodules/core';
|
2 |
|
3 | import { isSensorEnabledAsync } from './utils/isSensorEnabledAsync.web';
|
4 |
|
5 | const eventName = 'devicemotion';
|
6 |
|
7 | export default {
|
8 | get name(): string {
|
9 | return 'ExponentGyroscope';
|
10 | },
|
11 | async isAvailableAsync(): Promise<boolean> {
|
12 | if (typeof DeviceMotionEvent === 'undefined') {
|
13 | return false;
|
14 | }
|
15 | return await isSensorEnabledAsync(eventName);
|
16 | },
|
17 | _handleMotion({ accelerationIncludingGravity }) {
|
18 | SyntheticPlatformEmitter.emit('gyroscopeDidUpdate', {
|
19 | x: accelerationIncludingGravity.x,
|
20 | y: accelerationIncludingGravity.y,
|
21 | z: accelerationIncludingGravity.z,
|
22 | });
|
23 | },
|
24 | startObserving() {
|
25 | window.addEventListener(eventName, this._handleMotion);
|
26 | },
|
27 | stopObserving() {
|
28 | window.removeEventListener(eventName, this._handleMotion);
|
29 | },
|
30 | };
|