@bglocation/capacitor 1.1.0
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/CapacitorBackgroundLocation.podspec +19 -0
- package/LICENSE.md +97 -0
- package/Package.swift +44 -0
- package/README.md +264 -0
- package/android/build.gradle +74 -0
- package/android/src/main/AndroidManifest.xml +37 -0
- package/android/src/main/kotlin/dev/bglocation/BackgroundLocationPlugin.kt +684 -0
- package/android/src/main/kotlin/dev/bglocation/core/Models.kt +76 -0
- package/android/src/main/kotlin/dev/bglocation/core/battery/BGLBatteryHelper.kt +127 -0
- package/android/src/main/kotlin/dev/bglocation/core/boot/BGLBootCompletedReceiver.kt +32 -0
- package/android/src/main/kotlin/dev/bglocation/core/config/BGLConfigParser.kt +114 -0
- package/android/src/main/kotlin/dev/bglocation/core/config/BGLVersion.kt +6 -0
- package/android/src/main/kotlin/dev/bglocation/core/debug/BGLDebugLogger.kt +174 -0
- package/android/src/main/kotlin/dev/bglocation/core/geofence/BGLGeofenceBroadcastReceiver.kt +93 -0
- package/android/src/main/kotlin/dev/bglocation/core/geofence/BGLGeofenceManager.kt +310 -0
- package/android/src/main/kotlin/dev/bglocation/core/http/BGLHttpSender.kt +187 -0
- package/android/src/main/kotlin/dev/bglocation/core/http/BGLLocationBuffer.kt +152 -0
- package/android/src/main/kotlin/dev/bglocation/core/license/BGLBuildConfig.kt +16 -0
- package/android/src/main/kotlin/dev/bglocation/core/license/BGLLicenseEnforcer.kt +137 -0
- package/android/src/main/kotlin/dev/bglocation/core/license/BGLLicenseValidator.kt +134 -0
- package/android/src/main/kotlin/dev/bglocation/core/license/BGLTrialTimer.kt +176 -0
- package/android/src/main/kotlin/dev/bglocation/core/location/BGLAdaptiveFilter.kt +94 -0
- package/android/src/main/kotlin/dev/bglocation/core/location/BGLHeartbeatTimer.kt +38 -0
- package/android/src/main/kotlin/dev/bglocation/core/location/BGLLocationForegroundService.kt +289 -0
- package/android/src/main/kotlin/dev/bglocation/core/location/BGLLocationHelpers.kt +72 -0
- package/android/src/main/kotlin/dev/bglocation/core/location/BGLPermissionManager.kt +99 -0
- package/android/src/main/kotlin/dev/bglocation/core/notification/BGLNotificationHelper.kt +77 -0
- package/dist/esm/definitions.d.ts +390 -0
- package/dist/esm/definitions.js +3 -0
- package/dist/esm/definitions.js.map +1 -0
- package/dist/esm/index.d.ts +4 -0
- package/dist/esm/index.js +26 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/web.d.ts +47 -0
- package/dist/esm/web.js +231 -0
- package/dist/esm/web.js.map +1 -0
- package/dist/esm/web.test.d.ts +1 -0
- package/dist/esm/web.test.js +940 -0
- package/dist/esm/web.test.js.map +1 -0
- package/dist/plugin.cjs.js +267 -0
- package/dist/plugin.cjs.js.map +1 -0
- package/dist/plugin.js +270 -0
- package/dist/plugin.js.map +1 -0
- package/ios/Sources/BGLocationCore/Config/BGLConfigParser.swift +88 -0
- package/ios/Sources/BGLocationCore/Config/BGLVersion.swift +6 -0
- package/ios/Sources/BGLocationCore/Debug/BGLDebugLogger.swift +201 -0
- package/ios/Sources/BGLocationCore/Geofence/BGLGeofenceManager.swift +538 -0
- package/ios/Sources/BGLocationCore/Http/BGLHttpSender.swift +227 -0
- package/ios/Sources/BGLocationCore/Http/BGLLocationBuffer.swift +198 -0
- package/ios/Sources/BGLocationCore/License/BGLBuildConfig.swift +11 -0
- package/ios/Sources/BGLocationCore/License/BGLLicenseEnforcer.swift +134 -0
- package/ios/Sources/BGLocationCore/License/BGLLicenseValidator.swift +163 -0
- package/ios/Sources/BGLocationCore/License/BGLTrialTimer.swift +168 -0
- package/ios/Sources/BGLocationCore/Location/BGLAdaptiveFilter.swift +91 -0
- package/ios/Sources/BGLocationCore/Location/BGLHeartbeatTimer.swift +50 -0
- package/ios/Sources/BGLocationCore/Location/BGLLocationData.swift +48 -0
- package/ios/Sources/BGLocationCore/Location/BGLLocationHelpers.swift +42 -0
- package/ios/Sources/BGLocationCore/Location/BGLLocationManager.swift +268 -0
- package/ios/Sources/BGLocationCore/Location/BGLPermissionManager.swift +33 -0
- package/ios/Sources/BackgroundLocationPlugin/BackgroundLocationPlugin.swift +657 -0
- package/package.json +75 -0
|
@@ -0,0 +1,390 @@
|
|
|
1
|
+
import type { PermissionState, PluginListenerHandle } from '@capacitor/core';
|
|
2
|
+
export type LocationPermissionType = 'location' | 'backgroundLocation';
|
|
3
|
+
export interface LocationPermissionStatus {
|
|
4
|
+
/** Foreground location permission (ACCESS_FINE_LOCATION / When In Use). */
|
|
5
|
+
location: PermissionState;
|
|
6
|
+
/** Background location permission (ACCESS_BACKGROUND_LOCATION / Always). */
|
|
7
|
+
backgroundLocation: PermissionState;
|
|
8
|
+
}
|
|
9
|
+
export interface LocationPermissionRequest {
|
|
10
|
+
permissions: LocationPermissionType[];
|
|
11
|
+
}
|
|
12
|
+
export interface BackgroundLocationPlugin {
|
|
13
|
+
/**
|
|
14
|
+
* Get plugin and native core version information.
|
|
15
|
+
*/
|
|
16
|
+
getVersion(): Promise<VersionInfo>;
|
|
17
|
+
/**
|
|
18
|
+
* Check the current status of location permissions.
|
|
19
|
+
*/
|
|
20
|
+
checkPermissions(): Promise<LocationPermissionStatus>;
|
|
21
|
+
/**
|
|
22
|
+
* Request location permissions from the user.
|
|
23
|
+
* On Android 10+, background location must be requested separately after foreground is granted.
|
|
24
|
+
* Pass `{ permissions: ['location'] }` first, then `{ permissions: ['backgroundLocation'] }`.
|
|
25
|
+
*/
|
|
26
|
+
requestPermissions(options?: LocationPermissionRequest): Promise<LocationPermissionStatus>;
|
|
27
|
+
/**
|
|
28
|
+
* Configure the background location service.
|
|
29
|
+
* Must be called before start().
|
|
30
|
+
* Returns license validation result.
|
|
31
|
+
*/
|
|
32
|
+
configure(options: LocationConfig): Promise<ConfigureResult>;
|
|
33
|
+
/**
|
|
34
|
+
* Start background location tracking.
|
|
35
|
+
* Requires location permissions to be granted.
|
|
36
|
+
*/
|
|
37
|
+
start(): Promise<LocationState>;
|
|
38
|
+
/**
|
|
39
|
+
* Stop background location tracking.
|
|
40
|
+
*/
|
|
41
|
+
stop(): Promise<LocationState>;
|
|
42
|
+
/**
|
|
43
|
+
* Get the current state of the location service.
|
|
44
|
+
*/
|
|
45
|
+
getState(): Promise<LocationState>;
|
|
46
|
+
/**
|
|
47
|
+
* Request a single location update.
|
|
48
|
+
*/
|
|
49
|
+
getCurrentPosition(options?: PositionOptions): Promise<Location>;
|
|
50
|
+
/**
|
|
51
|
+
* Listen for location updates.
|
|
52
|
+
*/
|
|
53
|
+
addListener(event: 'onLocation', handler: (location: Location) => void): Promise<PluginListenerHandle>;
|
|
54
|
+
/**
|
|
55
|
+
* Listen for heartbeat events (fired at heartbeatInterval when stationary).
|
|
56
|
+
*/
|
|
57
|
+
addListener(event: 'onHeartbeat', handler: (event: HeartbeatEvent) => void): Promise<PluginListenerHandle>;
|
|
58
|
+
/**
|
|
59
|
+
* Listen for location provider changes (GPS on/off).
|
|
60
|
+
*/
|
|
61
|
+
addListener(event: 'onProviderChange', handler: (event: ProviderChangeEvent) => void): Promise<PluginListenerHandle>;
|
|
62
|
+
/**
|
|
63
|
+
* Listen for HTTP responses from native location uploads.
|
|
64
|
+
* Only emitted when `http` is configured in LocationConfig.
|
|
65
|
+
*/
|
|
66
|
+
addListener(event: 'onHttp', handler: (event: HttpEvent) => void): Promise<PluginListenerHandle>;
|
|
67
|
+
/**
|
|
68
|
+
* Listen for debug log messages.
|
|
69
|
+
* Only emitted when `debug: true` is set in LocationConfig.
|
|
70
|
+
*/
|
|
71
|
+
addListener(event: 'onDebug', handler: (event: DebugEvent) => void): Promise<PluginListenerHandle>;
|
|
72
|
+
/**
|
|
73
|
+
* Listen for battery optimization warnings (Android only).
|
|
74
|
+
* Emitted on start() if the device has active battery optimization that may kill tracking.
|
|
75
|
+
* Includes OEM-specific help URL (dontkillmyapp.com).
|
|
76
|
+
* On iOS/Web this event is never emitted.
|
|
77
|
+
*/
|
|
78
|
+
addListener(event: 'onBatteryWarning', handler: (event: BatteryWarningEvent) => void): Promise<PluginListenerHandle>;
|
|
79
|
+
/**
|
|
80
|
+
* Listen for accuracy authorization warnings (iOS only).
|
|
81
|
+
* Emitted on start() if the user has granted only approximate location (iOS 14+).
|
|
82
|
+
* On Android/Web this event is never emitted.
|
|
83
|
+
*/
|
|
84
|
+
addListener(event: 'onAccuracyWarning', handler: (event: AccuracyWarningEvent) => void): Promise<PluginListenerHandle>;
|
|
85
|
+
/**
|
|
86
|
+
* Listen for mock location detection (Android only).
|
|
87
|
+
* Emitted when a location from a mock provider is detected.
|
|
88
|
+
* On iOS/Web this event is never emitted.
|
|
89
|
+
*/
|
|
90
|
+
addListener(event: 'onMockLocation', handler: (event: MockLocationEvent) => void): Promise<PluginListenerHandle>;
|
|
91
|
+
/**
|
|
92
|
+
* Listen for permission rationale events (Android 11+ only).
|
|
93
|
+
* Emitted before requesting background location permission, so the app
|
|
94
|
+
* can display a custom rationale UI explaining why "Allow all the time" is needed.
|
|
95
|
+
* On iOS/Web this event is never emitted.
|
|
96
|
+
*/
|
|
97
|
+
addListener(event: 'onPermissionRationale', handler: (event: PermissionRationaleEvent) => void): Promise<PluginListenerHandle>;
|
|
98
|
+
/**
|
|
99
|
+
* Listen for trial expiration events.
|
|
100
|
+
* Emitted when the 30-minute trial period expires — tracking is auto-stopped.
|
|
101
|
+
* Only emitted in trial mode (no valid license key).
|
|
102
|
+
* On Web this event is never emitted.
|
|
103
|
+
*/
|
|
104
|
+
addListener(event: 'onTrialExpired', handler: (event: TrialExpiredEvent) => void): Promise<PluginListenerHandle>;
|
|
105
|
+
/**
|
|
106
|
+
* Add a geofence region to monitor.
|
|
107
|
+
* Requires `configure()` to be called first — rejects with `'NOT_CONFIGURED'` otherwise.
|
|
108
|
+
* Rejects with `'GEOFENCE_LIMIT_EXCEEDED'` if adding would exceed the 20-geofence limit.
|
|
109
|
+
* If a geofence with the same `identifier` already exists, it is replaced (not an error).
|
|
110
|
+
* On Web: rejects with `'UNSUPPORTED'`.
|
|
111
|
+
*/
|
|
112
|
+
addGeofence(geofence: Geofence): Promise<void>;
|
|
113
|
+
/**
|
|
114
|
+
* Add multiple geofence regions atomically (all-or-nothing).
|
|
115
|
+
* If the total count would exceed 20, the entire batch is rejected.
|
|
116
|
+
* Requires `configure()` to be called first.
|
|
117
|
+
* On Web: rejects with `'UNSUPPORTED'`.
|
|
118
|
+
*/
|
|
119
|
+
addGeofences(options: {
|
|
120
|
+
geofences: Geofence[];
|
|
121
|
+
}): Promise<void>;
|
|
122
|
+
/**
|
|
123
|
+
* Remove a geofence region by its identifier.
|
|
124
|
+
* No-op if the identifier does not match any registered geofence.
|
|
125
|
+
* On Web: rejects with `'UNSUPPORTED'`.
|
|
126
|
+
*/
|
|
127
|
+
removeGeofence(options: {
|
|
128
|
+
identifier: string;
|
|
129
|
+
}): Promise<void>;
|
|
130
|
+
/**
|
|
131
|
+
* Remove all registered geofence regions.
|
|
132
|
+
* On Web: rejects with `'UNSUPPORTED'`.
|
|
133
|
+
*/
|
|
134
|
+
removeAllGeofences(): Promise<void>;
|
|
135
|
+
/**
|
|
136
|
+
* Get the list of currently registered geofences.
|
|
137
|
+
* Returns data from the persistence layer (source of truth).
|
|
138
|
+
* On Web: rejects with `'UNSUPPORTED'`.
|
|
139
|
+
*/
|
|
140
|
+
getGeofences(): Promise<{
|
|
141
|
+
geofences: Geofence[];
|
|
142
|
+
}>;
|
|
143
|
+
/**
|
|
144
|
+
* Listen for geofence transition events (enter, exit, dwell).
|
|
145
|
+
* Emitted on both iOS and Android, even when the app is in background or terminated.
|
|
146
|
+
* On Web this event is never emitted.
|
|
147
|
+
*/
|
|
148
|
+
addListener(event: 'onGeofence', handler: (event: GeofenceEvent) => void): Promise<PluginListenerHandle>;
|
|
149
|
+
/**
|
|
150
|
+
* Check if battery optimization is affecting this app (Android only).
|
|
151
|
+
* Returns the current battery optimization state and OEM-specific info.
|
|
152
|
+
* On iOS/Web, returns `{ isIgnoringOptimizations: true }` (no-op).
|
|
153
|
+
*/
|
|
154
|
+
checkBatteryOptimization(): Promise<BatteryWarningEvent>;
|
|
155
|
+
/**
|
|
156
|
+
* Open the system battery optimization settings for this app (Android only).
|
|
157
|
+
* On Android: opens ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS intent.
|
|
158
|
+
* On iOS/Web: no-op, resolves immediately.
|
|
159
|
+
*
|
|
160
|
+
* NOTE: The returned `BatteryWarningEvent` reflects the state **before** the user
|
|
161
|
+
* interacts with the system dialog. Call `checkBatteryOptimization()` after the app
|
|
162
|
+
* resumes to get the updated state.
|
|
163
|
+
*/
|
|
164
|
+
requestBatteryOptimization(): Promise<BatteryWarningEvent>;
|
|
165
|
+
/**
|
|
166
|
+
* Remove all registered listeners.
|
|
167
|
+
*/
|
|
168
|
+
removeAllListeners(): Promise<void>;
|
|
169
|
+
}
|
|
170
|
+
export interface HttpConfig {
|
|
171
|
+
/** The URL to POST location data to. */
|
|
172
|
+
url: string;
|
|
173
|
+
/** Optional HTTP headers (e.g. Authorization). */
|
|
174
|
+
headers?: Record<string, string>;
|
|
175
|
+
/**
|
|
176
|
+
* Offline buffer configuration. When enabled, failed HTTP requests are
|
|
177
|
+
* stored in a local SQLite database and retried automatically.
|
|
178
|
+
*/
|
|
179
|
+
buffer?: LocationBufferConfig;
|
|
180
|
+
}
|
|
181
|
+
export interface LocationBufferConfig {
|
|
182
|
+
/** Maximum number of locations to store in the offline buffer. Oldest entries are dropped when exceeded. @default 1000 */
|
|
183
|
+
maxSize?: number;
|
|
184
|
+
}
|
|
185
|
+
export interface NotificationConfig {
|
|
186
|
+
/** Title of the Android foreground service notification. @default 'Background Location' */
|
|
187
|
+
title?: string;
|
|
188
|
+
/** Text body of the Android foreground service notification. @default 'Tracking your location' */
|
|
189
|
+
text?: string;
|
|
190
|
+
}
|
|
191
|
+
export interface AutoDistanceFilterConfig {
|
|
192
|
+
/** Target interval between location updates in seconds. @default 10 */
|
|
193
|
+
targetInterval?: number;
|
|
194
|
+
/** Minimum distance filter in meters (prevents excessive updates at low speed). @default 10 */
|
|
195
|
+
minDistance?: number;
|
|
196
|
+
/** Maximum distance filter in meters (ensures updates even at high speed). @default 500 */
|
|
197
|
+
maxDistance?: number;
|
|
198
|
+
}
|
|
199
|
+
export interface LocationConfig {
|
|
200
|
+
/** Distance filter in meters, or 'auto' for speed-adaptive mode. @default 15 */
|
|
201
|
+
distanceFilter?: number | 'auto';
|
|
202
|
+
/** Configuration for auto distance filter mode. Only used when distanceFilter is 'auto'. */
|
|
203
|
+
autoDistanceFilter?: AutoDistanceFilterConfig;
|
|
204
|
+
/** Location update interval in **milliseconds** (Android only). @default 5000 */
|
|
205
|
+
locationUpdateInterval?: number;
|
|
206
|
+
/** Fastest location update interval in **milliseconds** (Android only). @default 2000 */
|
|
207
|
+
fastestLocationUpdateInterval?: number;
|
|
208
|
+
/** Heartbeat interval in **seconds** when stationary. Applied identically on all platforms. @default 15 */
|
|
209
|
+
heartbeatInterval?: number;
|
|
210
|
+
/** Desired accuracy level. @default 'high' */
|
|
211
|
+
desiredAccuracy?: 'high' | 'balanced' | 'low';
|
|
212
|
+
/** Optional HTTP config. When provided, location updates are POSTed natively to the given URL. */
|
|
213
|
+
http?: HttpConfig;
|
|
214
|
+
/**
|
|
215
|
+
* Android foreground service notification configuration.
|
|
216
|
+
* Allows customizing the persistent notification title and text (i18n ready).
|
|
217
|
+
* Has no effect on iOS (uses blue pill indicator) or Web.
|
|
218
|
+
*/
|
|
219
|
+
notification?: NotificationConfig;
|
|
220
|
+
/**
|
|
221
|
+
* Enable debug mode. When true:
|
|
222
|
+
* - Verbose native logging (os_log on iOS, Logcat on Android)
|
|
223
|
+
* - `onDebug` events emitted to JS with timestamped messages
|
|
224
|
+
* - Android: notification updated dynamically with coordinates, counters, status
|
|
225
|
+
* - Optional system sounds on key events (location fix, heartbeat, HTTP)
|
|
226
|
+
* @default false
|
|
227
|
+
*/
|
|
228
|
+
debug?: boolean;
|
|
229
|
+
/**
|
|
230
|
+
* Play system sounds on key events in debug mode.
|
|
231
|
+
* Only applies when `debug: true`.
|
|
232
|
+
* @default false
|
|
233
|
+
*/
|
|
234
|
+
debugSounds?: boolean;
|
|
235
|
+
}
|
|
236
|
+
export interface Location {
|
|
237
|
+
latitude: number;
|
|
238
|
+
longitude: number;
|
|
239
|
+
accuracy: number;
|
|
240
|
+
speed: number;
|
|
241
|
+
heading: number;
|
|
242
|
+
altitude: number;
|
|
243
|
+
timestamp: number;
|
|
244
|
+
isMoving: boolean;
|
|
245
|
+
/** Whether this location was generated by a mock provider (Android only). Always `false` on iOS/Web. */
|
|
246
|
+
isMock: boolean;
|
|
247
|
+
/** Current effective distance filter in meters. Only present when distanceFilter is 'auto'. */
|
|
248
|
+
effectiveDistanceFilter?: number;
|
|
249
|
+
}
|
|
250
|
+
export interface LocationState {
|
|
251
|
+
/** Whether location permission is granted (iOS: authorization status, Android: runtime permission). */
|
|
252
|
+
enabled: boolean;
|
|
253
|
+
/** Whether the plugin is actively tracking location. */
|
|
254
|
+
tracking: boolean;
|
|
255
|
+
}
|
|
256
|
+
export interface HeartbeatEvent {
|
|
257
|
+
/** Location at the time of heartbeat. `null` if no location has been acquired yet (cold start). */
|
|
258
|
+
location: Location | null;
|
|
259
|
+
/** Epoch milliseconds when this heartbeat fired (independent of location timestamp). */
|
|
260
|
+
timestamp: number;
|
|
261
|
+
}
|
|
262
|
+
export interface ProviderChangeEvent {
|
|
263
|
+
gps: boolean;
|
|
264
|
+
network: boolean;
|
|
265
|
+
enabled: boolean;
|
|
266
|
+
status: number;
|
|
267
|
+
}
|
|
268
|
+
export interface HttpEvent {
|
|
269
|
+
/** HTTP status code (0 if network error). */
|
|
270
|
+
statusCode: number;
|
|
271
|
+
/** Whether the request succeeded (2xx). */
|
|
272
|
+
success: boolean;
|
|
273
|
+
/** Response body text. */
|
|
274
|
+
responseText: string;
|
|
275
|
+
/** Error message if the request failed due to a network error. */
|
|
276
|
+
error?: string;
|
|
277
|
+
/** Number of locations currently waiting in the offline buffer. 0 when buffer is disabled or empty. */
|
|
278
|
+
bufferedCount?: number;
|
|
279
|
+
}
|
|
280
|
+
export interface DebugEvent {
|
|
281
|
+
/** Debug log message. */
|
|
282
|
+
message: string;
|
|
283
|
+
/** Epoch milliseconds when this debug event was generated. */
|
|
284
|
+
timestamp: number;
|
|
285
|
+
}
|
|
286
|
+
export interface PositionOptions {
|
|
287
|
+
timeout?: number;
|
|
288
|
+
}
|
|
289
|
+
export interface BatteryWarningEvent {
|
|
290
|
+
/** Whether the app is exempt from battery optimization (true = safe, false = at risk). */
|
|
291
|
+
isIgnoringOptimizations: boolean;
|
|
292
|
+
/** Device manufacturer in lowercase (e.g., 'xiaomi', 'huawei', 'samsung'). Empty on iOS/Web. */
|
|
293
|
+
manufacturer: string;
|
|
294
|
+
/** URL to dontkillmyapp.com with OEM-specific instructions. Empty when not applicable. */
|
|
295
|
+
helpUrl: string;
|
|
296
|
+
/** Human-readable warning message. */
|
|
297
|
+
message: string;
|
|
298
|
+
}
|
|
299
|
+
export interface AccuracyWarningEvent {
|
|
300
|
+
/** Current accuracy authorization: 'full' (precise GPS) or 'approximate' (degraded). */
|
|
301
|
+
accuracyAuthorization: 'full' | 'approximate';
|
|
302
|
+
/** Human-readable warning message. */
|
|
303
|
+
message: string;
|
|
304
|
+
}
|
|
305
|
+
export interface MockLocationEvent {
|
|
306
|
+
/** The mock location that was detected. */
|
|
307
|
+
location: Location;
|
|
308
|
+
/** Human-readable warning message. */
|
|
309
|
+
message: string;
|
|
310
|
+
}
|
|
311
|
+
export interface PermissionRationaleEvent {
|
|
312
|
+
/** The permission that requires rationale before requesting. */
|
|
313
|
+
permission: 'backgroundLocation';
|
|
314
|
+
/** Whether the system suggests showing a rationale (Android `shouldShowRequestPermissionRationale`). */
|
|
315
|
+
shouldShowRationale: boolean;
|
|
316
|
+
/** Human-readable message explaining why the permission is needed. */
|
|
317
|
+
message: string;
|
|
318
|
+
}
|
|
319
|
+
/** License validation result returned by configure(). */
|
|
320
|
+
export interface ConfigureResult {
|
|
321
|
+
/** Current license mode: 'full' (no restrictions) or 'trial' (debug=true, 30 min limit, 1h cooldown). */
|
|
322
|
+
licenseMode: 'full' | 'trial';
|
|
323
|
+
/** The distance filter mode in effect: 'fixed' or 'auto'. */
|
|
324
|
+
distanceFilterMode: 'fixed' | 'auto';
|
|
325
|
+
/** ISO 8601 date until which plugin updates are available. Only present when licenseMode is 'full' and exp is set in key. */
|
|
326
|
+
licenseUpdatesUntil?: string;
|
|
327
|
+
/** Whether the license key's update period has expired for this plugin version. When true, the plugin degrades to trial mode. Renew at bglocation.dev/portal. */
|
|
328
|
+
licenseUpdateExpired?: boolean;
|
|
329
|
+
/** Reason the license key was rejected. Only present when licenseMode is 'trial'. */
|
|
330
|
+
licenseError?: string;
|
|
331
|
+
}
|
|
332
|
+
/** Emitted when the trial period expires (30 min). */
|
|
333
|
+
export interface TrialExpiredEvent {
|
|
334
|
+
/** Duration in seconds that tracking was active before expiry. */
|
|
335
|
+
elapsed: number;
|
|
336
|
+
/** Cooldown duration in seconds before next start() is allowed. */
|
|
337
|
+
cooldownSeconds: number;
|
|
338
|
+
/** Human-readable message. */
|
|
339
|
+
message: string;
|
|
340
|
+
}
|
|
341
|
+
/** Error returned when start() is called during trial cooldown. */
|
|
342
|
+
export interface TrialCooldownError {
|
|
343
|
+
/** Remaining cooldown time in seconds. */
|
|
344
|
+
remainingSeconds: number;
|
|
345
|
+
/** Human-readable message. */
|
|
346
|
+
message: string;
|
|
347
|
+
}
|
|
348
|
+
/** Plugin and native core version information. */
|
|
349
|
+
export interface VersionInfo {
|
|
350
|
+
/** Plugin version (from package.json). */
|
|
351
|
+
pluginVersion: string;
|
|
352
|
+
/** Native core library version. */
|
|
353
|
+
coreVersion: string;
|
|
354
|
+
}
|
|
355
|
+
/** Maximum number of geofences that can be registered simultaneously (iOS CLLocationManager limit). */
|
|
356
|
+
export declare const GEOFENCE_MAX_COUNT = 20;
|
|
357
|
+
/** Configuration for a single geofence region. */
|
|
358
|
+
export interface Geofence {
|
|
359
|
+
/** Unique identifier for this geofence. Used to remove or replace it. */
|
|
360
|
+
identifier: string;
|
|
361
|
+
/** Center latitude in degrees. */
|
|
362
|
+
latitude: number;
|
|
363
|
+
/** Center longitude in degrees. */
|
|
364
|
+
longitude: number;
|
|
365
|
+
/** Radius in meters. Recommended minimum: 100m for reliable detection. */
|
|
366
|
+
radius: number;
|
|
367
|
+
/** Fire event when entering the region. @default true */
|
|
368
|
+
notifyOnEntry?: boolean;
|
|
369
|
+
/** Fire event when exiting the region. @default true */
|
|
370
|
+
notifyOnExit?: boolean;
|
|
371
|
+
/** Fire event after dwelling in the region for `dwellDelay` seconds. **iOS: not supported natively by Core Location — this flag is accepted but ignored.** @default false */
|
|
372
|
+
notifyOnDwell?: boolean;
|
|
373
|
+
/** Seconds to wait inside region before firing a dwell event. Only effective on Android. @default 300 */
|
|
374
|
+
dwellDelay?: number;
|
|
375
|
+
/** Optional payload data attached to geofence events. Values must be strings (stringify numbers/booleans). */
|
|
376
|
+
extras?: Record<string, string>;
|
|
377
|
+
}
|
|
378
|
+
/** Event emitted when a geofence transition occurs. */
|
|
379
|
+
export interface GeofenceEvent {
|
|
380
|
+
/** Identifier of the geofence that triggered. */
|
|
381
|
+
identifier: string;
|
|
382
|
+
/** Type of transition. */
|
|
383
|
+
action: 'enter' | 'exit' | 'dwell';
|
|
384
|
+
/** Location at the time of the transition. `null` if unavailable. */
|
|
385
|
+
location: Location | null;
|
|
386
|
+
/** Optional extras attached when the geofence was created. */
|
|
387
|
+
extras?: Record<string, string>;
|
|
388
|
+
/** Epoch milliseconds when the transition was detected. */
|
|
389
|
+
timestamp: number;
|
|
390
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"AAwbA,uGAAuG;AACvG,MAAM,CAAC,MAAM,kBAAkB,GAAG,EAAE,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { registerPlugin } from '@capacitor/core';
|
|
2
|
+
const RawPlugin = registerPlugin('BackgroundLocation', {
|
|
3
|
+
web: () => import('./web').then((m) => new m.BackgroundLocationWeb()),
|
|
4
|
+
});
|
|
5
|
+
/**
|
|
6
|
+
* Thin wrapper that merges partial `configure()` calls with the last-applied
|
|
7
|
+
* config so callers don't lose previously set fields (e.g. http endpoint)
|
|
8
|
+
* when reconfiguring a single field (e.g. distanceFilter).
|
|
9
|
+
*/
|
|
10
|
+
let lastConfig;
|
|
11
|
+
const BackgroundLocation = new Proxy(RawPlugin, {
|
|
12
|
+
get(target, prop, receiver) {
|
|
13
|
+
if (prop === 'configure') {
|
|
14
|
+
return async (options) => {
|
|
15
|
+
const merged = lastConfig ? { ...lastConfig, ...options } : options;
|
|
16
|
+
const result = await target.configure(merged);
|
|
17
|
+
lastConfig = merged;
|
|
18
|
+
return result;
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
return Reflect.get(target, prop, receiver);
|
|
22
|
+
},
|
|
23
|
+
});
|
|
24
|
+
export * from './definitions';
|
|
25
|
+
export { BackgroundLocation };
|
|
26
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAIjD,MAAM,SAAS,GAAG,cAAc,CAC9B,oBAAoB,EACpB;IACE,GAAG,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC,qBAAqB,EAAE,CAAC;CACtE,CACF,CAAC;AAEF;;;;GAIG;AACH,IAAI,UAAsC,CAAC;AAE3C,MAAM,kBAAkB,GAA6B,IAAI,KAAK,CAAC,SAAS,EAAE;IACxE,GAAG,CAAC,MAAM,EAAE,IAAI,EAAE,QAAQ;QACxB,IAAI,IAAI,KAAK,WAAW,EAAE,CAAC;YACzB,OAAO,KAAK,EAAE,OAAuB,EAA4B,EAAE;gBACjE,MAAM,MAAM,GAAG,UAAU,CAAC,CAAC,CAAC,EAAE,GAAG,UAAU,EAAE,GAAG,OAAO,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC;gBACpE,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;gBAC9C,UAAU,GAAG,MAAM,CAAC;gBACpB,OAAO,MAAM,CAAC;YAChB,CAAC,CAAC;QACJ,CAAC;QACD,OAAO,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,IAAI,EAAE,QAAQ,CAAC,CAAC;IAC7C,CAAC;CACF,CAAC,CAAC;AAEH,cAAc,eAAe,CAAC;AAC9B,OAAO,EAAE,kBAAkB,EAAE,CAAC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { WebPlugin } from '@capacitor/core';
|
|
2
|
+
import type { BackgroundLocationPlugin, BatteryWarningEvent, ConfigureResult, Geofence, Location, LocationConfig, LocationPermissionStatus, LocationState, PositionOptions, VersionInfo } from './definitions';
|
|
3
|
+
/**
|
|
4
|
+
* Web fallback using navigator.geolocation.
|
|
5
|
+
* Used for development/testing in the browser only.
|
|
6
|
+
*/
|
|
7
|
+
export declare class BackgroundLocationWeb extends WebPlugin implements BackgroundLocationPlugin {
|
|
8
|
+
private watchId;
|
|
9
|
+
private heartbeatTimer;
|
|
10
|
+
private config;
|
|
11
|
+
private httpConfig;
|
|
12
|
+
private isTracking;
|
|
13
|
+
private debug;
|
|
14
|
+
private locationCount;
|
|
15
|
+
private heartbeatCount;
|
|
16
|
+
private httpSuccessCount;
|
|
17
|
+
private httpErrorCount;
|
|
18
|
+
private geofenceStore;
|
|
19
|
+
getVersion(): Promise<VersionInfo>;
|
|
20
|
+
checkPermissions(): Promise<LocationPermissionStatus>;
|
|
21
|
+
requestPermissions(): Promise<LocationPermissionStatus>;
|
|
22
|
+
configure(options: LocationConfig): Promise<ConfigureResult>;
|
|
23
|
+
start(): Promise<LocationState>;
|
|
24
|
+
stop(): Promise<LocationState>;
|
|
25
|
+
getState(): Promise<LocationState>;
|
|
26
|
+
removeAllListeners(): Promise<void>;
|
|
27
|
+
getCurrentPosition(options?: PositionOptions): Promise<Location>;
|
|
28
|
+
checkBatteryOptimization(): Promise<BatteryWarningEvent>;
|
|
29
|
+
requestBatteryOptimization(): Promise<BatteryWarningEvent>;
|
|
30
|
+
addGeofence(geofence: Geofence): Promise<void>;
|
|
31
|
+
addGeofences(options: {
|
|
32
|
+
geofences: Geofence[];
|
|
33
|
+
}): Promise<void>;
|
|
34
|
+
removeGeofence(options: {
|
|
35
|
+
identifier: string;
|
|
36
|
+
}): Promise<void>;
|
|
37
|
+
removeAllGeofences(): Promise<void>;
|
|
38
|
+
getGeofences(): Promise<{
|
|
39
|
+
geofences: Geofence[];
|
|
40
|
+
}>;
|
|
41
|
+
private startHeartbeat;
|
|
42
|
+
private stopHeartbeat;
|
|
43
|
+
private geolocationToLocation;
|
|
44
|
+
private sendHttp;
|
|
45
|
+
private emitDebug;
|
|
46
|
+
private resetCounters;
|
|
47
|
+
}
|