@capawesome/capacitor-gyroscope 0.0.1 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # @capawesome/capacitor-gyroscope
1
+ # Capacitor Gyroscope Plugin
2
2
 
3
3
  Capacitor plugin to read the device's gyroscope sensor.
4
4
 
@@ -10,7 +10,7 @@ Capacitor plugin to read the device's gyroscope sensor.
10
10
 
11
11
  ## Features
12
12
 
13
- We are proud to offer one of the most complete and feature-rich Capacitor plugins for gyroscope measurements. Here are some of the key features:
13
+ The Capacitor Gyroscope plugin is one of the most complete motion sensing solutions for Capacitor apps. Here are some of the key features:
14
14
 
15
15
  - 🖥️ **Cross-platform**: Supports Android and iOS.
16
16
  - ⚡ **Real-time measurements**: Continuous gyroscope data with event listeners.
@@ -18,13 +18,18 @@ We are proud to offer one of the most complete and feature-rich Capacitor plugin
18
18
  - 🔒 **Permission handling**: Built-in permission management for sensor access.
19
19
  - 📦 **CocoaPods & SPM**: Supports CocoaPods and Swift Package Manager for iOS.
20
20
  - 🔁 **Up-to-date**: Always supports the latest Capacitor version.
21
- - 🔗 **Compatibility**: Works alongside the [Accelerometer](https://capawesome.io/plugins/accelerometer/), [Barometer](https://capawesome.io/plugins/barometer/) and [Pedometer](https://capawesome.io/plugins/pedometer/) plugins.
21
+ - 🤝 **Compatibility**: Works alongside the [Accelerometer](https://capawesome.io/docs/sdks/capacitor/accelerometer/), [Barometer](https://capawesome.io/docs/sdks/capacitor/barometer/) and [Pedometer](https://capawesome.io/docs/sdks/capacitor/pedometer/) plugins.
22
22
 
23
23
  Missing a feature? Just [open an issue](https://github.com/capawesome-team/capacitor-plugins/issues) and we'll take a look!
24
24
 
25
- ## Newsletter
25
+ ## Use Cases
26
26
 
27
- Stay up to date with the latest news and updates about the Capawesome, Capacitor, and Ionic ecosystem by subscribing to our [Capawesome Newsletter](https://cloud.capawesome.io/newsletter/).
27
+ The Gyroscope plugin is typically used whenever an app needs to react to the rotation of the device, for example:
28
+
29
+ - **Motion-controlled games**: Use the real-time rotation rate to steer a character or vehicle by tilting the device.
30
+ - **Immersive experiences**: Rotate 360° views or augmented reality scenes based on the device's rotation.
31
+ - **Gesture detection**: Detect rotation gestures such as twisting the device to trigger actions in your app.
32
+ - **Motion analysis**: Record the rotation rate around the x, y, and z axes to analyze movement patterns.
28
33
 
29
34
  ## Compatibility
30
35
 
@@ -81,6 +86,25 @@ No configuration required for this plugin.
81
86
 
82
87
  ## Usage
83
88
 
89
+ The following examples show how to check if the gyroscope is available, get a single measurement, receive continuous measurement updates, check and request permissions, and remove all listeners.
90
+
91
+ ### Check if the gyroscope is available
92
+
93
+ Check whether the device has a gyroscope sensor before using the other methods:
94
+
95
+ ```typescript
96
+ import { Gyroscope } from '@capawesome/capacitor-gyroscope';
97
+
98
+ const isAvailable = async () => {
99
+ const result = await Gyroscope.isAvailable();
100
+ return result.available;
101
+ };
102
+ ```
103
+
104
+ ### Get a single measurement
105
+
106
+ Get the most recent measurement from the gyroscope sensor. The rotation rate around the x, y, and z axes is reported in radians per second (rad/s):
107
+
84
108
  ```typescript
85
109
  import { Gyroscope } from '@capawesome/capacitor-gyroscope';
86
110
 
@@ -90,11 +114,14 @@ const getMeasurement = async () => {
90
114
  console.log('Y: ', measurement.y);
91
115
  console.log('Z: ', measurement.z);
92
116
  };
117
+ ```
93
118
 
94
- const isAvailable = async () => {
95
- const result = await Gyroscope.isAvailable();
96
- return result.isAvailable;
97
- };
119
+ ### Receive continuous measurement updates
120
+
121
+ Add a listener for the `measurement` event and start the measurement updates to receive the rotation rate in real time. The `measurement` event is only available on Android and iOS:
122
+
123
+ ```typescript
124
+ import { Gyroscope } from '@capawesome/capacitor-gyroscope';
98
125
 
99
126
  const startMeasurementUpdates = async () => {
100
127
  await Gyroscope.addListener('measurement', measurement => {
@@ -108,6 +135,14 @@ const startMeasurementUpdates = async () => {
108
135
  const stopMeasurementUpdates = async () => {
109
136
  await Gyroscope.stopMeasurementUpdates();
110
137
  };
138
+ ```
139
+
140
+ ### Check and request permissions
141
+
142
+ Check and request the permission to access the gyroscope sensor:
143
+
144
+ ```typescript
145
+ import { Gyroscope } from '@capawesome/capacitor-gyroscope';
111
146
 
112
147
  const checkPermissions = async () => {
113
148
  const result = await Gyroscope.checkPermissions();
@@ -118,6 +153,14 @@ const requestPermissions = async () => {
118
153
  const result = await Gyroscope.requestPermissions();
119
154
  return result;
120
155
  };
156
+ ```
157
+
158
+ ### Remove all listeners
159
+
160
+ Remove all listeners when you no longer need them:
161
+
162
+ ```typescript
163
+ import { Gyroscope } from '@capawesome/capacitor-gyroscope';
121
164
 
122
165
  const removeAllListeners = async () => {
123
166
  await Gyroscope.removeAllListeners();
@@ -128,14 +171,14 @@ const removeAllListeners = async () => {
128
171
 
129
172
  <docgen-index>
130
173
 
131
- * [`addListener('measurement', ...)`](#addlistenermeasurement-)
132
174
  * [`checkPermissions()`](#checkpermissions)
133
175
  * [`getMeasurement()`](#getmeasurement)
134
176
  * [`isAvailable()`](#isavailable)
135
- * [`removeAllListeners()`](#removealllisteners)
136
177
  * [`requestPermissions()`](#requestpermissions)
137
178
  * [`startMeasurementUpdates()`](#startmeasurementupdates)
138
179
  * [`stopMeasurementUpdates()`](#stopmeasurementupdates)
180
+ * [`addListener('measurement', ...)`](#addlistenermeasurement-)
181
+ * [`removeAllListeners()`](#removealllisteners)
139
182
  * [Interfaces](#interfaces)
140
183
  * [Type Aliases](#type-aliases)
141
184
 
@@ -144,28 +187,6 @@ const removeAllListeners = async () => {
144
187
  <docgen-api>
145
188
  <!--Update the source file JSDoc comments and rerun docgen to update the docs below-->
146
189
 
147
- ### addListener('measurement', ...)
148
-
149
- ```typescript
150
- addListener(eventName: 'measurement', listenerFunc: (event: MeasurementEvent) => void) => Promise<PluginListenerHandle>
151
- ```
152
-
153
- Called when a new measurement is available.
154
-
155
- Only available on Android and iOS.
156
-
157
- | Param | Type |
158
- | ------------------ | ----------------------------------------------------------------------- |
159
- | **`eventName`** | <code>'measurement'</code> |
160
- | **`listenerFunc`** | <code>(event: <a href="#measurement">Measurement</a>) =&gt; void</code> |
161
-
162
- **Returns:** <code>Promise&lt;<a href="#pluginlistenerhandle">PluginListenerHandle</a>&gt;</code>
163
-
164
- **Since:** 0.1.0
165
-
166
- --------------------
167
-
168
-
169
190
  ### checkPermissions()
170
191
 
171
192
  ```typescript
@@ -213,19 +234,6 @@ Check if the gyroscope sensor is available on the device.
213
234
  --------------------
214
235
 
215
236
 
216
- ### removeAllListeners()
217
-
218
- ```typescript
219
- removeAllListeners() => Promise<void>
220
- ```
221
-
222
- Remove all listeners for this plugin.
223
-
224
- **Since:** 0.1.0
225
-
226
- --------------------
227
-
228
-
229
237
  ### requestPermissions()
230
238
 
231
239
  ```typescript
@@ -267,23 +275,42 @@ Stop emitting `measurement` events.
267
275
  --------------------
268
276
 
269
277
 
270
- ### Interfaces
278
+ ### addListener('measurement', ...)
271
279
 
280
+ ```typescript
281
+ addListener(eventName: 'measurement', listenerFunc: (event: MeasurementEvent) => void) => Promise<PluginListenerHandle>
282
+ ```
272
283
 
273
- #### PluginListenerHandle
284
+ Called when a new measurement is available.
274
285
 
275
- | Prop | Type |
276
- | ------------ | ----------------------------------------- |
277
- | **`remove`** | <code>() =&gt; Promise&lt;void&gt;</code> |
286
+ Only available on Android and iOS.
287
+
288
+ | Param | Type |
289
+ | ------------------ | ----------------------------------------------------------------------- |
290
+ | **`eventName`** | <code>'measurement'</code> |
291
+ | **`listenerFunc`** | <code>(event: <a href="#measurement">Measurement</a>) =&gt; void</code> |
278
292
 
293
+ **Returns:** <code>Promise&lt;<a href="#pluginlistenerhandle">PluginListenerHandle</a>&gt;</code>
279
294
 
280
- #### Measurement
295
+ **Since:** 0.1.0
281
296
 
282
- | Prop | Type | Description | Since |
283
- | ------- | ------------------- | ------------------------------------------------------------------ | ----- |
284
- | **`x`** | <code>number</code> | The rotation rate around the x-axis in radians per second (rad/s). | 0.1.0 |
285
- | **`y`** | <code>number</code> | The rotation rate around the y-axis in radians per second (rad/s). | 0.1.0 |
286
- | **`z`** | <code>number</code> | The rotation rate around the z-axis in radians per second (rad/s). | 0.1.0 |
297
+ --------------------
298
+
299
+
300
+ ### removeAllListeners()
301
+
302
+ ```typescript
303
+ removeAllListeners() => Promise<void>
304
+ ```
305
+
306
+ Remove all listeners for this plugin.
307
+
308
+ **Since:** 0.1.0
309
+
310
+ --------------------
311
+
312
+
313
+ ### Interfaces
287
314
 
288
315
 
289
316
  #### PermissionStatus
@@ -293,19 +320,30 @@ Stop emitting `measurement` events.
293
320
  | **`gyroscope`** | <code><a href="#gyroscopepermissionstate">GyroscopePermissionState</a></code> | The permission status of the gyroscope sensor. | 0.1.0 |
294
321
 
295
322
 
323
+ #### Measurement
324
+
325
+ | Prop | Type | Description | Since |
326
+ | ------- | ------------------- | ------------------------------------------------------------------ | ----- |
327
+ | **`x`** | <code>number</code> | The rotation rate around the x-axis in radians per second (rad/s). | 0.1.0 |
328
+ | **`y`** | <code>number</code> | The rotation rate around the y-axis in radians per second (rad/s). | 0.1.0 |
329
+ | **`z`** | <code>number</code> | The rotation rate around the z-axis in radians per second (rad/s). | 0.1.0 |
330
+
331
+
296
332
  #### IsAvailableResult
297
333
 
298
- | Prop | Type | Description | Since |
299
- | ----------------- | -------------------- | -------------------------------------------------------- | ----- |
300
- | **`isAvailable`** | <code>boolean</code> | Whether the gyroscope sensor is available on the device. | 0.1.0 |
334
+ | Prop | Type | Description | Since |
335
+ | --------------- | -------------------- | -------------------------------------------------------- | ----- |
336
+ | **`available`** | <code>boolean</code> | Whether the gyroscope sensor is available on the device. | 0.1.0 |
301
337
 
302
338
 
303
- ### Type Aliases
339
+ #### PluginListenerHandle
304
340
 
341
+ | Prop | Type |
342
+ | ------------ | ----------------------------------------- |
343
+ | **`remove`** | <code>() =&gt; Promise&lt;void&gt;</code> |
305
344
 
306
- #### MeasurementEvent
307
345
 
308
- <code><a href="#measurement">Measurement</a></code>
346
+ ### Type Aliases
309
347
 
310
348
 
311
349
  #### GyroscopePermissionState
@@ -322,8 +360,54 @@ Stop emitting `measurement` events.
322
360
 
323
361
  <code><a href="#measurement">Measurement</a></code>
324
362
 
363
+
364
+ #### MeasurementEvent
365
+
366
+ <code><a href="#measurement">Measurement</a></code>
367
+
325
368
  </docgen-api>
326
369
 
370
+ ## FAQ
371
+
372
+ ### How is this plugin different from other similar plugins?
373
+
374
+ It delivers accurate x, y, and z-axis rotation rate in rad/s with both one-off readings via `getMeasurement()` and continuous real-time updates via the `measurement` event, plus built-in permission handling for sensor access on Android and iOS. The API is fully typed and actively maintained against the latest Capacitor and OS versions, and it pairs cleanly with our Accelerometer, Barometer, and Pedometer plugins so a single, consistent motion-sensing story is covered. If you only need an occasional reading, a simpler setup is perfectly fine; if you need continuous, low-level rotation data, this plugin is built for exactly that.
375
+
376
+ ### Which platforms does the plugin support?
377
+
378
+ The plugin supports Android and iOS. The continuous `measurement` event is only emitted on Android and iOS, so there is no gyroscope support in the browser.
379
+
380
+ ### What units are the measurements reported in?
381
+
382
+ Each measurement contains the rotation rate around the x, y, and z axes in radians per second (rad/s).
383
+
384
+ ### What is the difference between `getMeasurement` and the `measurement` event?
385
+
386
+ The `getMeasurement()` method returns the most recent measurement from the gyroscope sensor once. If you need continuous real-time updates instead, add a listener for the `measurement` event and call `startMeasurementUpdates()`. Call `stopMeasurementUpdates()` when you no longer need updates.
387
+
388
+ ### Do I need any permissions to read the gyroscope?
389
+
390
+ The plugin provides the `checkPermissions()` and `requestPermissions()` methods to manage access to the gyroscope sensor. On iOS, you also have to add the `NSMotionUsageDescription` key to your `Info.plist` file, which tells the user why your app needs access to the device's motion data (see [Installation](#installation)).
391
+
392
+ ### How do I know if the device has a gyroscope sensor?
393
+
394
+ Call the `isAvailable()` method. It returns whether the gyroscope sensor is available on the device, so you can hide or disable motion features on devices without a gyroscope.
395
+
396
+ ### Can I use this plugin with Ionic, React, Vue or Angular?
397
+
398
+ Yes, the plugin is framework-agnostic. It works in any Capacitor app regardless of the web framework, including Ionic with Angular, React, or Vue, as well as plain JavaScript projects.
399
+
400
+ ## Related Plugins
401
+
402
+ - [Accelerometer](https://capawesome.io/docs/sdks/capacitor/accelerometer/): Capture the acceleration force along the x, y, and z axes.
403
+ - [Barometer](https://capawesome.io/docs/sdks/capacitor/barometer/): Obtain the static air pressure measured in hectopascals (hPa).
404
+ - [Compass](https://capawesome.io/docs/sdks/capacitor/compass/): Read the device compass heading.
405
+ - [Pedometer](https://capawesome.io/docs/sdks/capacitor/pedometer/): Retrieve motion data such as the number of steps and the distance traveled.
406
+
407
+ ## Newsletter
408
+
409
+ Stay up to date with the latest news and updates about the Capawesome, Capacitor, and Ionic ecosystem by subscribing to our [Capawesome Newsletter](https://cloud.capawesome.io/newsletter/).
410
+
327
411
  ## Changelog
328
412
 
329
413
  See [CHANGELOG.md](https://github.com/capawesome-team/capacitor-plugins/blob/main/packages/gyroscope/CHANGELOG.md).
@@ -30,7 +30,7 @@ android {
30
30
  buildTypes {
31
31
  release {
32
32
  minifyEnabled false
33
- proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
33
+ proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
34
34
  }
35
35
  }
36
36
  lintOptions {
@@ -53,8 +53,8 @@ public class Gyroscope {
53
53
  public void isAvailable(@NonNull NonEmptyResultCallback<IsAvailableResult> callback) {
54
54
  SensorManager sensorManager = (SensorManager) plugin.getContext().getSystemService(Context.SENSOR_SERVICE);
55
55
  Sensor gyroscopeSensor = sensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE);
56
- boolean isAvailable = gyroscopeSensor != null;
57
- callback.success(new IsAvailableResult(isAvailable));
56
+ boolean available = gyroscopeSensor != null;
57
+ callback.success(new IsAvailableResult(available));
58
58
  }
59
59
 
60
60
  public void startMeasurementUpdates(@NonNull EmptyCallback callback) {
@@ -78,12 +78,6 @@ public class GyroscopePlugin extends Plugin {
78
78
  notifyListeners(GyroscopePlugin.EVENT_MEASUREMENT, measurement.toJSObject());
79
79
  }
80
80
 
81
- @PluginMethod
82
- public void removeAllListeners(PluginCall call) {
83
- super.removeAllListeners(call);
84
- implementation.stopMeasurementUpdates(null);
85
- }
86
-
87
81
  @PluginMethod
88
82
  public void requestPermissions(PluginCall call) {
89
83
  JSObject result = new JSObject();
@@ -133,6 +127,12 @@ public class GyroscopePlugin extends Plugin {
133
127
  }
134
128
  }
135
129
 
130
+ @PluginMethod
131
+ public void removeAllListeners(PluginCall call) {
132
+ super.removeAllListeners(call);
133
+ implementation.stopMeasurementUpdates(null);
134
+ }
135
+
136
136
  private void rejectCall(@NonNull PluginCall call, @NonNull Exception exception) {
137
137
  String message = exception.getMessage();
138
138
  if (message == null) {
@@ -5,16 +5,16 @@ import io.capawesome.capacitorjs.plugins.gyroscope.classes.interfaces.Result;
5
5
 
6
6
  public class IsAvailableResult implements Result {
7
7
 
8
- private final boolean isAvailable;
8
+ private final boolean available;
9
9
 
10
- public IsAvailableResult(boolean isAvailable) {
11
- this.isAvailable = isAvailable;
10
+ public IsAvailableResult(boolean available) {
11
+ this.available = available;
12
12
  }
13
13
 
14
14
  @Override
15
15
  public JSObject toJSObject() {
16
16
  JSObject result = new JSObject();
17
- result.put("isAvailable", isAvailable);
17
+ result.put("available", available);
18
18
  return result;
19
19
  }
20
20
  }
package/dist/docs.json CHANGED
@@ -5,35 +5,6 @@
5
5
  "docs": "",
6
6
  "tags": [],
7
7
  "methods": [
8
- {
9
- "name": "addListener",
10
- "signature": "(eventName: 'measurement', listenerFunc: (event: MeasurementEvent) => void) => Promise<PluginListenerHandle>",
11
- "parameters": [
12
- {
13
- "name": "eventName",
14
- "docs": "",
15
- "type": "'measurement'"
16
- },
17
- {
18
- "name": "listenerFunc",
19
- "docs": "",
20
- "type": "(event: Measurement) => void"
21
- }
22
- ],
23
- "returns": "Promise<PluginListenerHandle>",
24
- "tags": [
25
- {
26
- "name": "since",
27
- "text": "0.1.0"
28
- }
29
- ],
30
- "docs": "Called when a new measurement is available.\n\nOnly available on Android and iOS.",
31
- "complexTypes": [
32
- "PluginListenerHandle",
33
- "MeasurementEvent"
34
- ],
35
- "slug": "addlistenermeasurement-"
36
- },
37
8
  {
38
9
  "name": "checkPermissions",
39
10
  "signature": "() => Promise<PermissionStatus>",
@@ -86,21 +57,6 @@
86
57
  ],
87
58
  "slug": "isavailable"
88
59
  },
89
- {
90
- "name": "removeAllListeners",
91
- "signature": "() => Promise<void>",
92
- "parameters": [],
93
- "returns": "Promise<void>",
94
- "tags": [
95
- {
96
- "name": "since",
97
- "text": "0.1.0"
98
- }
99
- ],
100
- "docs": "Remove all listeners for this plugin.",
101
- "complexTypes": [],
102
- "slug": "removealllisteners"
103
- },
104
60
  {
105
61
  "name": "requestPermissions",
106
62
  "signature": "() => Promise<PermissionStatus>",
@@ -147,24 +103,80 @@
147
103
  "docs": "Stop emitting `measurement` events.",
148
104
  "complexTypes": [],
149
105
  "slug": "stopmeasurementupdates"
106
+ },
107
+ {
108
+ "name": "addListener",
109
+ "signature": "(eventName: 'measurement', listenerFunc: (event: MeasurementEvent) => void) => Promise<PluginListenerHandle>",
110
+ "parameters": [
111
+ {
112
+ "name": "eventName",
113
+ "docs": "",
114
+ "type": "'measurement'"
115
+ },
116
+ {
117
+ "name": "listenerFunc",
118
+ "docs": "",
119
+ "type": "(event: Measurement) => void"
120
+ }
121
+ ],
122
+ "returns": "Promise<PluginListenerHandle>",
123
+ "tags": [
124
+ {
125
+ "name": "since",
126
+ "text": "0.1.0"
127
+ }
128
+ ],
129
+ "docs": "Called when a new measurement is available.\n\nOnly available on Android and iOS.",
130
+ "complexTypes": [
131
+ "PluginListenerHandle",
132
+ "MeasurementEvent"
133
+ ],
134
+ "slug": "addlistenermeasurement-"
135
+ },
136
+ {
137
+ "name": "removeAllListeners",
138
+ "signature": "() => Promise<void>",
139
+ "parameters": [],
140
+ "returns": "Promise<void>",
141
+ "tags": [
142
+ {
143
+ "name": "since",
144
+ "text": "0.1.0"
145
+ }
146
+ ],
147
+ "docs": "Remove all listeners for this plugin.",
148
+ "complexTypes": [],
149
+ "slug": "removealllisteners"
150
150
  }
151
151
  ],
152
152
  "properties": []
153
153
  },
154
154
  "interfaces": [
155
155
  {
156
- "name": "PluginListenerHandle",
157
- "slug": "pluginlistenerhandle",
156
+ "name": "PermissionStatus",
157
+ "slug": "permissionstatus",
158
158
  "docs": "",
159
- "tags": [],
159
+ "tags": [
160
+ {
161
+ "text": "0.1.0",
162
+ "name": "since"
163
+ }
164
+ ],
160
165
  "methods": [],
161
166
  "properties": [
162
167
  {
163
- "name": "remove",
164
- "tags": [],
165
- "docs": "",
166
- "complexTypes": [],
167
- "type": "() => Promise<void>"
168
+ "name": "gyroscope",
169
+ "tags": [
170
+ {
171
+ "text": "0.1.0",
172
+ "name": "since"
173
+ }
174
+ ],
175
+ "docs": "The permission status of the gyroscope sensor.",
176
+ "complexTypes": [
177
+ "GyroscopePermissionState"
178
+ ],
179
+ "type": "GyroscopePermissionState"
168
180
  }
169
181
  ]
170
182
  },
@@ -231,8 +243,8 @@
231
243
  ]
232
244
  },
233
245
  {
234
- "name": "PermissionStatus",
235
- "slug": "permissionstatus",
246
+ "name": "IsAvailableResult",
247
+ "slug": "isavailableresult",
236
248
  "docs": "",
237
249
  "tags": [
238
250
  {
@@ -243,63 +255,38 @@
243
255
  "methods": [],
244
256
  "properties": [
245
257
  {
246
- "name": "gyroscope",
258
+ "name": "available",
247
259
  "tags": [
248
260
  {
249
261
  "text": "0.1.0",
250
262
  "name": "since"
251
263
  }
252
264
  ],
253
- "docs": "The permission status of the gyroscope sensor.",
254
- "complexTypes": [
255
- "GyroscopePermissionState"
256
- ],
257
- "type": "GyroscopePermissionState"
265
+ "docs": "Whether the gyroscope sensor is available on the device.",
266
+ "complexTypes": [],
267
+ "type": "boolean"
258
268
  }
259
269
  ]
260
270
  },
261
271
  {
262
- "name": "IsAvailableResult",
263
- "slug": "isavailableresult",
272
+ "name": "PluginListenerHandle",
273
+ "slug": "pluginlistenerhandle",
264
274
  "docs": "",
265
- "tags": [
266
- {
267
- "text": "0.1.0",
268
- "name": "since"
269
- }
270
- ],
275
+ "tags": [],
271
276
  "methods": [],
272
277
  "properties": [
273
278
  {
274
- "name": "isAvailable",
275
- "tags": [
276
- {
277
- "text": "0.1.0",
278
- "name": "since"
279
- }
280
- ],
281
- "docs": "Whether the gyroscope sensor is available on the device.",
279
+ "name": "remove",
280
+ "tags": [],
281
+ "docs": "",
282
282
  "complexTypes": [],
283
- "type": "boolean"
283
+ "type": "() => Promise<void>"
284
284
  }
285
285
  ]
286
286
  }
287
287
  ],
288
288
  "enums": [],
289
289
  "typeAliases": [
290
- {
291
- "name": "MeasurementEvent",
292
- "slug": "measurementevent",
293
- "docs": "",
294
- "types": [
295
- {
296
- "text": "Measurement",
297
- "complexTypes": [
298
- "Measurement"
299
- ]
300
- }
301
- ]
302
- },
303
290
  {
304
291
  "name": "GyroscopePermissionState",
305
292
  "slug": "gyroscopepermissionstate",
@@ -352,6 +339,19 @@
352
339
  ]
353
340
  }
354
341
  ]
342
+ },
343
+ {
344
+ "name": "MeasurementEvent",
345
+ "slug": "measurementevent",
346
+ "docs": "",
347
+ "types": [
348
+ {
349
+ "text": "Measurement",
350
+ "complexTypes": [
351
+ "Measurement"
352
+ ]
353
+ }
354
+ ]
355
355
  }
356
356
  ],
357
357
  "pluginConfigs": []
@@ -1,14 +1,6 @@
1
1
  import type { PermissionState, PluginListenerHandle } from '@capacitor/core';
2
2
  export type GyroscopePermissionState = PermissionState | 'limited';
3
3
  export interface GyroscopePlugin {
4
- /**
5
- * Called when a new measurement is available.
6
- *
7
- * Only available on Android and iOS.
8
- *
9
- * @since 0.1.0
10
- */
11
- addListener(eventName: 'measurement', listenerFunc: (event: MeasurementEvent) => void): Promise<PluginListenerHandle>;
12
4
  /**
13
5
  * Check if the app has permission to access the gyroscope sensor.
14
6
  *
@@ -29,12 +21,6 @@ export interface GyroscopePlugin {
29
21
  * @since 0.1.0
30
22
  */
31
23
  isAvailable(): Promise<IsAvailableResult>;
32
- /**
33
- * Remove all listeners for this plugin.
34
- *
35
- * @since 0.1.0
36
- */
37
- removeAllListeners(): Promise<void>;
38
24
  /**
39
25
  * Request permission to access the gyroscope sensor.
40
26
  *
@@ -53,6 +39,20 @@ export interface GyroscopePlugin {
53
39
  * @since 0.1.0
54
40
  */
55
41
  stopMeasurementUpdates(): Promise<void>;
42
+ /**
43
+ * Called when a new measurement is available.
44
+ *
45
+ * Only available on Android and iOS.
46
+ *
47
+ * @since 0.1.0
48
+ */
49
+ addListener(eventName: 'measurement', listenerFunc: (event: MeasurementEvent) => void): Promise<PluginListenerHandle>;
50
+ /**
51
+ * Remove all listeners for this plugin.
52
+ *
53
+ * @since 0.1.0
54
+ */
55
+ removeAllListeners(): Promise<void>;
56
56
  }
57
57
  /**
58
58
  * @since 0.1.0
@@ -67,7 +67,7 @@ export interface IsAvailableResult {
67
67
  *
68
68
  * @since 0.1.0
69
69
  */
70
- isAvailable: boolean;
70
+ available: boolean;
71
71
  }
72
72
  /**
73
73
  * @since 0.1.0
@@ -1 +1 @@
1
- {"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["import type { PermissionState, PluginListenerHandle } from '@capacitor/core';\n\nexport type GyroscopePermissionState = PermissionState | 'limited';\n\nexport interface GyroscopePlugin {\n /**\n * Called when a new measurement is available.\n *\n * Only available on Android and iOS.\n *\n * @since 0.1.0\n */\n addListener(\n eventName: 'measurement',\n listenerFunc: (event: MeasurementEvent) => void,\n ): Promise<PluginListenerHandle>;\n /**\n * Check if the app has permission to access the gyroscope sensor.\n *\n * @since 0.1.0\n */\n checkPermissions(): Promise<PermissionStatus>;\n /**\n * Get the latest measurement.\n *\n * This method returns the most recent measurement from the gyroscope sensor.\n *\n * @since 0.1.0\n */\n getMeasurement(): Promise<GetMeasurementResult>;\n /**\n * Check if the gyroscope sensor is available on the device.\n *\n * @since 0.1.0\n */\n isAvailable(): Promise<IsAvailableResult>;\n /**\n * Remove all listeners for this plugin.\n *\n * @since 0.1.0\n */\n removeAllListeners(): Promise<void>;\n /**\n * Request permission to access the gyroscope sensor.\n *\n * @since 0.1.0\n */\n requestPermissions(): Promise<PermissionStatus>;\n /**\n * Start emitting `measurement` events.\n *\n * @since 0.1.0\n */\n startMeasurementUpdates(): Promise<void>;\n /**\n * Stop emitting `measurement` events.\n *\n * @since 0.1.0\n */\n stopMeasurementUpdates(): Promise<void>;\n}\n\n/**\n * @since 0.1.0\n */\nexport type GetMeasurementResult = Measurement;\n\n/**\n * @since 0.1.0\n */\nexport interface IsAvailableResult {\n /**\n * Whether the gyroscope sensor is available on the device.\n *\n * @since 0.1.0\n */\n isAvailable: boolean;\n}\n\n/**\n * @since 0.1.0\n */\nexport type MeasurementEvent = Measurement;\n\n/**\n * @since 0.1.0\n */\nexport interface Measurement {\n /**\n * The rotation rate around the x-axis in radians per second (rad/s).\n *\n * @example 0.12\n * @since 0.1.0\n */\n x: number;\n /**\n * The rotation rate around the y-axis in radians per second (rad/s).\n *\n * @example 0.12\n * @since 0.1.0\n */\n y: number;\n /**\n * The rotation rate around the z-axis in radians per second (rad/s).\n *\n * @example 0.12\n * @since 0.1.0\n */\n z: number;\n}\n\n/**\n * @since 0.1.0\n */\nexport interface PermissionStatus {\n /**\n * The permission status of the gyroscope sensor.\n *\n * @since 0.1.0\n */\n gyroscope: GyroscopePermissionState;\n}\n"]}
1
+ {"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["import type { PermissionState, PluginListenerHandle } from '@capacitor/core';\n\nexport type GyroscopePermissionState = PermissionState | 'limited';\n\nexport interface GyroscopePlugin {\n /**\n * Check if the app has permission to access the gyroscope sensor.\n *\n * @since 0.1.0\n */\n checkPermissions(): Promise<PermissionStatus>;\n /**\n * Get the latest measurement.\n *\n * This method returns the most recent measurement from the gyroscope sensor.\n *\n * @since 0.1.0\n */\n getMeasurement(): Promise<GetMeasurementResult>;\n /**\n * Check if the gyroscope sensor is available on the device.\n *\n * @since 0.1.0\n */\n isAvailable(): Promise<IsAvailableResult>;\n /**\n * Request permission to access the gyroscope sensor.\n *\n * @since 0.1.0\n */\n requestPermissions(): Promise<PermissionStatus>;\n /**\n * Start emitting `measurement` events.\n *\n * @since 0.1.0\n */\n startMeasurementUpdates(): Promise<void>;\n /**\n * Stop emitting `measurement` events.\n *\n * @since 0.1.0\n */\n stopMeasurementUpdates(): Promise<void>;\n /**\n * Called when a new measurement is available.\n *\n * Only available on Android and iOS.\n *\n * @since 0.1.0\n */\n addListener(\n eventName: 'measurement',\n listenerFunc: (event: MeasurementEvent) => void,\n ): Promise<PluginListenerHandle>;\n /**\n * Remove all listeners for this plugin.\n *\n * @since 0.1.0\n */\n removeAllListeners(): Promise<void>;\n}\n\n/**\n * @since 0.1.0\n */\nexport type GetMeasurementResult = Measurement;\n\n/**\n * @since 0.1.0\n */\nexport interface IsAvailableResult {\n /**\n * Whether the gyroscope sensor is available on the device.\n *\n * @since 0.1.0\n */\n available: boolean;\n}\n\n/**\n * @since 0.1.0\n */\nexport type MeasurementEvent = Measurement;\n\n/**\n * @since 0.1.0\n */\nexport interface Measurement {\n /**\n * The rotation rate around the x-axis in radians per second (rad/s).\n *\n * @example 0.12\n * @since 0.1.0\n */\n x: number;\n /**\n * The rotation rate around the y-axis in radians per second (rad/s).\n *\n * @example 0.12\n * @since 0.1.0\n */\n y: number;\n /**\n * The rotation rate around the z-axis in radians per second (rad/s).\n *\n * @example 0.12\n * @since 0.1.0\n */\n z: number;\n}\n\n/**\n * @since 0.1.0\n */\nexport interface PermissionStatus {\n /**\n * The permission status of the gyroscope sensor.\n *\n * @since 0.1.0\n */\n gyroscope: GyroscopePermissionState;\n}\n"]}
package/dist/esm/web.d.ts CHANGED
@@ -7,10 +7,10 @@ export declare class GyroscopeWeb extends WebPlugin implements GyroscopePlugin {
7
7
  checkPermissions(): Promise<PermissionStatus>;
8
8
  getMeasurement(): Promise<Measurement>;
9
9
  isAvailable(): Promise<IsAvailableResult>;
10
- removeAllListeners(): Promise<void>;
11
10
  requestPermissions(): Promise<PermissionStatus>;
12
11
  startMeasurementUpdates(): Promise<void>;
13
12
  stopMeasurementUpdates(): Promise<void>;
13
+ removeAllListeners(): Promise<void>;
14
14
  private createOrGetGyroscope;
15
15
  private createUnavailableException;
16
16
  private handleMeasurementEvent;
package/dist/esm/web.js CHANGED
@@ -31,9 +31,9 @@ export class GyroscopeWeb extends WebPlugin {
31
31
  });
32
32
  }
33
33
  async isAvailable() {
34
- let isAvailable = false;
34
+ let available = false;
35
35
  if (!this._isAvailable) {
36
- return { isAvailable };
36
+ return { available };
37
37
  }
38
38
  // According to an article on Chrome Developers (https://developer.chrome.com/docs/capabilities/web-apis/generic-sensor#feature-detection)
39
39
  // we also need to connect to the sensor for an actual meaningful feature detection
@@ -42,12 +42,12 @@ export class GyroscopeWeb extends WebPlugin {
42
42
  await new Promise(resolve => {
43
43
  gyroscope.onerror = (event) => {
44
44
  console.error(event);
45
- isAvailable = false;
45
+ available = false;
46
46
  gyroscope.stop();
47
47
  resolve();
48
48
  };
49
49
  gyroscope.onreading = () => {
50
- isAvailable = true;
50
+ available = true;
51
51
  gyroscope.stop();
52
52
  resolve();
53
53
  };
@@ -56,15 +56,9 @@ export class GyroscopeWeb extends WebPlugin {
56
56
  }
57
57
  catch (error) {
58
58
  console.error(error);
59
- isAvailable = false;
60
- }
61
- return { isAvailable };
62
- }
63
- async removeAllListeners() {
64
- await super.removeAllListeners();
65
- if (this.measurementEventStarted) {
66
- await this.stopMeasurementUpdates();
59
+ available = false;
67
60
  }
61
+ return { available };
68
62
  }
69
63
  async requestPermissions() {
70
64
  const { state } = await navigator.permissions.query({
@@ -96,6 +90,12 @@ export class GyroscopeWeb extends WebPlugin {
96
90
  gyroscope.stop();
97
91
  gyroscope.onreading = null;
98
92
  }
93
+ async removeAllListeners() {
94
+ await super.removeAllListeners();
95
+ if (this.measurementEventStarted) {
96
+ await this.stopMeasurementUpdates();
97
+ }
98
+ }
99
99
  // @ts-ignore
100
100
  createOrGetGyroscope() {
101
101
  if (!this._gyroscope) {
@@ -1 +1 @@
1
- {"version":3,"file":"web.js","sourceRoot":"","sources":["../../src/web.ts"],"names":[],"mappings":"AAAA,sDAAsD;AACtD,OAAO,EAAE,kBAAkB,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAS/E,MAAM,OAAO,YAAa,SAAQ,SAAS;IAA3C;;QAGmB,iBAAY,GAAG,WAAW,IAAI,MAAM,CAAC;QAC9C,4BAAuB,GAAG,KAAK,CAAC;IAiI1C,CAAC;IA/HC,KAAK,CAAC,gBAAgB;QACpB,MAAM,EAAE,KAAK,EAAE,GAAG,MAAM,SAAS,CAAC,WAAW,CAAC,KAAK,CAAC;YAClD,IAAI,EAAE,WAA6B;SACpC,CAAC,CAAC;QACH,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC;IAC9B,CAAC;IAED,KAAK,CAAC,cAAc;QAClB,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE,CAAC;YACvB,MAAM,IAAI,CAAC,0BAA0B,EAAE,CAAC;QAC1C,CAAC;QACD,MAAM,SAAS,GAAG,IAAI,CAAC,oBAAoB,EAAE,CAAC;QAC9C,OAAO,IAAI,OAAO,CAAc,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YAClD,SAAS,CAAC,OAAO,GAAG,CAAC,KAAU,EAAE,EAAE;gBACjC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;gBACrB,MAAM,CAAC,KAAK,CAAC,CAAC;YAChB,CAAC,CAAC;YACF,SAAS,CAAC,SAAS,GAAG,GAAG,EAAE;gBACzB,MAAM,WAAW,GAAG,IAAI,CAAC,4BAA4B,EAAE,CAAC;gBACxD,SAAS,CAAC,IAAI,EAAE,CAAC;gBACjB,OAAO,CAAC,WAAW,CAAC,CAAC;YACvB,CAAC,CAA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IAAI,kBAAkB,CAC3B,uDAAuD,EACvD,aAAa,CAAC,WAAW,CAC1B,CAAC;IACJ,CAAC;IAEO,sBAAsB;QAC5B,MAAM,WAAW,GAAG,IAAI,CAAC,4BAA4B,EAAE,CAAC;QACxD,IAAI,CAAC,eAAe,CAAC,aAAa,EAAE,WAAW,CAAC,CAAC;IACnD,CAAC;IAEO,4BAA4B;QAClC,MAAM,SAAS,GAAG,IAAI,CAAC,oBAAoB,EAAE,CAAC;QAC9C,OAAO;YACL,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,GAAG,GAAG,CAAC,GAAG,GAAG;YACtC,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,GAAG,GAAG,CAAC,GAAG,GAAG;YACtC,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,GAAG,GAAG,CAAC,GAAG,GAAG;SACvC,CAAC;IACJ,CAAC;CACF","sourcesContent":["/* eslint-disable @typescript-eslint/ban-ts-comment */\nimport { CapacitorException, ExceptionCode, WebPlugin } from '@capacitor/core';\n\nimport type {\n GyroscopePlugin,\n IsAvailableResult,\n Measurement,\n PermissionStatus,\n} from './definitions';\n\nexport class GyroscopeWeb extends WebPlugin implements GyroscopePlugin {\n // @ts-ignore\n private _gyroscope: Gyroscope | undefined;\n private readonly _isAvailable = 'Gyroscope' in window;\n private measurementEventStarted = false;\n\n async checkPermissions(): Promise<PermissionStatus> {\n const { state } = await navigator.permissions.query({\n name: 'gyroscope' as PermissionName,\n });\n return { gyroscope: state };\n }\n\n async getMeasurement(): Promise<Measurement> {\n if (!this._isAvailable) {\n throw this.createUnavailableException();\n }\n const gyroscope = this.createOrGetGyroscope();\n return new Promise<Measurement>((resolve, reject) => {\n gyroscope.onerror = (event: any) => {\n console.error(event);\n reject(event);\n };\n gyroscope.onreading = () => {\n const measurement = this.readMeasurementFromGyroscope();\n gyroscope.stop();\n resolve(measurement);\n };\n gyroscope.start();\n });\n }\n\n async isAvailable(): Promise<IsAvailableResult> {\n let isAvailable = false;\n if (!this._isAvailable) {\n return { isAvailable };\n }\n // According to an article on Chrome Developers (https://developer.chrome.com/docs/capabilities/web-apis/generic-sensor#feature-detection)\n // we also need to connect to the sensor for an actual meaningful feature detection\n const gyroscope = this.createOrGetGyroscope();\n try {\n await new Promise<void>(resolve => {\n gyroscope.onerror = (event: any) => {\n console.error(event);\n isAvailable = false;\n gyroscope.stop();\n resolve();\n };\n gyroscope.onreading = () => {\n isAvailable = true;\n gyroscope.stop();\n resolve();\n };\n gyroscope.start();\n });\n } catch (error: any) {\n console.error(error);\n isAvailable = false;\n }\n return { isAvailable };\n }\n\n async removeAllListeners(): Promise<void> {\n await super.removeAllListeners();\n if (this.measurementEventStarted) {\n await this.stopMeasurementUpdates();\n }\n }\n\n async requestPermissions(): Promise<PermissionStatus> {\n const { state } = await navigator.permissions.query({\n name: 'gyroscope' as PermissionName,\n });\n return { gyroscope: state };\n }\n\n async startMeasurementUpdates(): Promise<void> {\n if (!this._isAvailable) {\n throw this.createUnavailableException();\n }\n if (this.measurementEventStarted) {\n return;\n }\n this.measurementEventStarted = true;\n const gyroscope = this.createOrGetGyroscope();\n gyroscope.onreading = () => this.handleMeasurementEvent();\n gyroscope.start();\n }\n\n async stopMeasurementUpdates(): Promise<void> {\n if (!this._isAvailable) {\n throw this.createUnavailableException();\n }\n if (!this.measurementEventStarted) {\n return;\n }\n this.measurementEventStarted = false;\n const gyroscope = this.createOrGetGyroscope();\n gyroscope.stop();\n gyroscope.onreading = null;\n }\n\n // @ts-ignore\n private createOrGetGyroscope(): Gyroscope {\n if (!this._gyroscope) {\n // @ts-ignore\n this._gyroscope = new Gyroscope({\n frequency: 10,\n });\n }\n return this._gyroscope;\n }\n\n private createUnavailableException(): CapacitorException {\n return new CapacitorException(\n 'This plugin method is not available on this platform.',\n ExceptionCode.Unavailable,\n );\n }\n\n private handleMeasurementEvent(): void {\n const measurement = this.readMeasurementFromGyroscope();\n this.notifyListeners('measurement', measurement);\n }\n\n private readMeasurementFromGyroscope(): Measurement {\n const gyroscope = this.createOrGetGyroscope();\n return {\n x: Math.round(gyroscope.x * 100) / 100,\n y: Math.round(gyroscope.y * 100) / 100,\n z: Math.round(gyroscope.z * 100) / 100,\n };\n }\n}\n"]}
1
+ {"version":3,"file":"web.js","sourceRoot":"","sources":["../../src/web.ts"],"names":[],"mappings":"AAAA,sDAAsD;AACtD,OAAO,EAAE,kBAAkB,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAS/E,MAAM,OAAO,YAAa,SAAQ,SAAS;IAA3C;;QAGmB,iBAAY,GAAG,WAAW,IAAI,MAAM,CAAC;QAC9C,4BAAuB,GAAG,KAAK,CAAC;IAiI1C,CAAC;IA/HC,KAAK,CAAC,gBAAgB;QACpB,MAAM,EAAE,KAAK,EAAE,GAAG,MAAM,SAAS,CAAC,WAAW,CAAC,KAAK,CAAC;YAClD,IAAI,EAAE,WAA6B;SACpC,CAAC,CAAC;QACH,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC;IAC9B,CAAC;IAED,KAAK,CAAC,cAAc;QAClB,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE,CAAC;YACvB,MAAM,IAAI,CAAC,0BAA0B,EAAE,CAAC;QAC1C,CAAC;QACD,MAAM,SAAS,GAAG,IAAI,CAAC,oBAAoB,EAAE,CAAC;QAC9C,OAAO,IAAI,OAAO,CAAc,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YAClD,SAAS,CAAC,OAAO,GAAG,CAAC,KAAU,EAAE,EAAE;gBACjC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;gBACrB,MAAM,CAAC,KAAK,CAAC,CAAC;YAChB,CAAC,CAAC;YACF,SAAS,CAAC,SAAS,GAAG,GAAG,EAAE;gBACzB,MAAM,WAAW,GAAG,IAAI,CAAC,4BAA4B,EAAE,CAAC;gBACxD,SAAS,CAAC,IAAI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AO,IAAI,CAAC,UAAU,CAAC;IACzB,CAAC;IAEO,0BAA0B;QAChC,OAAO,IAAI,kBAAkB,CAC3B,uDAAuD,EACvD,aAAa,CAAC,WAAW,CAC1B,CAAC;IACJ,CAAC;IAEO,sBAAsB;QAC5B,MAAM,WAAW,GAAG,IAAI,CAAC,4BAA4B,EAAE,CAAC;QACxD,IAAI,CAAC,eAAe,CAAC,aAAa,EAAE,WAAW,CAAC,CAAC;IACnD,CAAC;IAEO,4BAA4B;QAClC,MAAM,SAAS,GAAG,IAAI,CAAC,oBAAoB,EAAE,CAAC;QAC9C,OAAO;YACL,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,GAAG,GAAG,CAAC,GAAG,GAAG;YACtC,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,GAAG,GAAG,CAAC,GAAG,GAAG;YACtC,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,GAAG,GAAG,CAAC,GAAG,GAAG;SACvC,CAAC;IACJ,CAAC;CACF","sourcesContent":["/* eslint-disable @typescript-eslint/ban-ts-comment */\nimport { CapacitorException, ExceptionCode, WebPlugin } from '@capacitor/core';\n\nimport type {\n GyroscopePlugin,\n IsAvailableResult,\n Measurement,\n PermissionStatus,\n} from './definitions';\n\nexport class GyroscopeWeb extends WebPlugin implements GyroscopePlugin {\n // @ts-ignore\n private _gyroscope: Gyroscope | undefined;\n private readonly _isAvailable = 'Gyroscope' in window;\n private measurementEventStarted = false;\n\n async checkPermissions(): Promise<PermissionStatus> {\n const { state } = await navigator.permissions.query({\n name: 'gyroscope' as PermissionName,\n });\n return { gyroscope: state };\n }\n\n async getMeasurement(): Promise<Measurement> {\n if (!this._isAvailable) {\n throw this.createUnavailableException();\n }\n const gyroscope = this.createOrGetGyroscope();\n return new Promise<Measurement>((resolve, reject) => {\n gyroscope.onerror = (event: any) => {\n console.error(event);\n reject(event);\n };\n gyroscope.onreading = () => {\n const measurement = this.readMeasurementFromGyroscope();\n gyroscope.stop();\n resolve(measurement);\n };\n gyroscope.start();\n });\n }\n\n async isAvailable(): Promise<IsAvailableResult> {\n let available = false;\n if (!this._isAvailable) {\n return { available };\n }\n // According to an article on Chrome Developers (https://developer.chrome.com/docs/capabilities/web-apis/generic-sensor#feature-detection)\n // we also need to connect to the sensor for an actual meaningful feature detection\n const gyroscope = this.createOrGetGyroscope();\n try {\n await new Promise<void>(resolve => {\n gyroscope.onerror = (event: any) => {\n console.error(event);\n available = false;\n gyroscope.stop();\n resolve();\n };\n gyroscope.onreading = () => {\n available = true;\n gyroscope.stop();\n resolve();\n };\n gyroscope.start();\n });\n } catch (error: any) {\n console.error(error);\n available = false;\n }\n return { available };\n }\n\n async requestPermissions(): Promise<PermissionStatus> {\n const { state } = await navigator.permissions.query({\n name: 'gyroscope' as PermissionName,\n });\n return { gyroscope: state };\n }\n\n async startMeasurementUpdates(): Promise<void> {\n if (!this._isAvailable) {\n throw this.createUnavailableException();\n }\n if (this.measurementEventStarted) {\n return;\n }\n this.measurementEventStarted = true;\n const gyroscope = this.createOrGetGyroscope();\n gyroscope.onreading = () => this.handleMeasurementEvent();\n gyroscope.start();\n }\n\n async stopMeasurementUpdates(): Promise<void> {\n if (!this._isAvailable) {\n throw this.createUnavailableException();\n }\n if (!this.measurementEventStarted) {\n return;\n }\n this.measurementEventStarted = false;\n const gyroscope = this.createOrGetGyroscope();\n gyroscope.stop();\n gyroscope.onreading = null;\n }\n\n async removeAllListeners(): Promise<void> {\n await super.removeAllListeners();\n if (this.measurementEventStarted) {\n await this.stopMeasurementUpdates();\n }\n }\n\n // @ts-ignore\n private createOrGetGyroscope(): Gyroscope {\n if (!this._gyroscope) {\n // @ts-ignore\n this._gyroscope = new Gyroscope({\n frequency: 10,\n });\n }\n return this._gyroscope;\n }\n\n private createUnavailableException(): CapacitorException {\n return new CapacitorException(\n 'This plugin method is not available on this platform.',\n ExceptionCode.Unavailable,\n );\n }\n\n private handleMeasurementEvent(): void {\n const measurement = this.readMeasurementFromGyroscope();\n this.notifyListeners('measurement', measurement);\n }\n\n private readMeasurementFromGyroscope(): Measurement {\n const gyroscope = this.createOrGetGyroscope();\n return {\n x: Math.round(gyroscope.x * 100) / 100,\n y: Math.round(gyroscope.y * 100) / 100,\n z: Math.round(gyroscope.z * 100) / 100,\n };\n }\n}\n"]}
@@ -38,9 +38,9 @@ class GyroscopeWeb extends core.WebPlugin {
38
38
  });
39
39
  }
40
40
  async isAvailable() {
41
- let isAvailable = false;
41
+ let available = false;
42
42
  if (!this._isAvailable) {
43
- return { isAvailable };
43
+ return { available };
44
44
  }
45
45
  // According to an article on Chrome Developers (https://developer.chrome.com/docs/capabilities/web-apis/generic-sensor#feature-detection)
46
46
  // we also need to connect to the sensor for an actual meaningful feature detection
@@ -49,12 +49,12 @@ class GyroscopeWeb extends core.WebPlugin {
49
49
  await new Promise(resolve => {
50
50
  gyroscope.onerror = (event) => {
51
51
  console.error(event);
52
- isAvailable = false;
52
+ available = false;
53
53
  gyroscope.stop();
54
54
  resolve();
55
55
  };
56
56
  gyroscope.onreading = () => {
57
- isAvailable = true;
57
+ available = true;
58
58
  gyroscope.stop();
59
59
  resolve();
60
60
  };
@@ -63,15 +63,9 @@ class GyroscopeWeb extends core.WebPlugin {
63
63
  }
64
64
  catch (error) {
65
65
  console.error(error);
66
- isAvailable = false;
67
- }
68
- return { isAvailable };
69
- }
70
- async removeAllListeners() {
71
- await super.removeAllListeners();
72
- if (this.measurementEventStarted) {
73
- await this.stopMeasurementUpdates();
66
+ available = false;
74
67
  }
68
+ return { available };
75
69
  }
76
70
  async requestPermissions() {
77
71
  const { state } = await navigator.permissions.query({
@@ -103,6 +97,12 @@ class GyroscopeWeb extends core.WebPlugin {
103
97
  gyroscope.stop();
104
98
  gyroscope.onreading = null;
105
99
  }
100
+ async removeAllListeners() {
101
+ await super.removeAllListeners();
102
+ if (this.measurementEventStarted) {
103
+ await this.stopMeasurementUpdates();
104
+ }
105
+ }
106
106
  // @ts-ignore
107
107
  createOrGetGyroscope() {
108
108
  if (!this._gyroscope) {
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.cjs.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst Gyroscope = registerPlugin('Gyroscope', {\n web: () => import('./web').then(m => new m.GyroscopeWeb()),\n});\nexport * from './definitions';\nexport { Gyroscope };\n//# sourceMappingURL=index.js.map","/* eslint-disable @typescript-eslint/ban-ts-comment */\nimport { CapacitorException, ExceptionCode, WebPlugin } from '@capacitor/core';\nexport class GyroscopeWeb extends WebPlugin {\n constructor() {\n super(...arguments);\n this._isAvailable = 'Gyroscope' in window;\n this.measurementEventStarted = false;\n }\n async checkPermissions() {\n const { state } = await navigator.permissions.query({\n name: 'gyroscope',\n });\n return { gyroscope: state };\n }\n async getMeasurement() {\n if (!this._isAvailable) {\n throw this.createUnavailableException();\n }\n const gyroscope = this.createOrGetGyroscope();\n return new Promise((resolve, reject) => {\n gyroscope.onerror = (event) => {\n console.error(event);\n reject(event);\n };\n gyroscope.onreading = () => {\n const measurement = this.readMeasurementFromGyroscope();\n gyroscope.stop();\n resolve(measurement);\n };\n gyroscope.start();\n });\n }\n async isAvailable() {\n let isAvailable = false;\n if (!this._isAvailable) {\n return { isAvailable };\n }\n // According to an article on Chrome Developers (https://developer.chrome.com/docs/capabilities/web-apis/generic-sensor#feature-detection)\n // we also need to connect to the sensor for an actual meaningful feature detection\n const gyroscope = this.createOrGetGyroscope();\n try {\n await new Promise(resolve => {\n gyroscope.onerror = (event) => {\n console.error(event);\n isAvailable = false;\n gyroscope.stop();\n resolve();\n };\n gyroscope.onreading = () => {\n isAvailable = true;\n gyroscope.stop();\n resolve();\n };\n gyroscope.start();\n });\n }\n catch (error) {\n console.error(error);\n isAvailable = false;\n }\n return { isAvailable };\n }\n async removeAllListeners() {\n await super.removeAllListeners();\n if (this.measurementEventStarted) {\n await this.stopMeasurementUpdates();\n }\n }\n async requestPermissions() {\n const { state } = await navigator.permissions.query({\n name: 'gyroscope',\n });\n return { gyroscope: state };\n }\n async startMeasurementUpdates() {\n if (!this._isAvailable) {\n throw this.createUnavailableException();\n }\n if (this.measurementEventStarted) {\n return;\n }\n this.measurementEventStarted = true;\n const gyroscope = this.createOrGetGyroscope();\n gyroscope.onreading = () => this.handleMeasurementEvent();\n gyroscope.start();\n }\n async stopMeasurementUpdates() {\n if (!this._isAvailable) {\n throw this.createUnavailableException();\n }\n if (!this.measurementEventStarted) {\n return;\n }\n this.measurementEventStarted = false;\n const gyroscope = this.createOrGetGyroscope();\n gyroscope.stop();\n gyroscope.onreading = null;\n }\n // @ts-ignore\n createOrGetGyroscope() {\n if (!this._gyroscope) {\n // @ts-ignore\n this._gyroscope = new Gyroscope({\n frequency: 10,\n });\n }\n return this._gyroscope;\n }\n createUnavailableException() {\n return new CapacitorException('This plugin method is not available on this platform.', ExceptionCode.Unavailable);\n }\n handleMeasurementEvent() {\n const measurement = this.readMeasurementFromGyroscope();\n this.notifyListeners('measurement', measurement);\n }\n readMeasurementFromGyroscope() {\n const gyroscope = this.createOrGetGyroscope();\n return {\n x: Math.round(gyroscope.x * 100) / 100,\n y: Math.round(gyroscope.y * 100) / 100,\n z: Math.round(gyroscope.z * 100) / 100,\n };\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["Gyroscope","registerPlugin","WebPlugin","CapacitorException","ExceptionCode"],"mappings":";;;;AACK,MAACA,WAAS,GAAGC,mBAAc,CAAC,WAAW,EAAE;AAC9C,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,YAAY,EAAE,CAAC;AAC9D,CAAC;;ACHD;AAEO,MAAM,YAAY,SAASC,cAAS,CAAC;AAC5C,IAAI,WAAW,GAAG;AAClB,QAAQ,KAAK,CAAC,GAAG,SAAS,CAAC;AAC3B,QAAQ,IAAI,CAAC,YAAY,GAAG,WAAW,IAAI,MAAM;AACjD,QAAQ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AAW,CAAC;AACxD,IAAI;AACJ,IAAI,4BAA4B,GAAG;AACnC,QAAQ,MAAM,SAAS,GAAG,IAAI,CAAC,oBAAoB,EAAE;AACrD,QAAQ,OAAO;AACf,YAAY,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,GAAG,GAAG,CAAC,GAAG,GAAG;AAClD,YAAY,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,GAAG,GAAG,CAAC,GAAG,GAAG;AAClD,YAAY,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,GAAG,GAAG,CAAC,GAAG,GAAG;AAClD,SAAS;AACT,IAAI;AACJ;;;;;;;;;"}
1
+ {"version":3,"file":"plugin.cjs.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst Gyroscope = registerPlugin('Gyroscope', {\n web: () => import('./web').then(m => new m.GyroscopeWeb()),\n});\nexport * from './definitions';\nexport { Gyroscope };\n//# sourceMappingURL=index.js.map","/* eslint-disable @typescript-eslint/ban-ts-comment */\nimport { CapacitorException, ExceptionCode, WebPlugin } from '@capacitor/core';\nexport class GyroscopeWeb extends WebPlugin {\n constructor() {\n super(...arguments);\n this._isAvailable = 'Gyroscope' in window;\n this.measurementEventStarted = false;\n }\n async checkPermissions() {\n const { state } = await navigator.permissions.query({\n name: 'gyroscope',\n });\n return { gyroscope: state };\n }\n async getMeasurement() {\n if (!this._isAvailable) {\n throw this.createUnavailableException();\n }\n const gyroscope = this.createOrGetGyroscope();\n return new Promise((resolve, reject) => {\n gyroscope.onerror = (event) => {\n console.error(event);\n reject(event);\n };\n gyroscope.onreading = () => {\n const measurement = this.readMeasurementFromGyroscope();\n gyroscope.stop();\n resolve(measurement);\n };\n gyroscope.start();\n });\n }\n async isAvailable() {\n let available = false;\n if (!this._isAvailable) {\n return { available };\n }\n // According to an article on Chrome Developers (https://developer.chrome.com/docs/capabilities/web-apis/generic-sensor#feature-detection)\n // we also need to connect to the sensor for an actual meaningful feature detection\n const gyroscope = this.createOrGetGyroscope();\n try {\n await new Promise(resolve => {\n gyroscope.onerror = (event) => {\n console.error(event);\n available = false;\n gyroscope.stop();\n resolve();\n };\n gyroscope.onreading = () => {\n available = true;\n gyroscope.stop();\n resolve();\n };\n gyroscope.start();\n });\n }\n catch (error) {\n console.error(error);\n available = false;\n }\n return { available };\n }\n async requestPermissions() {\n const { state } = await navigator.permissions.query({\n name: 'gyroscope',\n });\n return { gyroscope: state };\n }\n async startMeasurementUpdates() {\n if (!this._isAvailable) {\n throw this.createUnavailableException();\n }\n if (this.measurementEventStarted) {\n return;\n }\n this.measurementEventStarted = true;\n const gyroscope = this.createOrGetGyroscope();\n gyroscope.onreading = () => this.handleMeasurementEvent();\n gyroscope.start();\n }\n async stopMeasurementUpdates() {\n if (!this._isAvailable) {\n throw this.createUnavailableException();\n }\n if (!this.measurementEventStarted) {\n return;\n }\n this.measurementEventStarted = false;\n const gyroscope = this.createOrGetGyroscope();\n gyroscope.stop();\n gyroscope.onreading = null;\n }\n async removeAllListeners() {\n await super.removeAllListeners();\n if (this.measurementEventStarted) {\n await this.stopMeasurementUpdates();\n }\n }\n // @ts-ignore\n createOrGetGyroscope() {\n if (!this._gyroscope) {\n // @ts-ignore\n this._gyroscope = new Gyroscope({\n frequency: 10,\n });\n }\n return this._gyroscope;\n }\n createUnavailableException() {\n return new CapacitorException('This plugin method is not available on this platform.', ExceptionCode.Unavailable);\n }\n handleMeasurementEvent() {\n const measurement = this.readMeasurementFromGyroscope();\n this.notifyListeners('measurement', measurement);\n }\n readMeasurementFromGyroscope() {\n const gyroscope = this.createOrGetGyroscope();\n return {\n x: Math.round(gyroscope.x * 100) / 100,\n y: Math.round(gyroscope.y * 100) / 100,\n z: Math.round(gyroscope.z * 100) / 100,\n };\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["Gyroscope","registerPlugin","WebPlugin","CapacitorException","ExceptionCode"],"mappings":";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EAAE,EAAE;AAC7B,aAAa,CAAC;AACd,QAAQ;AACR,QAAQ,OAAO,IAAI,CAAC,UAAU;AAC9B,IAAI;AACJ,IAAI,0BAA0B,GAAG;AACjC,QAAQ,OAAO,IAAIC,uBAAkB,CAAC,uDAAuD,EAAEC,kBAAa,CAAC,WAAW,CAAC;AACzH,IAAI;AACJ,IAAI,sBAAsB,GAAG;AAC7B,QAAQ,MAAM,WAAW,GAAG,IAAI,CAAC,4BAA4B,EAAE;AAC/D,QAAQ,IAAI,CAAC,eAAe,CAAC,aAAa,EAAE,WAAW,CAAC;AACxD,IAAI;AACJ,IAAI,4BAA4B,GAAG;AACnC,QAAQ,MAAM,SAAS,GAAG,IAAI,CAAC,oBAAoB,EAAE;AACrD,QAAQ,OAAO;AACf,YAAY,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,GAAG,GAAG,CAAC,GAAG,GAAG;AAClD,YAAY,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,GAAG,GAAG,CAAC,GAAG,GAAG;AAClD,YAAY,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,GAAG,GAAG,CAAC,GAAG,GAAG;AAClD,SAAS;AACT,IAAI;AACJ;;;;;;;;;"}
package/dist/plugin.js CHANGED
@@ -37,9 +37,9 @@ var capacitorGyroscope = (function (exports, core) {
37
37
  });
38
38
  }
39
39
  async isAvailable() {
40
- let isAvailable = false;
40
+ let available = false;
41
41
  if (!this._isAvailable) {
42
- return { isAvailable };
42
+ return { available };
43
43
  }
44
44
  // According to an article on Chrome Developers (https://developer.chrome.com/docs/capabilities/web-apis/generic-sensor#feature-detection)
45
45
  // we also need to connect to the sensor for an actual meaningful feature detection
@@ -48,12 +48,12 @@ var capacitorGyroscope = (function (exports, core) {
48
48
  await new Promise(resolve => {
49
49
  gyroscope.onerror = (event) => {
50
50
  console.error(event);
51
- isAvailable = false;
51
+ available = false;
52
52
  gyroscope.stop();
53
53
  resolve();
54
54
  };
55
55
  gyroscope.onreading = () => {
56
- isAvailable = true;
56
+ available = true;
57
57
  gyroscope.stop();
58
58
  resolve();
59
59
  };
@@ -62,15 +62,9 @@ var capacitorGyroscope = (function (exports, core) {
62
62
  }
63
63
  catch (error) {
64
64
  console.error(error);
65
- isAvailable = false;
66
- }
67
- return { isAvailable };
68
- }
69
- async removeAllListeners() {
70
- await super.removeAllListeners();
71
- if (this.measurementEventStarted) {
72
- await this.stopMeasurementUpdates();
65
+ available = false;
73
66
  }
67
+ return { available };
74
68
  }
75
69
  async requestPermissions() {
76
70
  const { state } = await navigator.permissions.query({
@@ -102,6 +96,12 @@ var capacitorGyroscope = (function (exports, core) {
102
96
  gyroscope.stop();
103
97
  gyroscope.onreading = null;
104
98
  }
99
+ async removeAllListeners() {
100
+ await super.removeAllListeners();
101
+ if (this.measurementEventStarted) {
102
+ await this.stopMeasurementUpdates();
103
+ }
104
+ }
105
105
  // @ts-ignore
106
106
  createOrGetGyroscope() {
107
107
  if (!this._gyroscope) {
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst Gyroscope = registerPlugin('Gyroscope', {\n web: () => import('./web').then(m => new m.GyroscopeWeb()),\n});\nexport * from './definitions';\nexport { Gyroscope };\n//# sourceMappingURL=index.js.map","/* eslint-disable @typescript-eslint/ban-ts-comment */\nimport { CapacitorException, ExceptionCode, WebPlugin } from '@capacitor/core';\nexport class GyroscopeWeb extends WebPlugin {\n constructor() {\n super(...arguments);\n this._isAvailable = 'Gyroscope' in window;\n this.measurementEventStarted = false;\n }\n async checkPermissions() {\n const { state } = await navigator.permissions.query({\n name: 'gyroscope',\n });\n return { gyroscope: state };\n }\n async getMeasurement() {\n if (!this._isAvailable) {\n throw this.createUnavailableException();\n }\n const gyroscope = this.createOrGetGyroscope();\n return new Promise((resolve, reject) => {\n gyroscope.onerror = (event) => {\n console.error(event);\n reject(event);\n };\n gyroscope.onreading = () => {\n const measurement = this.readMeasurementFromGyroscope();\n gyroscope.stop();\n resolve(measurement);\n };\n gyroscope.start();\n });\n }\n async isAvailable() {\n let isAvailable = false;\n if (!this._isAvailable) {\n return { isAvailable };\n }\n // According to an article on Chrome Developers (https://developer.chrome.com/docs/capabilities/web-apis/generic-sensor#feature-detection)\n // we also need to connect to the sensor for an actual meaningful feature detection\n const gyroscope = this.createOrGetGyroscope();\n try {\n await new Promise(resolve => {\n gyroscope.onerror = (event) => {\n console.error(event);\n isAvailable = false;\n gyroscope.stop();\n resolve();\n };\n gyroscope.onreading = () => {\n isAvailable = true;\n gyroscope.stop();\n resolve();\n };\n gyroscope.start();\n });\n }\n catch (error) {\n console.error(error);\n isAvailable = false;\n }\n return { isAvailable };\n }\n async removeAllListeners() {\n await super.removeAllListeners();\n if (this.measurementEventStarted) {\n await this.stopMeasurementUpdates();\n }\n }\n async requestPermissions() {\n const { state } = await navigator.permissions.query({\n name: 'gyroscope',\n });\n return { gyroscope: state };\n }\n async startMeasurementUpdates() {\n if (!this._isAvailable) {\n throw this.createUnavailableException();\n }\n if (this.measurementEventStarted) {\n return;\n }\n this.measurementEventStarted = true;\n const gyroscope = this.createOrGetGyroscope();\n gyroscope.onreading = () => this.handleMeasurementEvent();\n gyroscope.start();\n }\n async stopMeasurementUpdates() {\n if (!this._isAvailable) {\n throw this.createUnavailableException();\n }\n if (!this.measurementEventStarted) {\n return;\n }\n this.measurementEventStarted = false;\n const gyroscope = this.createOrGetGyroscope();\n gyroscope.stop();\n gyroscope.onreading = null;\n }\n // @ts-ignore\n createOrGetGyroscope() {\n if (!this._gyroscope) {\n // @ts-ignore\n this._gyroscope = new Gyroscope({\n frequency: 10,\n });\n }\n return this._gyroscope;\n }\n createUnavailableException() {\n return new CapacitorException('This plugin method is not available on this platform.', ExceptionCode.Unavailable);\n }\n handleMeasurementEvent() {\n const measurement = this.readMeasurementFromGyroscope();\n this.notifyListeners('measurement', measurement);\n }\n readMeasurementFromGyroscope() {\n const gyroscope = this.createOrGetGyroscope();\n return {\n x: Math.round(gyroscope.x * 100) / 100,\n y: Math.round(gyroscope.y * 100) / 100,\n z: Math.round(gyroscope.z * 100) / 100,\n };\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["Gyroscope","registerPlugin","WebPlugin","CapacitorException","ExceptionCode"],"mappings":";;;AACK,UAACA,WAAS,GAAGC,mBAAc,CAAC,WAAW,EAAE;IAC9C,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,YAAY,EAAE,CAAC;IAC9D,CAAC;;ICHD;IAEO,MAAM,YAAY,SAASC,cAAS,CAAC;IAC5C,IAAI,WAAW,GAAG;IAClB,QAAQ,KAAK,CAAC,GAAG,SAAS,CAAC;IAC3B,QAAQ,IAAI,CAAC,YAAY,GAAG,WAAW,IAAI,MAAM;IACjD,QAAQ,IAAI,CAAC,uBAAuB,GAAG,KAAK;IAC5C,IAAI;IACJ,IAAI,MAAM,gBAAgB,GAAG;IAC7B,QAAQ,MAAM,EAAE,KAAK,EAAE,GAAG,MAAM,SAAS,CAAC,WAAW,CAAC,KAAK,CAAC;IAC5D,YAAY,IAAI,EAAE,WAAW;IAC7B,SAAS,CAAC;IACV,QAAQ,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE;IACnC,IAAI;IACJ,IAAI,MAAM,cAAc,GAAG;IAC3B,QAAQ,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE;IAChC,YAAY,MAAM,IAAI,CAAC,0BAA0B,EAAE;IACnD,QAAQ;IACR,QAAQ,MAAM,SAAS,GAAG,IAAI,CAAC,oBAAoB,EAAE;IACrD,QAAQ,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,KAAK;IAChD,YAAY,SAAS,CAAC,OAAO,GAAG,CAAC,KAAK,KAAK;IAC3C,gBAAgB,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC;IACpC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IAAI,EAAE;IACxB,QAAQ,SAAS,CAAC,SAAS,GAAG,IAAI;IAClC,IAAI;IACJ;IACA,IAAI,oBAAoB,GAAG;IAC3B,QAAQ,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE;IAC9B;IACA,YAAY,IAAI,CAAC,UAAU,GAAG,IAAI,SAAS,CAAC;IAC5C,gBAAgB,SAAS,EAAE,EAAE;IAC7B,aAAa,CAAC;IACd,QAAQ;IACR,QAAQ,OAAO,IAAI,CAAC,UAAU;IAC9B,IAAI;IACJ,IAAI,0BAA0B,GAAG;IACjC,QAAQ,OAAO,IAAIC,uBAAkB,CAAC,uDAAuD,EAAEC,kBAAa,CAAC,WAAW,CAAC;IACzH,IAAI;IACJ,IAAI,sBAAsB,GAAG;IAC7B,QAAQ,MAAM,WAAW,GAAG,IAAI,CAAC,4BAA4B,EAAE;IAC/D,QAAQ,IAAI,CAAC,eAAe,CAAC,aAAa,EAAE,WAAW,CAAC;IACxD,IAAI;IACJ,IAAI,4BAA4B,GAAG;IACnC,QAAQ,MAAM,SAAS,GAAG,IAAI,CAAC,oBAAoB,EAAE;IACrD,QAAQ,OAAO;IACf,YAAY,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,GAAG,GAAG,CAAC,GAAG,GAAG;IAClD,YAAY,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,GAAG,GAAG,CAAC,GAAG,GAAG;IAClD,YAAY,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,GAAG,GAAG,CAAC,GAAG,GAAG;IAClD,SAAS;IACT,IAAI;IACJ;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"plugin.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst Gyroscope = registerPlugin('Gyroscope', {\n web: () => import('./web').then(m => new m.GyroscopeWeb()),\n});\nexport * from './definitions';\nexport { Gyroscope };\n//# sourceMappingURL=index.js.map","/* eslint-disable @typescript-eslint/ban-ts-comment */\nimport { CapacitorException, ExceptionCode, WebPlugin } from '@capacitor/core';\nexport class GyroscopeWeb extends WebPlugin {\n constructor() {\n super(...arguments);\n this._isAvailable = 'Gyroscope' in window;\n this.measurementEventStarted = false;\n }\n async checkPermissions() {\n const { state } = await navigator.permissions.query({\n name: 'gyroscope',\n });\n return { gyroscope: state };\n }\n async getMeasurement() {\n if (!this._isAvailable) {\n throw this.createUnavailableException();\n }\n const gyroscope = this.createOrGetGyroscope();\n return new Promise((resolve, reject) => {\n gyroscope.onerror = (event) => {\n console.error(event);\n reject(event);\n };\n gyroscope.onreading = () => {\n const measurement = this.readMeasurementFromGyroscope();\n gyroscope.stop();\n resolve(measurement);\n };\n gyroscope.start();\n });\n }\n async isAvailable() {\n let available = false;\n if (!this._isAvailable) {\n return { available };\n }\n // According to an article on Chrome Developers (https://developer.chrome.com/docs/capabilities/web-apis/generic-sensor#feature-detection)\n // we also need to connect to the sensor for an actual meaningful feature detection\n const gyroscope = this.createOrGetGyroscope();\n try {\n await new Promise(resolve => {\n gyroscope.onerror = (event) => {\n console.error(event);\n available = false;\n gyroscope.stop();\n resolve();\n };\n gyroscope.onreading = () => {\n available = true;\n gyroscope.stop();\n resolve();\n };\n gyroscope.start();\n });\n }\n catch (error) {\n console.error(error);\n available = false;\n }\n return { available };\n }\n async requestPermissions() {\n const { state } = await navigator.permissions.query({\n name: 'gyroscope',\n });\n return { gyroscope: state };\n }\n async startMeasurementUpdates() {\n if (!this._isAvailable) {\n throw this.createUnavailableException();\n }\n if (this.measurementEventStarted) {\n return;\n }\n this.measurementEventStarted = true;\n const gyroscope = this.createOrGetGyroscope();\n gyroscope.onreading = () => this.handleMeasurementEvent();\n gyroscope.start();\n }\n async stopMeasurementUpdates() {\n if (!this._isAvailable) {\n throw this.createUnavailableException();\n }\n if (!this.measurementEventStarted) {\n return;\n }\n this.measurementEventStarted = false;\n const gyroscope = this.createOrGetGyroscope();\n gyroscope.stop();\n gyroscope.onreading = null;\n }\n async removeAllListeners() {\n await super.removeAllListeners();\n if (this.measurementEventStarted) {\n await this.stopMeasurementUpdates();\n }\n }\n // @ts-ignore\n createOrGetGyroscope() {\n if (!this._gyroscope) {\n // @ts-ignore\n this._gyroscope = new Gyroscope({\n frequency: 10,\n });\n }\n return this._gyroscope;\n }\n createUnavailableException() {\n return new CapacitorException('This plugin method is not available on this platform.', ExceptionCode.Unavailable);\n }\n handleMeasurementEvent() {\n const measurement = this.readMeasurementFromGyroscope();\n this.notifyListeners('measurement', measurement);\n }\n readMeasurementFromGyroscope() {\n const gyroscope = this.createOrGetGyroscope();\n return {\n x: Math.round(gyroscope.x * 100) / 100,\n y: Math.round(gyroscope.y * 100) / 100,\n z: Math.round(gyroscope.z * 100) / 100,\n };\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["Gyroscope","registerPlugin","WebPlugin","CapacitorException","ExceptionCode"],"mappings":";;;AACK,UAACA,WAAS,GAAGC,mBAAc,CAAC,WAAW,EAAE;IAC9C,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,YAAY,EAAE,CAAC;IAC9D,CAAC;;ICHD;IAEO,MAAM,YAAY,SAASC,cAAS,CAAC;IAC5C,IAAI,WAAW,GAAG;IAClB,QAAQ,KAAK,CAAC,GAAG,SAAS,CAAC;IAC3B,QAAQ,IAAI,CAAC,YAAY,GAAG,WAAW,IAAI,MAAM;IACjD,QAAQ,IAAI,CAAC,uBAAuB,GAAG,KAAK;IAC5C,IAAI;IACJ,IAAI,MAAM,gBAAgB,GAAG;IAC7B,QAAQ,MAAM,EAAE,KAAK,EAAE,GAAG,MAAM,SAAS,CAAC,WAAW,CAAC,KAAK,CAAC;IAC5D,YAAY,IAAI,EAAE,WAAW;IAC7B,SAAS,CAAC;IACV,QAAQ,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE;IACnC,IAAI;IACJ,IAAI,MAAM,cAA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CAAC,GAAG,GAAG;IAClD,YAAY,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,GAAG,GAAG,CAAC,GAAG,GAAG;IAClD,SAAS;IACT,IAAI;IACJ;;;;;;;;;;;;;;;"}
@@ -1,15 +1,15 @@
1
1
  import Capacitor
2
2
 
3
3
  @objc public class IsAvailableResult: NSObject, Result {
4
- private let isAvailable: Bool
4
+ private let available: Bool
5
5
 
6
- init(isAvailable: Bool) {
7
- self.isAvailable = isAvailable
6
+ init(available: Bool) {
7
+ self.available = available
8
8
  }
9
9
 
10
10
  public func toJSObject() -> AnyObject {
11
11
  var result = JSObject()
12
- result["isAvailable"] = isAvailable
12
+ result["available"] = available
13
13
  return result as AnyObject
14
14
  }
15
15
  }
@@ -45,7 +45,7 @@ import CoreMotion
45
45
  }
46
46
 
47
47
  @objc func isAvailable(completion: @escaping (IsAvailableResult?, Error?) -> Void) {
48
- completion(IsAvailableResult(isAvailable: motionManager.isGyroAvailable), nil)
48
+ completion(IsAvailableResult(available: motionManager.isGyroAvailable), nil)
49
49
  }
50
50
 
51
51
  @objc public func startMeasurementUpdates(completion: @escaping (Error?) -> Void) {
@@ -59,11 +59,6 @@ public class GyroscopePlugin: CAPPlugin, CAPBridgedPlugin {
59
59
  }
60
60
  }
61
61
 
62
- @objc override public func removeAllListeners(_ call: CAPPluginCall) {
63
- super.removeAllListeners(call)
64
- implementation?.stopMeasurementUpdates()
65
- }
66
-
67
62
  @objc override public func requestPermissions(_ call: CAPPluginCall) {
68
63
  call.resolve(["gyroscope": "granted"])
69
64
  }
@@ -93,6 +88,11 @@ public class GyroscopePlugin: CAPPlugin, CAPBridgedPlugin {
93
88
  }
94
89
  }
95
90
 
91
+ @objc override public func removeAllListeners(_ call: CAPPluginCall) {
92
+ super.removeAllListeners(call)
93
+ implementation?.stopMeasurementUpdates()
94
+ }
95
+
96
96
  private func hasUsageDescription(forKey key: String) -> Bool {
97
97
  return Bundle.main.object(forInfoDictionaryKey: key) is String
98
98
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@capawesome/capacitor-gyroscope",
3
- "version": "0.0.1",
4
- "description": "Capacitor plugin to read the device's gyroscope sensor.",
3
+ "version": "0.1.1",
4
+ "description": "Capacitor plugin to read the device's gyroscope sensor on Android and iOS.",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",
7
7
  "types": "dist/esm/index.d.ts",
@@ -33,11 +33,18 @@
33
33
  "url": "https://opencollective.com/capawesome"
34
34
  }
35
35
  ],
36
- "homepage": "https://capawesome.io/docs/plugins/gyroscope/",
36
+ "homepage": "https://capawesome.io/docs/sdks/capacitor/gyroscope/",
37
37
  "keywords": [
38
38
  "capacitor",
39
39
  "plugin",
40
- "native"
40
+ "native",
41
+ "capacitor-plugin",
42
+ "gyroscope",
43
+ "gyro",
44
+ "rotation rate",
45
+ "motion sensor",
46
+ "device motion",
47
+ "angular velocity"
41
48
  ],
42
49
  "scripts": {
43
50
  "verify": "npm run verify:ios && npm run verify:android && npm run verify:web",