@capgo/background-geolocation 7.0.9 → 7.0.10
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 +161 -68
- package/android/src/main/java/com/capgo/capacitor_background_geolocation/BackgroundGeolocation.java +25 -0
- package/android/src/main/java/com/capgo/capacitor_background_geolocation/BackgroundGeolocationService.java +76 -0
- package/dist/docs.json +90 -30
- package/dist/esm/definitions.d.ts +58 -31
- package/dist/esm/definitions.js.map +1 -1
- package/dist/esm/web.d.ts +2 -1
- package/dist/esm/web.js +12 -0
- package/dist/esm/web.js.map +1 -1
- package/dist/plugin.cjs.js +12 -0
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +12 -0
- package/dist/plugin.js.map +1 -1
- package/ios/Plugin/Plugin.m +1 -0
- package/ios/Plugin/Plugin.swift +26 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -9,48 +9,39 @@
|
|
|
9
9
|
A Capacitor plugin that lets you receive geolocation updates even while the app is backgrounded.
|
|
10
10
|
It has a web API to facilitate for a similar usage, but background geolocation is not supported in a regular browser, only in an app environment.
|
|
11
11
|
|
|
12
|
+
## This plugin's history
|
|
13
|
+
|
|
14
|
+
Interestingly enough, this plugin has a lot of history. The initial solution from [Transistorsoft](https://github.com/transistorsoft) was a great piece of software, and I encourage using it if it fits your needs.
|
|
15
|
+
I tried it and understood that it prioritizes battery life over accuracy, which wasn't the right fit for my hiking app.
|
|
16
|
+
There was a very good fork maintained by **mauron85** specifically for that use case, and I was happy to help maintain it.
|
|
17
|
+
But at some point, **mauron85** stopped responding to messages on GitHub, and no one could continue maintaining it.
|
|
18
|
+
I hope mauron85 is safe and sound somewhere.
|
|
19
|
+
|
|
20
|
+
So I created a fork and started maintaining it [here](https://github.com/HaylLtd/cordova-background-geolocation-plugin).
|
|
21
|
+
It served me well for over half a decade, but I felt it was hard to maintain due to all its history, features, and bug fixes.
|
|
22
|
+
I also felt like there was a barrier to introducing new features because of its complexity.
|
|
23
|
+
|
|
24
|
+
So I started exploring what it would take to reduce that complexity—at the same time, I was envious of how small [`@capacitor-community/background-geolocation`](https://github.com/capacitor-community/background-geolocation) is.
|
|
25
|
+
I took the best of both worlds: tried to reduce the codebase in the original Cordova plugin and add some robustness to the Capacitor plugin.
|
|
26
|
+
|
|
27
|
+
That's how I ended up maintaining this one.
|
|
28
|
+
I hope you'll enjoy it!
|
|
29
|
+
|
|
30
|
+
|
|
12
31
|
## Usage
|
|
13
32
|
|
|
14
33
|
```javascript
|
|
15
34
|
import { BackgroundGeolocation } from "@capgo/background-geolocation";
|
|
16
35
|
|
|
17
|
-
|
|
18
|
-
// You do this by calling 'addWatcher' with an options object and a callback. A
|
|
19
|
-
// Promise is returned, which resolves to the callback ID used to remove the
|
|
20
|
-
// watcher in the future. The callback will be called every time a new location
|
|
21
|
-
// is available. Watchers can not be paused, only removed. Multiple watchers may
|
|
22
|
-
// exist simultaneously.
|
|
23
|
-
BackgroundGeolocation.addWatcher(
|
|
36
|
+
BackgroundGeolocation.start(
|
|
24
37
|
{
|
|
25
|
-
// If the "backgroundMessage" option is defined, the watcher will
|
|
26
|
-
// provide location updates whether the app is in the background or the
|
|
27
|
-
// foreground. If it is not defined, location updates are only
|
|
28
|
-
// guaranteed in the foreground. This is true on both platforms.
|
|
29
|
-
|
|
30
|
-
// On Android, a notification must be shown to continue receiving
|
|
31
|
-
// location updates in the background. This option specifies the text of
|
|
32
|
-
// that notification.
|
|
33
38
|
backgroundMessage: "Cancel to prevent battery drain.",
|
|
34
|
-
|
|
35
|
-
// The title of the notification mentioned above. Defaults to "Using
|
|
36
|
-
// your location".
|
|
37
39
|
backgroundTitle: "Tracking You.",
|
|
38
|
-
|
|
39
|
-
// Whether permissions should be requested from the user automatically,
|
|
40
|
-
// if they are not already granted. Defaults to "true".
|
|
41
40
|
requestPermissions: true,
|
|
42
|
-
|
|
43
|
-
// If "true", stale locations may be delivered while the device
|
|
44
|
-
// obtains a GPS fix. You are responsible for checking the "time"
|
|
45
|
-
// property. If "false", locations are guaranteed to be up to date.
|
|
46
|
-
// Defaults to "false".
|
|
47
41
|
stale: false,
|
|
48
|
-
|
|
49
|
-
// The minimum number of metres between subsequent locations. Defaults
|
|
50
|
-
// to 0.
|
|
51
42
|
distanceFilter: 50
|
|
52
43
|
},
|
|
53
|
-
|
|
44
|
+
(location, error) => {
|
|
54
45
|
if (error) {
|
|
55
46
|
if (error.code === "NOT_AUTHORIZED") {
|
|
56
47
|
if (window.confirm(
|
|
@@ -67,56 +58,31 @@ BackgroundGeolocation.addWatcher(
|
|
|
67
58
|
}
|
|
68
59
|
return console.error(error);
|
|
69
60
|
}
|
|
70
|
-
|
|
61
|
+
// in case of off-track for example, play a sound:
|
|
62
|
+
BackgroundGeolocation.playSound({soundFile: "assets/myFile.mp3" });
|
|
71
63
|
return console.log(location);
|
|
72
64
|
}
|
|
73
|
-
).then(
|
|
74
|
-
// When
|
|
75
|
-
|
|
76
|
-
BackgroundGeolocation.removeWatcher({
|
|
77
|
-
id: watcher_id
|
|
78
|
-
});
|
|
65
|
+
).then(() => {
|
|
66
|
+
// When location updates are no longer needed, the plugin should be stopped by calling
|
|
67
|
+
BackgroundGeolocation.stop();
|
|
79
68
|
});
|
|
80
69
|
|
|
81
|
-
// The location object.
|
|
82
|
-
{
|
|
83
|
-
// Longitude in degrees.
|
|
84
|
-
longitude: 131.723423719132,
|
|
85
|
-
// Latitude in degrees.
|
|
86
|
-
latitude: -22.40106297456,
|
|
87
|
-
// Radius of horizontal uncertainty in metres, with 68% confidence.
|
|
88
|
-
accuracy: 11,
|
|
89
|
-
// Metres above sea level (or null).
|
|
90
|
-
altitude: 65,
|
|
91
|
-
// Vertical uncertainty in metres, with 68% confidence (or null).
|
|
92
|
-
altitudeAccuracy: 4,
|
|
93
|
-
// Deviation from true north in degrees (or null).
|
|
94
|
-
bearing: 159.60000610351562,
|
|
95
|
-
// True if the location was simulated by software, rather than GPS.
|
|
96
|
-
simulated: false,
|
|
97
|
-
// Speed in metres per second (or null).
|
|
98
|
-
speed: 23.51068878173828,
|
|
99
|
-
// Time the location was produced, in milliseconds since the unix epoch.
|
|
100
|
-
time: 1562731602000
|
|
101
|
-
}
|
|
102
|
-
|
|
103
70
|
// If you just want the current location, try something like this. The longer
|
|
104
|
-
// the timeout, the more accurate the guess will be. I wouldn't go below about
|
|
105
|
-
|
|
106
|
-
function guess_location(callback, timeout) {
|
|
71
|
+
// the timeout, the more accurate the guess will be. I wouldn't go below about 100ms.
|
|
72
|
+
function guessLocation(callback, timeout) {
|
|
107
73
|
let last_location;
|
|
108
|
-
BackgroundGeolocation.
|
|
74
|
+
BackgroundGeolocation.start(
|
|
109
75
|
{
|
|
110
76
|
requestPermissions: false,
|
|
111
77
|
stale: true
|
|
112
78
|
},
|
|
113
|
-
|
|
79
|
+
(location) => {
|
|
114
80
|
last_location = location || undefined;
|
|
115
81
|
}
|
|
116
|
-
).then(
|
|
117
|
-
setTimeout(
|
|
82
|
+
).then(() => {
|
|
83
|
+
setTimeout(() => {
|
|
118
84
|
callback(last_location);
|
|
119
|
-
BackgroundGeolocation.
|
|
85
|
+
BackgroundGeolocation.stop();
|
|
120
86
|
}, timeout);
|
|
121
87
|
});
|
|
122
88
|
}
|
|
@@ -128,7 +94,7 @@ This plugin supports Capacitor v7:
|
|
|
128
94
|
|
|
129
95
|
| Capacitor | Plugin |
|
|
130
96
|
|------------|--------|
|
|
131
|
-
| v7 |
|
|
97
|
+
| v7 | v7 |
|
|
132
98
|
|
|
133
99
|
```sh
|
|
134
100
|
npm install @capgo/background-geolocation
|
|
@@ -211,6 +177,133 @@ Configration specific to Android can be made in `strings.xml`:
|
|
|
211
177
|
* [`start(...)`](#start)
|
|
212
178
|
* [`stop()`](#stop)
|
|
213
179
|
* [`openSettings()`](#opensettings)
|
|
180
|
+
* [`playSound(...)`](#playsound)
|
|
214
181
|
* [Interfaces](#interfaces)
|
|
215
182
|
|
|
216
183
|
</docgen-index>
|
|
184
|
+
|
|
185
|
+
<docgen-api>
|
|
186
|
+
<!--Update the source file JSDoc comments and rerun docgen to update the docs below-->
|
|
187
|
+
|
|
188
|
+
Main plugin interface for background geolocation functionality.
|
|
189
|
+
Provides methods to manage location updates and access device settings.
|
|
190
|
+
|
|
191
|
+
### start(...)
|
|
192
|
+
|
|
193
|
+
```typescript
|
|
194
|
+
start(options: StartOptions, callback: (position?: Location | undefined, error?: CallbackError | undefined) => void) => Promise<void>
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
To start listening for changes in the device's location, call this method.
|
|
198
|
+
A Promise is returned to indicate that it finished the call. The callback will be called every time a new location
|
|
199
|
+
is available, or if there was an error when calling this method. Don't rely on promise rejection for this.
|
|
200
|
+
|
|
201
|
+
| Param | Type | Description |
|
|
202
|
+
| -------------- | ------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------- |
|
|
203
|
+
| **`options`** | <code><a href="#startoptions">StartOptions</a></code> | The configuration options |
|
|
204
|
+
| **`callback`** | <code>(position?: <a href="#location">Location</a>, error?: <a href="#callbackerror">CallbackError</a>) => void</code> | The callback function invoked when a new location is available or an error occurs |
|
|
205
|
+
|
|
206
|
+
**Since:** 7.0.9
|
|
207
|
+
|
|
208
|
+
--------------------
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
### stop()
|
|
212
|
+
|
|
213
|
+
```typescript
|
|
214
|
+
stop() => Promise<void>
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
Stops location updates.
|
|
218
|
+
|
|
219
|
+
**Since:** 7.0.9
|
|
220
|
+
|
|
221
|
+
--------------------
|
|
222
|
+
|
|
223
|
+
|
|
224
|
+
### openSettings()
|
|
225
|
+
|
|
226
|
+
```typescript
|
|
227
|
+
openSettings() => Promise<void>
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
Opens the device's location settings page.
|
|
231
|
+
Useful for directing users to enable location services or adjust permissions.
|
|
232
|
+
|
|
233
|
+
**Since:** 7.0.0
|
|
234
|
+
|
|
235
|
+
--------------------
|
|
236
|
+
|
|
237
|
+
|
|
238
|
+
### playSound(...)
|
|
239
|
+
|
|
240
|
+
```typescript
|
|
241
|
+
playSound(options: PlaySoundOptions) => Promise<void>
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
Plays a sound file.
|
|
245
|
+
This should be used to play a sound, in the background too.
|
|
246
|
+
The idea behind this is to allow the user to hear a sound when a new location is available or when going off track.
|
|
247
|
+
If you simply need to play a sound, you can use `@capgo/native-audio` plugin instead.
|
|
248
|
+
For Android, there's a need to start monitoring location updates first, otherwise the sound will not play.
|
|
249
|
+
|
|
250
|
+
| Param | Type | Description |
|
|
251
|
+
| ------------- | ------------------------------------------------------------- | --------------------------------- |
|
|
252
|
+
| **`options`** | <code><a href="#playsoundoptions">PlaySoundOptions</a></code> | The options for playing the sound |
|
|
253
|
+
|
|
254
|
+
**Since:** 7.0.10
|
|
255
|
+
|
|
256
|
+
--------------------
|
|
257
|
+
|
|
258
|
+
|
|
259
|
+
### Interfaces
|
|
260
|
+
|
|
261
|
+
|
|
262
|
+
#### StartOptions
|
|
263
|
+
|
|
264
|
+
The options for configuring for location updates.
|
|
265
|
+
|
|
266
|
+
| Prop | Type | Description | Default | Since |
|
|
267
|
+
| ------------------------ | -------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------- | ----- |
|
|
268
|
+
| **`backgroundMessage`** | <code>string</code> | If the "backgroundMessage" option is defined, the plugin will provide location updates whether the app is in the background or the foreground. If it is not defined, location updates are only guaranteed in the foreground. This is true on both platforms. On Android, a notification must be shown to continue receiving location updates in the background. This option specifies the text of that notification. | | 7.0.9 |
|
|
269
|
+
| **`backgroundTitle`** | <code>string</code> | The title of the notification mentioned above. | <code>"Using your location"</code> | 7.0.9 |
|
|
270
|
+
| **`requestPermissions`** | <code>boolean</code> | Whether permissions should be requested from the user automatically, if they are not already granted. | <code>true</code> | 7.0.9 |
|
|
271
|
+
| **`stale`** | <code>boolean</code> | If "true", stale locations may be delivered while the device obtains a GPS fix. You are responsible for checking the "time" property. If "false", locations are guaranteed to be up to date. | <code>false</code> | 7.0.9 |
|
|
272
|
+
| **`distanceFilter`** | <code>number</code> | The distance in meters that the device must move before a new location update is triggered. This is used to filter out small movements and reduce the number of updates. | <code>0</code> | 7.0.9 |
|
|
273
|
+
|
|
274
|
+
|
|
275
|
+
#### Location
|
|
276
|
+
|
|
277
|
+
Represents a geographical location with various attributes.
|
|
278
|
+
Contains all the standard location properties returned by GPS/network providers.
|
|
279
|
+
|
|
280
|
+
| Prop | Type | Description | Since |
|
|
281
|
+
| ---------------------- | --------------------------- | -------------------------------------------------------------------------------------------------------------------------------------- | ----- |
|
|
282
|
+
| **`latitude`** | <code>number</code> | Latitude in degrees. Range: -90.0 to +90.0 | 7.0.0 |
|
|
283
|
+
| **`longitude`** | <code>number</code> | Longitude in degrees. Range: -180.0 to +180.0 | 7.0.0 |
|
|
284
|
+
| **`accuracy`** | <code>number</code> | Radius of horizontal uncertainty in metres, with 68% confidence. Lower values indicate more accurate location. | 7.0.0 |
|
|
285
|
+
| **`altitude`** | <code>number \| null</code> | Metres above sea level (or null if not available). | 7.0.0 |
|
|
286
|
+
| **`altitudeAccuracy`** | <code>number \| null</code> | Vertical uncertainty in metres, with 68% confidence (or null if not available). | 7.0.0 |
|
|
287
|
+
| **`simulated`** | <code>boolean</code> | `true` if the location was simulated by software, rather than GPS. Useful for detecting mock locations in development or testing. | 7.0.0 |
|
|
288
|
+
| **`bearing`** | <code>number \| null</code> | Deviation from true north in degrees (or null if not available). Range: 0.0 to 360.0 | 7.0.0 |
|
|
289
|
+
| **`speed`** | <code>number \| null</code> | Speed in metres per second (or null if not available). | 7.0.0 |
|
|
290
|
+
| **`time`** | <code>number \| null</code> | Time the location was produced, in milliseconds since the unix epoch. Use this to check if a location is stale when using stale: true. | 7.0.0 |
|
|
291
|
+
|
|
292
|
+
|
|
293
|
+
#### CallbackError
|
|
294
|
+
|
|
295
|
+
Error object that may be passed to the location start callback.
|
|
296
|
+
Extends the standard Error with optional error codes.
|
|
297
|
+
|
|
298
|
+
| Prop | Type | Description | Since |
|
|
299
|
+
| ---------- | ------------------- | ----------------------------------------------------- | ----- |
|
|
300
|
+
| **`code`** | <code>string</code> | Optional error code for more specific error handling. | 7.0.0 |
|
|
301
|
+
|
|
302
|
+
|
|
303
|
+
#### PlaySoundOptions
|
|
304
|
+
|
|
305
|
+
| Prop | Type | Description | Since |
|
|
306
|
+
| --------------- | ------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------ |
|
|
307
|
+
| **`soundFile`** | <code>string</code> | The name of the sound file to play. Must be a valid sound relative path in the app's public folder to work for both web and native platforms. There's no need to include the public folder in the path. | 7.0.10 |
|
|
308
|
+
|
|
309
|
+
</docgen-api>
|
package/android/src/main/java/com/capgo/capacitor_background_geolocation/BackgroundGeolocation.java
CHANGED
|
@@ -188,6 +188,31 @@ public class BackgroundGeolocation extends Plugin {
|
|
|
188
188
|
call.resolve();
|
|
189
189
|
}
|
|
190
190
|
|
|
191
|
+
@PluginMethod
|
|
192
|
+
public void playSound(PluginCall call) {
|
|
193
|
+
String soundFile = call.getString("soundFile");
|
|
194
|
+
if (soundFile == null || soundFile.isEmpty()) {
|
|
195
|
+
call.reject("Sound file is required");
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
if (serviceConnectionFuture == null) {
|
|
199
|
+
call.reject(
|
|
200
|
+
"Service not started, make sure to call start() first",
|
|
201
|
+
"NOT_STARTED"
|
|
202
|
+
);
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
serviceConnectionFuture
|
|
206
|
+
.thenAccept(service -> {
|
|
207
|
+
service.playSound(soundFile);
|
|
208
|
+
call.resolve();
|
|
209
|
+
})
|
|
210
|
+
.exceptionally(throwable -> {
|
|
211
|
+
call.reject("Failed to play sound: " + throwable.getMessage());
|
|
212
|
+
return null;
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
|
|
191
216
|
// Checks if device-wide location services are disabled
|
|
192
217
|
private static Boolean isLocationEnabled(Context context) {
|
|
193
218
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
|
|
@@ -5,9 +5,12 @@ import android.app.PendingIntent;
|
|
|
5
5
|
import android.app.Service;
|
|
6
6
|
import android.content.Context;
|
|
7
7
|
import android.content.Intent;
|
|
8
|
+
import android.content.res.AssetFileDescriptor;
|
|
9
|
+
import android.content.res.AssetManager;
|
|
8
10
|
import android.graphics.Color;
|
|
9
11
|
import android.location.LocationListener;
|
|
10
12
|
import android.location.LocationManager;
|
|
13
|
+
import android.media.MediaPlayer;
|
|
11
14
|
import android.os.Binder;
|
|
12
15
|
import android.os.Build;
|
|
13
16
|
import android.os.IBinder;
|
|
@@ -30,6 +33,7 @@ public class BackgroundGeolocationService extends Service {
|
|
|
30
33
|
|
|
31
34
|
private LocationManager client;
|
|
32
35
|
private LocationListener locationCallback;
|
|
36
|
+
private MediaPlayer mediaPlayer;
|
|
33
37
|
|
|
34
38
|
@Override
|
|
35
39
|
public IBinder onBind(Intent intent) {
|
|
@@ -43,10 +47,33 @@ public class BackgroundGeolocationService extends Service {
|
|
|
43
47
|
@Override
|
|
44
48
|
public boolean onUnbind(Intent intent) {
|
|
45
49
|
client.removeUpdates(locationCallback);
|
|
50
|
+
releaseMediaPlayer();
|
|
46
51
|
stopSelf();
|
|
47
52
|
return false;
|
|
48
53
|
}
|
|
49
54
|
|
|
55
|
+
@Override
|
|
56
|
+
public void onDestroy() {
|
|
57
|
+
client.removeUpdates(locationCallback);
|
|
58
|
+
super.onDestroy();
|
|
59
|
+
releaseMediaPlayer();
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
private void releaseMediaPlayer() {
|
|
63
|
+
if (mediaPlayer == null) {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
try {
|
|
67
|
+
if (mediaPlayer.isPlaying()) {
|
|
68
|
+
mediaPlayer.stop();
|
|
69
|
+
}
|
|
70
|
+
mediaPlayer.release();
|
|
71
|
+
} catch (Exception e) {
|
|
72
|
+
Logger.error("Error releasing MediaPlayer", e);
|
|
73
|
+
}
|
|
74
|
+
mediaPlayer = null;
|
|
75
|
+
}
|
|
76
|
+
|
|
50
77
|
// Handles requests from the activity.
|
|
51
78
|
public class LocalBinder extends Binder {
|
|
52
79
|
|
|
@@ -106,6 +133,55 @@ public class BackgroundGeolocationService extends Service {
|
|
|
106
133
|
stopSelf();
|
|
107
134
|
return callbackId;
|
|
108
135
|
}
|
|
136
|
+
|
|
137
|
+
void playSound(String filePath) {
|
|
138
|
+
try {
|
|
139
|
+
releaseMediaPlayer();
|
|
140
|
+
|
|
141
|
+
mediaPlayer = new MediaPlayer();
|
|
142
|
+
|
|
143
|
+
AssetManager am = getApplicationContext().getResources().getAssets();
|
|
144
|
+
AssetFileDescriptor assetFileDescriptor = am.openFd(
|
|
145
|
+
"public/" + filePath
|
|
146
|
+
);
|
|
147
|
+
|
|
148
|
+
mediaPlayer.setDataSource(
|
|
149
|
+
assetFileDescriptor.getFileDescriptor(),
|
|
150
|
+
assetFileDescriptor.getStartOffset(),
|
|
151
|
+
assetFileDescriptor.getLength()
|
|
152
|
+
);
|
|
153
|
+
mediaPlayer.setLooping(false);
|
|
154
|
+
|
|
155
|
+
mediaPlayer.setOnCompletionListener(mp -> {
|
|
156
|
+
try {
|
|
157
|
+
mp.release();
|
|
158
|
+
} catch (Exception e) {
|
|
159
|
+
Logger.error("Error releasing MediaPlayer on completion", e);
|
|
160
|
+
}
|
|
161
|
+
mediaPlayer = null;
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
mediaPlayer.setOnErrorListener((mp, what, extra) -> {
|
|
165
|
+
Logger.error("MediaPlayer error: what=" + what + ", extra=" + extra);
|
|
166
|
+
releaseMediaPlayer();
|
|
167
|
+
return true; // Indicate we handled the error
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
mediaPlayer.prepareAsync();
|
|
171
|
+
mediaPlayer.setOnPreparedListener(mp -> {
|
|
172
|
+
try {
|
|
173
|
+
mp.start();
|
|
174
|
+
Logger.debug("PlaySound: Successfully started playing sound");
|
|
175
|
+
} catch (Exception e) {
|
|
176
|
+
Logger.error("Error starting MediaPlayer", e);
|
|
177
|
+
releaseMediaPlayer();
|
|
178
|
+
}
|
|
179
|
+
});
|
|
180
|
+
} catch (Exception e) {
|
|
181
|
+
Logger.error("PlaySound: Unexpected error", e);
|
|
182
|
+
releaseMediaPlayer();
|
|
183
|
+
}
|
|
184
|
+
}
|
|
109
185
|
}
|
|
110
186
|
|
|
111
187
|
private Notification createBackgroundNotification(
|
package/dist/docs.json
CHANGED
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
"api": {
|
|
3
3
|
"name": "BackgroundGeolocationPlugin",
|
|
4
4
|
"slug": "backgroundgeolocationplugin",
|
|
5
|
-
"docs": "Main plugin interface for background geolocation functionality.\nProvides methods to manage location
|
|
5
|
+
"docs": "Main plugin interface for background geolocation functionality.\nProvides methods to manage location updates and access device settings.",
|
|
6
6
|
"tags": [
|
|
7
7
|
{
|
|
8
|
-
"text": "
|
|
8
|
+
"text": "7.0.0",
|
|
9
9
|
"name": "since"
|
|
10
10
|
}
|
|
11
11
|
],
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"parameters": [
|
|
17
17
|
{
|
|
18
18
|
"name": "options",
|
|
19
|
-
"docs": "The
|
|
19
|
+
"docs": "The configuration options",
|
|
20
20
|
"type": "StartOptions"
|
|
21
21
|
},
|
|
22
22
|
{
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"tags": [
|
|
30
30
|
{
|
|
31
31
|
"name": "param",
|
|
32
|
-
"text": "options The
|
|
32
|
+
"text": "options The configuration options"
|
|
33
33
|
},
|
|
34
34
|
{
|
|
35
35
|
"name": "param",
|
|
@@ -37,18 +37,18 @@
|
|
|
37
37
|
},
|
|
38
38
|
{
|
|
39
39
|
"name": "returns",
|
|
40
|
-
"text": "A promise that resolves
|
|
40
|
+
"text": "A promise that resolves when the method is successfully called"
|
|
41
41
|
},
|
|
42
42
|
{
|
|
43
43
|
"name": "since",
|
|
44
|
-
"text": "
|
|
44
|
+
"text": "7.0.9"
|
|
45
45
|
},
|
|
46
46
|
{
|
|
47
47
|
"name": "example",
|
|
48
48
|
"text": "await BackgroundGeolocation.start(\n {\n backgroundMessage: \"App is using your location in the background\",\n backgroundTitle: \"Location Service\",\n requestPermissions: true,\n stale: false,\n distanceFilter: 10\n },\n (location, error) => {\n if (error) {\n console.error('Location error:', error);\n return;\n }\n if (location) {\n console.log('New location:', location.latitude, location.longitude);\n }\n }\n);"
|
|
49
49
|
}
|
|
50
50
|
],
|
|
51
|
-
"docs": "
|
|
51
|
+
"docs": "To start listening for changes in the device's location, call this method.\nA Promise is returned to indicate that it finished the call. The callback will be called every time a new location\nis available, or if there was an error when calling this method. Don't rely on promise rejection for this.",
|
|
52
52
|
"complexTypes": [
|
|
53
53
|
"StartOptions",
|
|
54
54
|
"Location",
|
|
@@ -64,11 +64,11 @@
|
|
|
64
64
|
"tags": [
|
|
65
65
|
{
|
|
66
66
|
"name": "returns",
|
|
67
|
-
"text": "A promise that resolves when the
|
|
67
|
+
"text": "A promise that resolves when the plugin stops successfully removed"
|
|
68
68
|
},
|
|
69
69
|
{
|
|
70
70
|
"name": "since",
|
|
71
|
-
"text": "
|
|
71
|
+
"text": "7.0.9"
|
|
72
72
|
},
|
|
73
73
|
{
|
|
74
74
|
"name": "example",
|
|
@@ -91,7 +91,7 @@
|
|
|
91
91
|
},
|
|
92
92
|
{
|
|
93
93
|
"name": "since",
|
|
94
|
-
"text": "
|
|
94
|
+
"text": "7.0.0"
|
|
95
95
|
},
|
|
96
96
|
{
|
|
97
97
|
"name": "example",
|
|
@@ -101,6 +101,41 @@
|
|
|
101
101
|
"docs": "Opens the device's location settings page.\nUseful for directing users to enable location services or adjust permissions.",
|
|
102
102
|
"complexTypes": [],
|
|
103
103
|
"slug": "opensettings"
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
"name": "playSound",
|
|
107
|
+
"signature": "(options: PlaySoundOptions) => Promise<void>",
|
|
108
|
+
"parameters": [
|
|
109
|
+
{
|
|
110
|
+
"name": "options",
|
|
111
|
+
"docs": "The options for playing the sound",
|
|
112
|
+
"type": "PlaySoundOptions"
|
|
113
|
+
}
|
|
114
|
+
],
|
|
115
|
+
"returns": "Promise<void>",
|
|
116
|
+
"tags": [
|
|
117
|
+
{
|
|
118
|
+
"name": "param",
|
|
119
|
+
"text": "options The options for playing the sound"
|
|
120
|
+
},
|
|
121
|
+
{
|
|
122
|
+
"name": "returns",
|
|
123
|
+
"text": "A promise that resolves when the sound is successfully played"
|
|
124
|
+
},
|
|
125
|
+
{
|
|
126
|
+
"name": "since",
|
|
127
|
+
"text": "7.0.10"
|
|
128
|
+
},
|
|
129
|
+
{
|
|
130
|
+
"name": "example",
|
|
131
|
+
"text": "await BackgroundGeolocation.playSound({\n soundFile: \"notification.mp3\"\n});"
|
|
132
|
+
}
|
|
133
|
+
],
|
|
134
|
+
"docs": "Plays a sound file.\nThis should be used to play a sound, in the background too.\nThe idea behind this is to allow the user to hear a sound when a new location is available or when going off track.\nIf you simply need to play a sound, you can use `@capgo/native-audio` plugin instead.\nFor Android, there's a need to start monitoring location updates first, otherwise the sound will not play.",
|
|
135
|
+
"complexTypes": [
|
|
136
|
+
"PlaySoundOptions"
|
|
137
|
+
],
|
|
138
|
+
"slug": "playsound"
|
|
104
139
|
}
|
|
105
140
|
],
|
|
106
141
|
"properties": []
|
|
@@ -112,7 +147,7 @@
|
|
|
112
147
|
"docs": "The options for configuring for location updates.",
|
|
113
148
|
"tags": [
|
|
114
149
|
{
|
|
115
|
-
"text": "
|
|
150
|
+
"text": "7.0.9",
|
|
116
151
|
"name": "since"
|
|
117
152
|
}
|
|
118
153
|
],
|
|
@@ -122,7 +157,7 @@
|
|
|
122
157
|
"name": "backgroundMessage",
|
|
123
158
|
"tags": [
|
|
124
159
|
{
|
|
125
|
-
"text": "
|
|
160
|
+
"text": "7.0.9",
|
|
126
161
|
"name": "since"
|
|
127
162
|
},
|
|
128
163
|
{
|
|
@@ -130,7 +165,7 @@
|
|
|
130
165
|
"name": "example"
|
|
131
166
|
}
|
|
132
167
|
],
|
|
133
|
-
"docs": "If the \"backgroundMessage\" option is defined, the
|
|
168
|
+
"docs": "If the \"backgroundMessage\" option is defined, the plugin will\nprovide location updates whether the app is in the background or the\nforeground. If it is not defined, location updates are only\nguaranteed in the foreground. This is true on both platforms.\n\nOn Android, a notification must be shown to continue receiving\nlocation updates in the background. This option specifies the text of\nthat notification.",
|
|
134
169
|
"complexTypes": [],
|
|
135
170
|
"type": "string | undefined"
|
|
136
171
|
},
|
|
@@ -138,7 +173,7 @@
|
|
|
138
173
|
"name": "backgroundTitle",
|
|
139
174
|
"tags": [
|
|
140
175
|
{
|
|
141
|
-
"text": "
|
|
176
|
+
"text": "7.0.9",
|
|
142
177
|
"name": "since"
|
|
143
178
|
},
|
|
144
179
|
{
|
|
@@ -158,7 +193,7 @@
|
|
|
158
193
|
"name": "requestPermissions",
|
|
159
194
|
"tags": [
|
|
160
195
|
{
|
|
161
|
-
"text": "
|
|
196
|
+
"text": "7.0.9",
|
|
162
197
|
"name": "since"
|
|
163
198
|
},
|
|
164
199
|
{
|
|
@@ -178,7 +213,7 @@
|
|
|
178
213
|
"name": "stale",
|
|
179
214
|
"tags": [
|
|
180
215
|
{
|
|
181
|
-
"text": "
|
|
216
|
+
"text": "7.0.9",
|
|
182
217
|
"name": "since"
|
|
183
218
|
},
|
|
184
219
|
{
|
|
@@ -198,7 +233,7 @@
|
|
|
198
233
|
"name": "distanceFilter",
|
|
199
234
|
"tags": [
|
|
200
235
|
{
|
|
201
|
-
"text": "
|
|
236
|
+
"text": "7.0.9",
|
|
202
237
|
"name": "since"
|
|
203
238
|
},
|
|
204
239
|
{
|
|
@@ -222,7 +257,7 @@
|
|
|
222
257
|
"docs": "Represents a geographical location with various attributes.\nContains all the standard location properties returned by GPS/network providers.",
|
|
223
258
|
"tags": [
|
|
224
259
|
{
|
|
225
|
-
"text": "
|
|
260
|
+
"text": "7.0.0",
|
|
226
261
|
"name": "since"
|
|
227
262
|
}
|
|
228
263
|
],
|
|
@@ -232,7 +267,7 @@
|
|
|
232
267
|
"name": "latitude",
|
|
233
268
|
"tags": [
|
|
234
269
|
{
|
|
235
|
-
"text": "
|
|
270
|
+
"text": "7.0.0",
|
|
236
271
|
"name": "since"
|
|
237
272
|
},
|
|
238
273
|
{
|
|
@@ -248,7 +283,7 @@
|
|
|
248
283
|
"name": "longitude",
|
|
249
284
|
"tags": [
|
|
250
285
|
{
|
|
251
|
-
"text": "
|
|
286
|
+
"text": "7.0.0",
|
|
252
287
|
"name": "since"
|
|
253
288
|
},
|
|
254
289
|
{
|
|
@@ -264,7 +299,7 @@
|
|
|
264
299
|
"name": "accuracy",
|
|
265
300
|
"tags": [
|
|
266
301
|
{
|
|
267
|
-
"text": "
|
|
302
|
+
"text": "7.0.0",
|
|
268
303
|
"name": "since"
|
|
269
304
|
},
|
|
270
305
|
{
|
|
@@ -280,7 +315,7 @@
|
|
|
280
315
|
"name": "altitude",
|
|
281
316
|
"tags": [
|
|
282
317
|
{
|
|
283
|
-
"text": "
|
|
318
|
+
"text": "7.0.0",
|
|
284
319
|
"name": "since"
|
|
285
320
|
},
|
|
286
321
|
{
|
|
@@ -296,7 +331,7 @@
|
|
|
296
331
|
"name": "altitudeAccuracy",
|
|
297
332
|
"tags": [
|
|
298
333
|
{
|
|
299
|
-
"text": "
|
|
334
|
+
"text": "7.0.0",
|
|
300
335
|
"name": "since"
|
|
301
336
|
},
|
|
302
337
|
{
|
|
@@ -312,7 +347,7 @@
|
|
|
312
347
|
"name": "simulated",
|
|
313
348
|
"tags": [
|
|
314
349
|
{
|
|
315
|
-
"text": "
|
|
350
|
+
"text": "7.0.0",
|
|
316
351
|
"name": "since"
|
|
317
352
|
},
|
|
318
353
|
{
|
|
@@ -328,7 +363,7 @@
|
|
|
328
363
|
"name": "bearing",
|
|
329
364
|
"tags": [
|
|
330
365
|
{
|
|
331
|
-
"text": "
|
|
366
|
+
"text": "7.0.0",
|
|
332
367
|
"name": "since"
|
|
333
368
|
},
|
|
334
369
|
{
|
|
@@ -344,7 +379,7 @@
|
|
|
344
379
|
"name": "speed",
|
|
345
380
|
"tags": [
|
|
346
381
|
{
|
|
347
|
-
"text": "
|
|
382
|
+
"text": "7.0.0",
|
|
348
383
|
"name": "since"
|
|
349
384
|
},
|
|
350
385
|
{
|
|
@@ -360,7 +395,7 @@
|
|
|
360
395
|
"name": "time",
|
|
361
396
|
"tags": [
|
|
362
397
|
{
|
|
363
|
-
"text": "
|
|
398
|
+
"text": "7.0.0",
|
|
364
399
|
"name": "since"
|
|
365
400
|
},
|
|
366
401
|
{
|
|
@@ -377,10 +412,10 @@
|
|
|
377
412
|
{
|
|
378
413
|
"name": "CallbackError",
|
|
379
414
|
"slug": "callbackerror",
|
|
380
|
-
"docs": "Error object that may be passed to the location
|
|
415
|
+
"docs": "Error object that may be passed to the location start callback.\nExtends the standard Error with optional error codes.",
|
|
381
416
|
"tags": [
|
|
382
417
|
{
|
|
383
|
-
"text": "
|
|
418
|
+
"text": "7.0.0",
|
|
384
419
|
"name": "since"
|
|
385
420
|
}
|
|
386
421
|
],
|
|
@@ -390,7 +425,7 @@
|
|
|
390
425
|
"name": "code",
|
|
391
426
|
"tags": [
|
|
392
427
|
{
|
|
393
|
-
"text": "
|
|
428
|
+
"text": "7.0.0",
|
|
394
429
|
"name": "since"
|
|
395
430
|
},
|
|
396
431
|
{
|
|
@@ -403,6 +438,31 @@
|
|
|
403
438
|
"type": "string | undefined"
|
|
404
439
|
}
|
|
405
440
|
]
|
|
441
|
+
},
|
|
442
|
+
{
|
|
443
|
+
"name": "PlaySoundOptions",
|
|
444
|
+
"slug": "playsoundoptions",
|
|
445
|
+
"docs": "",
|
|
446
|
+
"tags": [],
|
|
447
|
+
"methods": [],
|
|
448
|
+
"properties": [
|
|
449
|
+
{
|
|
450
|
+
"name": "soundFile",
|
|
451
|
+
"tags": [
|
|
452
|
+
{
|
|
453
|
+
"text": "7.0.10",
|
|
454
|
+
"name": "since"
|
|
455
|
+
},
|
|
456
|
+
{
|
|
457
|
+
"text": "\"notification.mp3\"",
|
|
458
|
+
"name": "example"
|
|
459
|
+
}
|
|
460
|
+
],
|
|
461
|
+
"docs": "The name of the sound file to play.\nMust be a valid sound relative path in the app's public folder to work for both web and native platforms.\nThere's no need to include the public folder in the path.",
|
|
462
|
+
"complexTypes": [],
|
|
463
|
+
"type": "string"
|
|
464
|
+
}
|
|
465
|
+
]
|
|
406
466
|
}
|
|
407
467
|
],
|
|
408
468
|
"enums": [],
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The options for configuring for location updates.
|
|
3
3
|
*
|
|
4
|
-
* @since
|
|
4
|
+
* @since 7.0.9
|
|
5
5
|
*/
|
|
6
6
|
export interface StartOptions {
|
|
7
7
|
/**
|
|
8
|
-
* If the "backgroundMessage" option is defined, the
|
|
8
|
+
* If the "backgroundMessage" option is defined, the plugin will
|
|
9
9
|
* provide location updates whether the app is in the background or the
|
|
10
10
|
* foreground. If it is not defined, location updates are only
|
|
11
11
|
* guaranteed in the foreground. This is true on both platforms.
|
|
@@ -14,14 +14,14 @@ export interface StartOptions {
|
|
|
14
14
|
* location updates in the background. This option specifies the text of
|
|
15
15
|
* that notification.
|
|
16
16
|
*
|
|
17
|
-
* @since
|
|
17
|
+
* @since 7.0.9
|
|
18
18
|
* @example "Getting your location to provide better service"
|
|
19
19
|
*/
|
|
20
20
|
backgroundMessage?: string;
|
|
21
21
|
/**
|
|
22
22
|
* The title of the notification mentioned above.
|
|
23
23
|
*
|
|
24
|
-
* @since
|
|
24
|
+
* @since 7.0.9
|
|
25
25
|
* @default "Using your location"
|
|
26
26
|
* @example "Location Service"
|
|
27
27
|
*/
|
|
@@ -30,7 +30,7 @@ export interface StartOptions {
|
|
|
30
30
|
* Whether permissions should be requested from the user automatically,
|
|
31
31
|
* if they are not already granted.
|
|
32
32
|
*
|
|
33
|
-
* @since
|
|
33
|
+
* @since 7.0.9
|
|
34
34
|
* @default true
|
|
35
35
|
* @example
|
|
36
36
|
* // Auto-request permissions
|
|
@@ -45,7 +45,7 @@ export interface StartOptions {
|
|
|
45
45
|
* obtains a GPS fix. You are responsible for checking the "time"
|
|
46
46
|
* property. If "false", locations are guaranteed to be up to date.
|
|
47
47
|
*
|
|
48
|
-
* @since
|
|
48
|
+
* @since 7.0.9
|
|
49
49
|
* @default false
|
|
50
50
|
* @example
|
|
51
51
|
* // Allow stale locations for faster initial response
|
|
@@ -59,7 +59,7 @@ export interface StartOptions {
|
|
|
59
59
|
* The distance in meters that the device must move before a new location update is triggered.
|
|
60
60
|
* This is used to filter out small movements and reduce the number of updates.
|
|
61
61
|
*
|
|
62
|
-
* @since
|
|
62
|
+
* @since 7.0.9
|
|
63
63
|
* @default 0
|
|
64
64
|
* @example
|
|
65
65
|
* // Update every 10 meters
|
|
@@ -74,14 +74,14 @@ export interface StartOptions {
|
|
|
74
74
|
* Represents a geographical location with various attributes.
|
|
75
75
|
* Contains all the standard location properties returned by GPS/network providers.
|
|
76
76
|
*
|
|
77
|
-
* @since
|
|
77
|
+
* @since 7.0.0
|
|
78
78
|
*/
|
|
79
79
|
export interface Location {
|
|
80
80
|
/**
|
|
81
81
|
* Latitude in degrees.
|
|
82
82
|
* Range: -90.0 to +90.0
|
|
83
83
|
*
|
|
84
|
-
* @since
|
|
84
|
+
* @since 7.0.0
|
|
85
85
|
* @example 40.7128
|
|
86
86
|
*/
|
|
87
87
|
latitude: number;
|
|
@@ -89,7 +89,7 @@ export interface Location {
|
|
|
89
89
|
* Longitude in degrees.
|
|
90
90
|
* Range: -180.0 to +180.0
|
|
91
91
|
*
|
|
92
|
-
* @since
|
|
92
|
+
* @since 7.0.0
|
|
93
93
|
* @example -74.0060
|
|
94
94
|
*/
|
|
95
95
|
longitude: number;
|
|
@@ -97,21 +97,21 @@ export interface Location {
|
|
|
97
97
|
* Radius of horizontal uncertainty in metres, with 68% confidence.
|
|
98
98
|
* Lower values indicate more accurate location.
|
|
99
99
|
*
|
|
100
|
-
* @since
|
|
100
|
+
* @since 7.0.0
|
|
101
101
|
* @example 5.0
|
|
102
102
|
*/
|
|
103
103
|
accuracy: number;
|
|
104
104
|
/**
|
|
105
105
|
* Metres above sea level (or null if not available).
|
|
106
106
|
*
|
|
107
|
-
* @since
|
|
107
|
+
* @since 7.0.0
|
|
108
108
|
* @example 10.5
|
|
109
109
|
*/
|
|
110
110
|
altitude: number | null;
|
|
111
111
|
/**
|
|
112
112
|
* Vertical uncertainty in metres, with 68% confidence (or null if not available).
|
|
113
113
|
*
|
|
114
|
-
* @since
|
|
114
|
+
* @since 7.0.0
|
|
115
115
|
* @example 3.0
|
|
116
116
|
*/
|
|
117
117
|
altitudeAccuracy: number | null;
|
|
@@ -119,7 +119,7 @@ export interface Location {
|
|
|
119
119
|
* `true` if the location was simulated by software, rather than GPS.
|
|
120
120
|
* Useful for detecting mock locations in development or testing.
|
|
121
121
|
*
|
|
122
|
-
* @since
|
|
122
|
+
* @since 7.0.0
|
|
123
123
|
* @example false
|
|
124
124
|
*/
|
|
125
125
|
simulated: boolean;
|
|
@@ -127,14 +127,14 @@ export interface Location {
|
|
|
127
127
|
* Deviation from true north in degrees (or null if not available).
|
|
128
128
|
* Range: 0.0 to 360.0
|
|
129
129
|
*
|
|
130
|
-
* @since
|
|
130
|
+
* @since 7.0.0
|
|
131
131
|
* @example 45.5
|
|
132
132
|
*/
|
|
133
133
|
bearing: number | null;
|
|
134
134
|
/**
|
|
135
135
|
* Speed in metres per second (or null if not available).
|
|
136
136
|
*
|
|
137
|
-
* @since
|
|
137
|
+
* @since 7.0.0
|
|
138
138
|
* @example 2.5
|
|
139
139
|
*/
|
|
140
140
|
speed: number | null;
|
|
@@ -142,43 +142,53 @@ export interface Location {
|
|
|
142
142
|
* Time the location was produced, in milliseconds since the unix epoch.
|
|
143
143
|
* Use this to check if a location is stale when using stale: true.
|
|
144
144
|
*
|
|
145
|
-
* @since
|
|
145
|
+
* @since 7.0.0
|
|
146
146
|
* @example 1640995200000
|
|
147
147
|
*/
|
|
148
148
|
time: number | null;
|
|
149
149
|
}
|
|
150
150
|
/**
|
|
151
|
-
* Error object that may be passed to the location
|
|
151
|
+
* Error object that may be passed to the location start callback.
|
|
152
152
|
* Extends the standard Error with optional error codes.
|
|
153
153
|
*
|
|
154
|
-
* @since
|
|
154
|
+
* @since 7.0.0
|
|
155
155
|
*/
|
|
156
156
|
export interface CallbackError extends Error {
|
|
157
157
|
/**
|
|
158
158
|
* Optional error code for more specific error handling.
|
|
159
159
|
*
|
|
160
|
-
* @since
|
|
160
|
+
* @since 7.0.0
|
|
161
161
|
* @example "PERMISSION_DENIED"
|
|
162
162
|
*/
|
|
163
163
|
code?: string;
|
|
164
164
|
}
|
|
165
|
+
export interface PlaySoundOptions {
|
|
166
|
+
/**
|
|
167
|
+
* The name of the sound file to play.
|
|
168
|
+
* Must be a valid sound relative path in the app's public folder to work for both web and native platforms.
|
|
169
|
+
* There's no need to include the public folder in the path.
|
|
170
|
+
* @since 7.0.10
|
|
171
|
+
* @example "notification.mp3"
|
|
172
|
+
* */
|
|
173
|
+
soundFile: string;
|
|
174
|
+
}
|
|
165
175
|
/**
|
|
166
176
|
* Main plugin interface for background geolocation functionality.
|
|
167
|
-
* Provides methods to manage location
|
|
177
|
+
* Provides methods to manage location updates and access device settings.
|
|
168
178
|
*
|
|
169
|
-
* @since
|
|
179
|
+
* @since 7.0.0
|
|
170
180
|
*/
|
|
171
181
|
export interface BackgroundGeolocationPlugin {
|
|
172
182
|
/**
|
|
173
|
-
*
|
|
174
|
-
*
|
|
175
|
-
*
|
|
183
|
+
* To start listening for changes in the device's location, call this method.
|
|
184
|
+
* A Promise is returned to indicate that it finished the call. The callback will be called every time a new location
|
|
185
|
+
* is available, or if there was an error when calling this method. Don't rely on promise rejection for this.
|
|
176
186
|
*
|
|
177
|
-
* @param options The
|
|
187
|
+
* @param options The configuration options
|
|
178
188
|
* @param callback The callback function invoked when a new location is available or an error occurs
|
|
179
|
-
* @returns A promise that resolves
|
|
189
|
+
* @returns A promise that resolves when the method is successfully called
|
|
180
190
|
*
|
|
181
|
-
* @since
|
|
191
|
+
* @since 7.0.9
|
|
182
192
|
* @example
|
|
183
193
|
* await BackgroundGeolocation.start(
|
|
184
194
|
* {
|
|
@@ -203,9 +213,9 @@ export interface BackgroundGeolocationPlugin {
|
|
|
203
213
|
/**
|
|
204
214
|
* Stops location updates.
|
|
205
215
|
*
|
|
206
|
-
* @returns A promise that resolves when the
|
|
216
|
+
* @returns A promise that resolves when the plugin stops successfully removed
|
|
207
217
|
*
|
|
208
|
-
* @since
|
|
218
|
+
* @since 7.0.9
|
|
209
219
|
* @example
|
|
210
220
|
* await BackgroundGeolocation.stop();
|
|
211
221
|
*/
|
|
@@ -216,10 +226,27 @@ export interface BackgroundGeolocationPlugin {
|
|
|
216
226
|
*
|
|
217
227
|
* @returns A promise that resolves when the settings page is opened
|
|
218
228
|
*
|
|
219
|
-
* @since
|
|
229
|
+
* @since 7.0.0
|
|
220
230
|
* @example
|
|
221
231
|
* // Direct user to location settings
|
|
222
232
|
* await BackgroundGeolocation.openSettings();
|
|
223
233
|
*/
|
|
224
234
|
openSettings(): Promise<void>;
|
|
235
|
+
/**
|
|
236
|
+
* Plays a sound file.
|
|
237
|
+
* This should be used to play a sound, in the background too.
|
|
238
|
+
* The idea behind this is to allow the user to hear a sound when a new location is available or when going off track.
|
|
239
|
+
* If you simply need to play a sound, you can use `@capgo/native-audio` plugin instead.
|
|
240
|
+
* For Android, there's a need to start monitoring location updates first, otherwise the sound will not play.
|
|
241
|
+
*
|
|
242
|
+
* @param options The options for playing the sound
|
|
243
|
+
* @returns A promise that resolves when the sound is successfully played
|
|
244
|
+
*
|
|
245
|
+
* @since 7.0.10
|
|
246
|
+
* @example
|
|
247
|
+
* await BackgroundGeolocation.playSound({
|
|
248
|
+
* soundFile: "notification.mp3"
|
|
249
|
+
* });
|
|
250
|
+
*/
|
|
251
|
+
playSound(options: PlaySoundOptions): Promise<void>;
|
|
225
252
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * The options for configuring for location updates.\n *\n * @since
|
|
1
|
+
{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * The options for configuring for location updates.\n *\n * @since 7.0.9\n */\nexport interface StartOptions {\n /**\n * If the \"backgroundMessage\" option is defined, the plugin will\n * provide location updates whether the app is in the background or the\n * foreground. If it is not defined, location updates are only\n * guaranteed in the foreground. This is true on both platforms.\n *\n * On Android, a notification must be shown to continue receiving\n * location updates in the background. This option specifies the text of\n * that notification.\n *\n * @since 7.0.9\n * @example \"Getting your location to provide better service\"\n */\n backgroundMessage?: string;\n /**\n * The title of the notification mentioned above.\n *\n * @since 7.0.9\n * @default \"Using your location\"\n * @example \"Location Service\"\n */\n backgroundTitle?: string;\n /**\n * Whether permissions should be requested from the user automatically,\n * if they are not already granted.\n *\n * @since 7.0.9\n * @default true\n * @example\n * // Auto-request permissions\n * requestPermissions: true\n *\n * // Don't auto-request, handle manually\n * requestPermissions: false\n */\n requestPermissions?: boolean;\n /**\n * If \"true\", stale locations may be delivered while the device\n * obtains a GPS fix. You are responsible for checking the \"time\"\n * property. If \"false\", locations are guaranteed to be up to date.\n *\n * @since 7.0.9\n * @default false\n * @example\n * // Allow stale locations for faster initial response\n * stale: true\n *\n * // Only fresh locations\n * stale: false\n */\n stale?: boolean;\n /**\n * The distance in meters that the device must move before a new location update is triggered.\n * This is used to filter out small movements and reduce the number of updates.\n *\n * @since 7.0.9\n * @default 0\n * @example\n * // Update every 10 meters\n * distanceFilter: 10\n *\n * // Update on any movement\n * distanceFilter: 0\n */\n distanceFilter?: number;\n}\n\n/**\n * Represents a geographical location with various attributes.\n * Contains all the standard location properties returned by GPS/network providers.\n *\n * @since 7.0.0\n */\nexport interface Location {\n /**\n * Latitude in degrees.\n * Range: -90.0 to +90.0\n *\n * @since 7.0.0\n * @example 40.7128\n */\n latitude: number;\n /**\n * Longitude in degrees.\n * Range: -180.0 to +180.0\n *\n * @since 7.0.0\n * @example -74.0060\n */\n longitude: number;\n /**\n * Radius of horizontal uncertainty in metres, with 68% confidence.\n * Lower values indicate more accurate location.\n *\n * @since 7.0.0\n * @example 5.0\n */\n accuracy: number;\n /**\n * Metres above sea level (or null if not available).\n *\n * @since 7.0.0\n * @example 10.5\n */\n altitude: number | null;\n /**\n * Vertical uncertainty in metres, with 68% confidence (or null if not available).\n *\n * @since 7.0.0\n * @example 3.0\n */\n altitudeAccuracy: number | null;\n /**\n * `true` if the location was simulated by software, rather than GPS.\n * Useful for detecting mock locations in development or testing.\n *\n * @since 7.0.0\n * @example false\n */\n simulated: boolean;\n /**\n * Deviation from true north in degrees (or null if not available).\n * Range: 0.0 to 360.0\n *\n * @since 7.0.0\n * @example 45.5\n */\n bearing: number | null;\n /**\n * Speed in metres per second (or null if not available).\n *\n * @since 7.0.0\n * @example 2.5\n */\n speed: number | null;\n /**\n * Time the location was produced, in milliseconds since the unix epoch.\n * Use this to check if a location is stale when using stale: true.\n *\n * @since 7.0.0\n * @example 1640995200000\n */\n time: number | null;\n}\n\n/**\n * Error object that may be passed to the location start callback.\n * Extends the standard Error with optional error codes.\n *\n * @since 7.0.0\n */\nexport interface CallbackError extends Error {\n /**\n * Optional error code for more specific error handling.\n *\n * @since 7.0.0\n * @example \"PERMISSION_DENIED\"\n */\n code?: string;\n}\n\nexport interface PlaySoundOptions {\n /**\n * The name of the sound file to play.\n * Must be a valid sound relative path in the app's public folder to work for both web and native platforms.\n * There's no need to include the public folder in the path.\n * @since 7.0.10\n * @example \"notification.mp3\"\n * */\n soundFile: string;\n}\n\n/**\n * Main plugin interface for background geolocation functionality.\n * Provides methods to manage location updates and access device settings.\n *\n * @since 7.0.0\n */\nexport interface BackgroundGeolocationPlugin {\n /**\n * To start listening for changes in the device's location, call this method.\n * A Promise is returned to indicate that it finished the call. The callback will be called every time a new location\n * is available, or if there was an error when calling this method. Don't rely on promise rejection for this.\n *\n * @param options The configuration options\n * @param callback The callback function invoked when a new location is available or an error occurs\n * @returns A promise that resolves when the method is successfully called\n *\n * @since 7.0.9\n * @example\n * await BackgroundGeolocation.start(\n * {\n * backgroundMessage: \"App is using your location in the background\",\n * backgroundTitle: \"Location Service\",\n * requestPermissions: true,\n * stale: false,\n * distanceFilter: 10\n * },\n * (location, error) => {\n * if (error) {\n * console.error('Location error:', error);\n * return;\n * }\n * if (location) {\n * console.log('New location:', location.latitude, location.longitude);\n * }\n * }\n * );\n */\n start(\n options: StartOptions,\n callback: (position?: Location, error?: CallbackError) => void,\n ): Promise<void>;\n\n /**\n * Stops location updates.\n *\n * @returns A promise that resolves when the plugin stops successfully removed\n *\n * @since 7.0.9\n * @example\n * await BackgroundGeolocation.stop();\n */\n stop(): Promise<void>;\n\n /**\n * Opens the device's location settings page.\n * Useful for directing users to enable location services or adjust permissions.\n *\n * @returns A promise that resolves when the settings page is opened\n *\n * @since 7.0.0\n * @example\n * // Direct user to location settings\n * await BackgroundGeolocation.openSettings();\n */\n openSettings(): Promise<void>;\n\n /**\n * Plays a sound file.\n * This should be used to play a sound, in the background too.\n * The idea behind this is to allow the user to hear a sound when a new location is available or when going off track.\n * If you simply need to play a sound, you can use `@capgo/native-audio` plugin instead.\n * For Android, there's a need to start monitoring location updates first, otherwise the sound will not play.\n *\n * @param options The options for playing the sound\n * @returns A promise that resolves when the sound is successfully played\n *\n * @since 7.0.10\n * @example\n * await BackgroundGeolocation.playSound({\n * soundFile: \"notification.mp3\"\n * });\n */\n playSound(options: PlaySoundOptions): Promise<void>;\n}\n"]}
|
package/dist/esm/web.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { WebPlugin } from "@capacitor/core";
|
|
2
|
-
import type { BackgroundGeolocationPlugin, StartOptions, Location, CallbackError } from "./definitions";
|
|
2
|
+
import type { BackgroundGeolocationPlugin, StartOptions, Location, CallbackError, PlaySoundOptions } from "./definitions";
|
|
3
3
|
export declare class BackgroundGeolocationWeb extends WebPlugin implements BackgroundGeolocationPlugin {
|
|
4
4
|
private watchId;
|
|
5
5
|
start(options: StartOptions, callback: (position?: Location, error?: CallbackError) => void): Promise<void>;
|
|
6
6
|
stop(): Promise<void>;
|
|
7
7
|
openSettings(): Promise<void>;
|
|
8
|
+
playSound(options: PlaySoundOptions): Promise<void>;
|
|
8
9
|
}
|
package/dist/esm/web.js
CHANGED
|
@@ -53,5 +53,17 @@ export class BackgroundGeolocationWeb extends WebPlugin {
|
|
|
53
53
|
console.log("openSettings: Web implementation cannot open native settings");
|
|
54
54
|
window.alert("Please enable location permissions in your browser settings");
|
|
55
55
|
}
|
|
56
|
+
async playSound(options) {
|
|
57
|
+
if (!options.soundFile) {
|
|
58
|
+
throw new Error("Sound file is required");
|
|
59
|
+
}
|
|
60
|
+
const audio = new Audio(options.soundFile);
|
|
61
|
+
try {
|
|
62
|
+
await audio.play();
|
|
63
|
+
}
|
|
64
|
+
catch (error) {
|
|
65
|
+
throw new Error(`Failed to play sound: ${error.message}`);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
56
68
|
}
|
|
57
69
|
//# sourceMappingURL=web.js.map
|
package/dist/esm/web.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"web.js","sourceRoot":"","sources":["../../src/web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"web.js","sourceRoot":"","sources":["../../src/web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAU5C,MAAM,OAAO,w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,QAAQ,EAAE;aAC5B,CAAC;YACF,QAAQ,CAAC,SAAS,EAAE,aAAa,CAAC,CAAC;QACrC,CAAC,EACD;YACE,kBAAkB,EAAE,IAAI;YACxB,OAAO,EAAE,KAAK;YACd,UAAU,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;SACvC,CACF,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,IAAI;QACR,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;YACjB,SAAS,CAAC,WAAW,CAAC,UAAU,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;YAC/C,OAAO,IAAI,CAAC,OAAO,CAAC;QACtB,CAAC;IACH,CAAC;IAED,KAAK,CAAC,YAAY;QAChB,OAAO,CAAC,GAAG,CAAC,8DAA8D,CAAC,CAAC;QAC5E,MAAM,CAAC,KAAK,CAAC,6DAA6D,CAAC,CAAC;IAC9E,CAAC;IAED,KAAK,CAAC,SAAS,CAAC,OAAyB;QACvC,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,CAAC;YACvB,MAAM,IAAI,KAAK,CAAC,wBAAwB,CAAC,CAAC;QAC5C,CAAC;QACD,MAAM,KAAK,GAAG,IAAI,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;QAC3C,IAAI,CAAC;YACH,MAAM,KAAK,CAAC,IAAI,EAAE,CAAC;QACrB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,IAAI,KAAK,CAAC,yBAA0B,KAAe,CAAC,OAAO,EAAE,CAAC,CAAC;QACvE,CAAC;IACH,CAAC;CACF","sourcesContent":["import { WebPlugin } from \"@capacitor/core\";\n\nimport type {\n BackgroundGeolocationPlugin,\n StartOptions,\n Location,\n CallbackError,\n PlaySoundOptions,\n} from \"./definitions\";\n\nexport class BackgroundGeolocationWeb\n extends WebPlugin\n implements BackgroundGeolocationPlugin\n{\n private watchId: number | undefined;\n\n async start(\n options: StartOptions,\n callback: (position?: Location, error?: CallbackError) => void,\n ): Promise<void> {\n if (!navigator.geolocation) {\n callback(undefined, {\n name: \"GeolocationError\",\n message: \"Geolocation is not supported by this browser\",\n code: \"NOT_SUPPORTED\",\n });\n return;\n }\n\n if (this.watchId) {\n callback(undefined, {\n name: \"GeolocationError\",\n message: \"Geolocation already started\",\n code: \"ALREADY_STARTED\",\n });\n return;\n }\n\n this.watchId = navigator.geolocation.watchPosition(\n (position) => {\n const location: Location = {\n latitude: position.coords.latitude,\n longitude: position.coords.longitude,\n accuracy: position.coords.accuracy,\n altitude: position.coords.altitude,\n altitudeAccuracy: position.coords.altitudeAccuracy,\n simulated: false,\n bearing: position.coords.heading,\n speed: position.coords.speed,\n time: position.timestamp,\n };\n callback(location);\n },\n (error) => {\n const callbackError: CallbackError = {\n name: \"GeolocationError\",\n message: error.message,\n code: error.code.toString(),\n };\n callback(undefined, callbackError);\n },\n {\n enableHighAccuracy: true,\n timeout: 10000,\n maximumAge: options.stale ? 300000 : 0,\n },\n );\n }\n\n async stop(): Promise<void> {\n if (this.watchId) {\n navigator.geolocation.clearWatch(this.watchId);\n delete this.watchId;\n }\n }\n\n async openSettings(): Promise<void> {\n console.log(\"openSettings: Web implementation cannot open native settings\");\n window.alert(\"Please enable location permissions in your browser settings\");\n }\n\n async playSound(options: PlaySoundOptions): Promise<void> {\n if (!options.soundFile) {\n throw new Error(\"Sound file is required\");\n }\n const audio = new Audio(options.soundFile);\n try {\n await audio.play();\n } catch (error) {\n throw new Error(`Failed to play sound: ${(error as Error).message}`);\n }\n }\n}\n"]}
|
package/dist/plugin.cjs.js
CHANGED
|
@@ -60,6 +60,18 @@ class BackgroundGeolocationWeb extends core.WebPlugin {
|
|
|
60
60
|
console.log("openSettings: Web implementation cannot open native settings");
|
|
61
61
|
window.alert("Please enable location permissions in your browser settings");
|
|
62
62
|
}
|
|
63
|
+
async playSound(options) {
|
|
64
|
+
if (!options.soundFile) {
|
|
65
|
+
throw new Error("Sound file is required");
|
|
66
|
+
}
|
|
67
|
+
const audio = new Audio(options.soundFile);
|
|
68
|
+
try {
|
|
69
|
+
await audio.play();
|
|
70
|
+
}
|
|
71
|
+
catch (error) {
|
|
72
|
+
throw new Error(`Failed to play sound: ${error.message}`);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
63
75
|
}
|
|
64
76
|
|
|
65
77
|
var web = /*#__PURE__*/Object.freeze({
|
package/dist/plugin.cjs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.cjs.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from \"@capacitor/core\";\nconst BackgroundGeolocation = registerPlugin(\"BackgroundGeolocation\", {\n web: () => import(\"./web\").then((m) => new m.BackgroundGeolocationWeb()),\n});\nexport * from \"./definitions\";\nexport { BackgroundGeolocation };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from \"@capacitor/core\";\nexport class BackgroundGeolocationWeb extends WebPlugin {\n async start(options, callback) {\n if (!navigator.geolocation) {\n callback(undefined, {\n name: \"GeolocationError\",\n message: \"Geolocation is not supported by this browser\",\n code: \"NOT_SUPPORTED\",\n });\n return;\n }\n if (this.watchId) {\n callback(undefined, {\n name: \"GeolocationError\",\n message: \"Geolocation already started\",\n code: \"ALREADY_STARTED\",\n });\n return;\n }\n this.watchId = navigator.geolocation.watchPosition((position) => {\n const location = {\n latitude: position.coords.latitude,\n longitude: position.coords.longitude,\n accuracy: position.coords.accuracy,\n altitude: position.coords.altitude,\n altitudeAccuracy: position.coords.altitudeAccuracy,\n simulated: false,\n bearing: position.coords.heading,\n speed: position.coords.speed,\n time: position.timestamp,\n };\n callback(location);\n }, (error) => {\n const callbackError = {\n name: \"GeolocationError\",\n message: error.message,\n code: error.code.toString(),\n };\n callback(undefined, callbackError);\n }, {\n enableHighAccuracy: true,\n timeout: 10000,\n maximumAge: options.stale ? 300000 : 0,\n });\n }\n async stop() {\n if (this.watchId) {\n navigator.geolocation.clearWatch(this.watchId);\n delete this.watchId;\n }\n }\n async openSettings() {\n console.log(\"openSettings: Web implementation cannot open native settings\");\n window.alert(\"Please enable location permissions in your browser settings\");\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;;AACK,MAAC,qBAAqB,GAAGA,mBAAc,CAAC,uBAAuB,EAAE;AACtE,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,wBAAwB,EAAE,CAAC;AAC5E,CAAC;;ACFM,MAAM,wBAAwB,SAASC,cAAS,CAAC;AACxD,IAAI,MAAM,KAAK,CAAC,OAAO,EAAE,QAAQ,EAAE;AACnC,QAAQ,IAAI,CAAC,SAAS,CAAC,WAAW,EAAE;AACpC,YAAY,QAAQ,CAAC,SAAS,EAAE;AAChC,gBAAgB,IAAI,EAAE,kBAAkB;AACxC,gBAAgB,OAAO,EAAE,8CAA8C;AACvE,gBAAgB,IAAI,EAAE,eAAe;AACrC,aAAa,CAAC;AACd,YAAY;AACZ,QAAQ;AACR,QAAQ,IAAI,IAAI,CAAC,OAAO,EAAE;AAC1B,YAAY,QAAQ,CAAC,SAAS,EAAE;AAChC,gBAAgB,IAAI,EAAE,kBAAkB;AACxC,gBAAgB,OAAO,EAAE,6BAA6B;AACtD,gBAAgB,IAAI,EAAE,iBAAiB;AACvC,aAAa,CAAC;AACd,YAAY;AACZ,QAAQ;AACR,QAAQ,IAAI,CAAC,OAAO,GAAG,SAAS,CAAC,WAAW,CAAC,aAAa,CAAC,CAAC,QAAQ,KAAK;AACzE,YAAY,MAAM,QAAQ,GAAG;AAC7B,gBAAgB,QAAQ,EAAE,QAAQ,CAAC,MAAM,CAAC,QAAQ;AAClD,gBAAgB,SAAS,EAAE,QAAQ,CAAC,MAAM,CAAC,SAAS;AACpD,gBAAgB,QAAQ,EAAE,QAAQ,CAAC,MAAM,CAAC,QAAQ;AAClD,gBAAgB,QAAQ,EAAE,QAAQ,CAAC,MAAM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erPlugin } from \"@capacitor/core\";\nconst BackgroundGeolocation = registerPlugin(\"BackgroundGeolocation\", {\n web: () => import(\"./web\").then((m) => new m.BackgroundGeolocationWeb()),\n});\nexport * from \"./definitions\";\nexport { BackgroundGeolocation };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from \"@capacitor/core\";\nexport class BackgroundGeolocationWeb extends WebPlugin {\n async start(options, callback) {\n if (!navigator.geolocation) {\n callback(undefined, {\n name: \"GeolocationError\",\n message: \"Geolocation is not supported by this browser\",\n code: \"NOT_SUPPORTED\",\n });\n return;\n }\n if (this.watchId) {\n callback(undefined, {\n name: \"GeolocationError\",\n message: \"Geolocation already started\",\n code: \"ALREADY_STARTED\",\n });\n return;\n }\n this.watchId = navigator.geolocation.watchPosition((position) => {\n const location = {\n latitude: position.coords.latitude,\n longitude: position.coords.longitude,\n accuracy: position.coords.accuracy,\n altitude: position.coords.altitude,\n altitudeAccuracy: position.coords.altitudeAccuracy,\n simulated: false,\n bearing: position.coords.heading,\n speed: position.coords.speed,\n time: position.timestamp,\n };\n callback(location);\n }, (error) => {\n const callbackError = {\n name: \"GeolocationError\",\n message: error.message,\n code: error.code.toString(),\n };\n callback(undefined, callbackError);\n }, {\n enableHighAccuracy: true,\n timeout: 10000,\n maximumAge: options.stale ? 300000 : 0,\n });\n }\n async stop() {\n if (this.watchId) {\n navigator.geolocation.clearWatch(this.watchId);\n delete this.watchId;\n }\n }\n async openSettings() {\n console.log(\"openSettings: Web implementation cannot open native settings\");\n window.alert(\"Please enable location permissions in your browser settings\");\n }\n async playSound(options) {\n if (!options.soundFile) {\n throw new Error(\"Sound file is required\");\n }\n const audio = new Audio(options.soundFile);\n try {\n await audio.play();\n }\n catch (error) {\n throw new Error(`Failed to play sound: ${error.message}`);\n }\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;;AACK,MAAC,qBAAqB,GAAGA,mBAAc,CAAC,uBAAuB,EAAE;AACtE,IAAI,GAAG,EA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AO,KAAK,EAAE;AACtB,YAAY,MAAM,IAAI,KAAK,CAAC,CAAC,sBAAsB,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC;AACrE,QAAQ;AACR,IAAI;AACJ;;;;;;;;;"}
|
package/dist/plugin.js
CHANGED
|
@@ -59,6 +59,18 @@ var capacitorBackgroundGeolocation = (function (exports, core) {
|
|
|
59
59
|
console.log("openSettings: Web implementation cannot open native settings");
|
|
60
60
|
window.alert("Please enable location permissions in your browser settings");
|
|
61
61
|
}
|
|
62
|
+
async playSound(options) {
|
|
63
|
+
if (!options.soundFile) {
|
|
64
|
+
throw new Error("Sound file is required");
|
|
65
|
+
}
|
|
66
|
+
const audio = new Audio(options.soundFile);
|
|
67
|
+
try {
|
|
68
|
+
await audio.play();
|
|
69
|
+
}
|
|
70
|
+
catch (error) {
|
|
71
|
+
throw new Error(`Failed to play sound: ${error.message}`);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
62
74
|
}
|
|
63
75
|
|
|
64
76
|
var web = /*#__PURE__*/Object.freeze({
|
package/dist/plugin.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from \"@capacitor/core\";\nconst BackgroundGeolocation = registerPlugin(\"BackgroundGeolocation\", {\n web: () => import(\"./web\").then((m) => new m.BackgroundGeolocationWeb()),\n});\nexport * from \"./definitions\";\nexport { BackgroundGeolocation };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from \"@capacitor/core\";\nexport class BackgroundGeolocationWeb extends WebPlugin {\n async start(options, callback) {\n if (!navigator.geolocation) {\n callback(undefined, {\n name: \"GeolocationError\",\n message: \"Geolocation is not supported by this browser\",\n code: \"NOT_SUPPORTED\",\n });\n return;\n }\n if (this.watchId) {\n callback(undefined, {\n name: \"GeolocationError\",\n message: \"Geolocation already started\",\n code: \"ALREADY_STARTED\",\n });\n return;\n }\n this.watchId = navigator.geolocation.watchPosition((position) => {\n const location = {\n latitude: position.coords.latitude,\n longitude: position.coords.longitude,\n accuracy: position.coords.accuracy,\n altitude: position.coords.altitude,\n altitudeAccuracy: position.coords.altitudeAccuracy,\n simulated: false,\n bearing: position.coords.heading,\n speed: position.coords.speed,\n time: position.timestamp,\n };\n callback(location);\n }, (error) => {\n const callbackError = {\n name: \"GeolocationError\",\n message: error.message,\n code: error.code.toString(),\n };\n callback(undefined, callbackError);\n }, {\n enableHighAccuracy: true,\n timeout: 10000,\n maximumAge: options.stale ? 300000 : 0,\n });\n }\n async stop() {\n if (this.watchId) {\n navigator.geolocation.clearWatch(this.watchId);\n delete this.watchId;\n }\n }\n async openSettings() {\n console.log(\"openSettings: Web implementation cannot open native settings\");\n window.alert(\"Please enable location permissions in your browser settings\");\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;AACK,UAAC,qBAAqB,GAAGA,mBAAc,CAAC,uBAAuB,EAAE;IACtE,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,wBAAwB,EAAE,CAAC;IAC5E,CAAC;;ICFM,MAAM,wBAAwB,SAASC,cAAS,CAAC;IACxD,IAAI,MAAM,KAAK,CAAC,OAAO,EAAE,QAAQ,EAAE;IACnC,QAAQ,IAAI,CAAC,SAAS,CAAC,WAAW,EAAE;IACpC,YAAY,QAAQ,CAAC,SAAS,EAAE;IAChC,gBAAgB,IAAI,EAAE,kBAAkB;IACxC,gBAAgB,OAAO,EAAE,8CAA8C;IACvE,gBAAgB,IAAI,EAAE,eAAe;IACrC,aAAa,CAAC;IACd,YAAY;IACZ,QAAQ;IACR,QAAQ,IAAI,IAAI,CAAC,OAAO,EAAE;IAC1B,YAAY,QAAQ,CAAC,SAAS,EAAE;IAChC,gBAAgB,IAAI,EAAE,kBAAkB;IACxC,gBAAgB,OAAO,EAAE,6BAA6B;IACtD,gBAAgB,IAAI,EAAE,i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AAI,CAAC,OAAO,EAAE;IAC1B,YAAY,SAAS,CAAC,WAAW,CAAC,UAAU,CAAC,IAAI,CAAC,OAAO,CAAC;IAC1D,YAAY,OAAO,IAAI,CAAC,OAAO;IAC/B,QAAQ;IACR,IAAI;IACJ,IAAI,MAAM,YAAY,GAAG;IACzB,QAAQ,OAAO,CAAC,GAAG,CAAC,8DAA8D,CAAC;IACnF,QAAQ,MAAM,CAAC,KAAK,CAAC,6DAA6D,CAAC;IACnF,IAAI;IACJ;;;;;;;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"plugin.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from \"@capacitor/core\";\nconst BackgroundGeolocation = registerPlugin(\"BackgroundGeolocation\", {\n web: () => import(\"./web\").then((m) => new m.BackgroundGeolocationWeb()),\n});\nexport * from \"./definitions\";\nexport { BackgroundGeolocation };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from \"@capacitor/core\";\nexport class BackgroundGeolocationWeb extends WebPlugin {\n async start(options, callback) {\n if (!navigator.geolocation) {\n callback(undefined, {\n name: \"GeolocationError\",\n message: \"Geolocation is not supported by this browser\",\n code: \"NOT_SUPPORTED\",\n });\n return;\n }\n if (this.watchId) {\n callback(undefined, {\n name: \"GeolocationError\",\n message: \"Geolocation already started\",\n code: \"ALREADY_STARTED\",\n });\n return;\n }\n this.watchId = navigator.geolocation.watchPosition((position) => {\n const location = {\n latitude: position.coords.latitude,\n longitude: position.coords.longitude,\n accuracy: position.coords.accuracy,\n altitude: position.coords.altitude,\n altitudeAccuracy: position.coords.altitudeAccuracy,\n simulated: false,\n bearing: position.coords.heading,\n speed: position.coords.speed,\n time: position.timestamp,\n };\n callback(location);\n }, (error) => {\n const callbackError = {\n name: \"GeolocationError\",\n message: error.message,\n code: error.code.toString(),\n };\n callback(undefined, callbackError);\n }, {\n enableHighAccuracy: true,\n timeout: 10000,\n maximumAge: options.stale ? 300000 : 0,\n });\n }\n async stop() {\n if (this.watchId) {\n navigator.geolocation.clearWatch(this.watchId);\n delete this.watchId;\n }\n }\n async openSettings() {\n console.log(\"openSettings: Web implementation cannot open native settings\");\n window.alert(\"Please enable location permissions in your browser settings\");\n }\n async playSound(options) {\n if (!options.soundFile) {\n throw new Error(\"Sound file is required\");\n }\n const audio = new Audio(options.soundFile);\n try {\n await audio.play();\n }\n catch (error) {\n throw new Error(`Failed to play sound: ${error.message}`);\n }\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;AACK,UAAC,qBAAqB,GAAGA,mBAAc,CAAC,uBAAuB,EAAE;IACtE,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,wBAAwB,EAAE,CAAC;IAC5E,CAAC;;ICFM,MAAM,wBAAwB,SAASC,cAAS,CAAC;IACxD,IAAI,MAAM,KAAK,CAAC,OAAO,EAAE,QAAQ,EAAE;IACnC,QAAQ,IAAI,CAAC,SAAS,CAAC,WAAW,EAAE;IACpC,YAAY,QAAQ,CAAC,SAAS,EAAE;IAChC,gBAAgB,IAAI,EAAE,kBAAkB;IACxC,gBAAgB,OAAO,EAAE,8CAA8C;IACvE,gBAAgB,IAAI,EAAE,eAAe;IACrC,aAAa,CAAC;IACd,YAAY;IACZ,QAAQ;IACR,QAAQ,IAAI,IAAI,CAAC,OAAO,EAAE;IAC1B,YAAY,QAAQ,CAAC,SAAS,EAAE;IAChC,gBAAgB,IAAI,EAAE,kBAAkB;IACxC,gBAAgB,OAAO,EAAE,6BAA6B;IACtD,gBAAgB,IAAI,EAAE,iBAAiB;IACvC,aAAa,CAAC;IACd,YAAY;IACZ,QAAQ;IACR,QAAQ,IAAI,CAAC,OAAO,GAAG,SAAS,CAAC,WAAW,CAAC,aAAa,CAAC,CAAC,QAAQ,KAAK;IACzE,YAAY,MAAM,QAAQ,GAAG;IAC7B,gBAAgB,QAAQ,EAAE,QAAQ,CAAC,MAAM,CAAC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,8DAA8D,CAAC;IACnF,QAAQ,MAAM,CAAC,KAAK,CAAC,6DAA6D,CAAC;IACnF,IAAI;IACJ,IAAI,MAAM,SAAS,CAAC,OAAO,EAAE;IAC7B,QAAQ,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE;IAChC,YAAY,MAAM,IAAI,KAAK,CAAC,wBAAwB,CAAC;IACrD,QAAQ;IACR,QAAQ,MAAM,KAAK,GAAG,IAAI,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC;IAClD,QAAQ,IAAI;IACZ,YAAY,MAAM,KAAK,CAAC,IAAI,EAAE;IAC9B,QAAQ;IACR,QAAQ,OAAO,KAAK,EAAE;IACtB,YAAY,MAAM,IAAI,KAAK,CAAC,CAAC,sBAAsB,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC;IACrE,QAAQ;IACR,IAAI;IACJ;;;;;;;;;;;;;;;"}
|
package/ios/Plugin/Plugin.m
CHANGED
|
@@ -5,4 +5,5 @@ CAP_PLUGIN(BackgroundGeolocation, "BackgroundGeolocation",
|
|
|
5
5
|
CAP_PLUGIN_METHOD(start, CAPPluginReturnCallback);
|
|
6
6
|
CAP_PLUGIN_METHOD(stop, CAPPluginReturnPromise);
|
|
7
7
|
CAP_PLUGIN_METHOD(openSettings, CAPPluginReturnPromise);
|
|
8
|
+
CAP_PLUGIN_METHOD(playSound, CAPPluginReturnPromise);
|
|
8
9
|
)
|
package/ios/Plugin/Plugin.swift
CHANGED
|
@@ -2,6 +2,7 @@ import Capacitor
|
|
|
2
2
|
import Foundation
|
|
3
3
|
import UIKit
|
|
4
4
|
import CoreLocation
|
|
5
|
+
import AVFoundation
|
|
5
6
|
|
|
6
7
|
// Avoids a bewildering type warning.
|
|
7
8
|
let null = Optional<Double>.none as Any
|
|
@@ -40,6 +41,7 @@ public class BackgroundGeolocation: CAPPlugin, CLLocationManagerDelegate {
|
|
|
40
41
|
private var allowStale: Bool = false
|
|
41
42
|
private var isUpdatingLocation: Bool = false
|
|
42
43
|
private var activeCallbackId: String?
|
|
44
|
+
private var audioPlayer: AVAudioPlayer?
|
|
43
45
|
|
|
44
46
|
@objc override public func load() {
|
|
45
47
|
UIDevice.current.isBatteryMonitoringEnabled = true
|
|
@@ -171,6 +173,30 @@ public class BackgroundGeolocation: CAPPlugin, CLLocationManagerDelegate {
|
|
|
171
173
|
)
|
|
172
174
|
}
|
|
173
175
|
|
|
176
|
+
@objc func playSound(_ call: CAPPluginCall) {
|
|
177
|
+
// Use a background queue for audio loading to avoid blocking the main thread
|
|
178
|
+
DispatchQueue.global(qos: .background).async { [weak self] in
|
|
179
|
+
guard let self = self else { return }
|
|
180
|
+
|
|
181
|
+
let assetPath = "public/" + (call.getString("soundFile") ?? "")
|
|
182
|
+
let assetPathSplit = assetPath.components(separatedBy: ".")
|
|
183
|
+
guard let url = Bundle.main.url(forResource: assetPathSplit[0], withExtension: assetPathSplit[1]) else {
|
|
184
|
+
call.reject("Sound file not found: \(assetPath)")
|
|
185
|
+
return
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
do {
|
|
189
|
+
self.audioPlayer?.stop()
|
|
190
|
+
self.audioPlayer = nil
|
|
191
|
+
self.audioPlayer = try AVAudioPlayer(contentsOf: url)
|
|
192
|
+
self.audioPlayer?.play()
|
|
193
|
+
call.resolve()
|
|
194
|
+
} catch {
|
|
195
|
+
call.reject("Could not play the sound file: \(error.localizedDescription)")
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
174
200
|
public func locationManager(
|
|
175
201
|
_ manager: CLLocationManager,
|
|
176
202
|
didFailWithError error: Error
|
package/package.json
CHANGED