UNPKG

2.82 kBJavaScriptView Raw
1"use strict";
2var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3 var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4 if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5 else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6 return c > 3 && r && Object.defineProperty(target, key, r), r;
7};
8var plugin_1 = require('./plugin');
9var Observable_1 = require('rxjs/Observable');
10/**
11 * @name Gyroscope
12 * @description Read Gyroscope sensor data
13 * @usage
14 * ```
15 * import { Gyroscope, GyroscopeOrientation, GyroscopeOptions } from 'ionic-native';
16 *
17 *
18 * let options: GyroscopeOptions = {
19 * frequency: 1000
20 * };
21 *
22 * Gyroscope.getCurrent(options)
23 * .then((orientation: GyroscopeOrientation) => {
24 * console.log(orientation.x, orientation.y, orientation.z, orientation.timestamp);
25 * })
26 * .catch()
27 *
28 *
29 * Gyroscope.watch()
30 * .subscribe((orientation: GyroscopeOrientation) => {
31 * console.log(orientation.x, orientation.y, orientation.z, orientation.timestamp);
32 * });
33 *
34 * ```
35 */
36var Gyroscope = (function () {
37 function Gyroscope() {
38 }
39 /**
40 * Watching for gyroscope sensor changes
41 * @param options {GyroscopeOptions} (optional)
42 * @return {Observable<GyroscopeOrientation>} Returns an Observable that resolves GyroscopeOrientation
43 */
44 Gyroscope.watch = function (options) {
45 return new Observable_1.Observable(function (observer) {
46 var watchId = navigator.gyroscope.watch(observer.next.bind(observer), observer.next.bind(observer), options);
47 return function () { return navigator.gyroscope.clearWatch(watchId); };
48 });
49 };
50 /**
51 * Get current data from gyroscope sensor
52 * @param options {GyroscopeOptions} (optional)
53 * @return {Promise<GyroscopeOrientation>} Returns a promise that resolves GyroscopeOrientation
54 */
55 Gyroscope.getCurrent = function (options) { return; };
56 __decorate([
57 plugin_1.Cordova({
58 callbackOrder: 'reverse'
59 })
60 ], Gyroscope, "getCurrent", null);
61 Gyroscope = __decorate([
62 plugin_1.Plugin({
63 pluginName: 'Gyroscope',
64 plugin: 'cordova-plugin-gyroscope',
65 pluginRef: 'navigator.gyroscope',
66 repo: 'https://github.com/NeoLSN/cordova-plugin-gyroscope',
67 platforms: ['Android', 'iOS']
68 })
69 ], Gyroscope);
70 return Gyroscope;
71}());
72exports.Gyroscope = Gyroscope;
73//# sourceMappingURL=gyroscope.js.map
\No newline at end of file