forked from anibalsolon/react-native-background-geolocation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.d.ts
893 lines (789 loc) · 20.3 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
// Type definitions for react-native-mauron85-background-geolocation
// Project: https://github.com/mauron85/react-native-background-geolocation
// Definitions by: Mauron85 (@mauron85), Norbert Györög (@djereg)
// Definitions: https://github.com/mauron85/react-native-background-geolocation/blob/master/index.d.ts
type Event = 'location' | 'stationary' | 'activity' | 'start' | 'stop' | 'error' | 'authorization' | 'foreground' | 'background' | 'abort_requested' | 'http_authorization';
type HeadlessTaskEventName = 'location' | 'stationary' | 'activity';
type iOSActivityType = 'AutomotiveNavigation' | 'OtherNavigation' | 'Fitness' | 'Other';
type NativeProvider = 'gps' | 'network' | 'passive' | 'fused';
type ActivityType = 'IN_VEHICLE' | 'ON_BICYCLE' | 'ON_FOOT' | 'RUNNING' | 'STILL' | 'TILTING' | 'UNKNOWN' | 'WALKING';
type LogLevel = 'TRACE' | 'DEBUG' | 'INFO' | 'WARN' | 'ERROR';
type LocationProvider = 0 | 1 | 2;
type AuthorizationStatus = 0 | 1 | 2;
type AccuracyLevel = 0 | 100 | 1000 | 10000 | number;
type LocationErrorCode = 1 | 2 | 3;
type ServiceMode = 0 | 1;
export interface ConfigureOptions {
/**
* Set location provider
*
* Platform: all
* Available providers:
* DISTANCE_FILTER_PROVIDER,
* ACTIVITY_PROVIDER
* RAW_PROVIDER
*
* @default DISTANCE_FILTER_PROVIDER
* @example
* { locationProvider: BackgroundGeolocation.RAW_PROVIDER }
*/
locationProvider?: LocationProvider;
/**
* Desired accuracy in meters.
*
* Platform: all
* Provider: all
* Possible values:
* HIGH_ACCURACY,
* MEDIUM_ACCURACY,
* LOW_ACCURACY,
* PASSIVE_ACCURACY
* Note: Accuracy has direct effect on power drain. Lower accuracy = lower power drain.
*
* @default MEDIUM_ACCURACY
* @example
* { desiredAccuracy: BackgroundGeolocation.LOW_ACCURACY }
*/
desiredAccuracy?: AccuracyLevel;
/**
* Stationary radius in meters.
*
* When stopped, the minimum distance the device must move beyond the stationary location for aggressive background-tracking to engage.
* Platform: all
* Provider: DISTANCE_FILTER
*
* @default 50
*/
stationaryRadius?: number;
/**
* When enabled, the plugin will emit sounds for life-cycle events of background-geolocation! See debugging sounds table.
*
* Platform: all
* Provider: all
*
* @default false
*/
debug?: boolean;
/**
* The minimum distance (measured in meters) a device must move horizontally before an update event is generated.
*
* Platform: all
* Provider: DISTANCE_FILTER, RAW
*
* @default 500
* @see {@link https://apple.co/2oHo2CV|Apple docs}
*/
distanceFilter?: number;
/**
* Enable this in order to force a stop() when the application terminated.
* E.g. on iOS, double-tap home button, swipe away the app.
*
* Platform: all
* Provider: all
*
* @default true
*/
stopOnTerminate?: boolean;
/**
* Start background service on device boot.
*
* Platform: Android
* Provider: all
*
* @default false
*/
startOnBoot?: boolean;
/**
* The minimum time interval between location updates in milliseconds.
*
* Platform: Android
* Provider: all
*
* @default 60000
* @see {@link https://bit.ly/1x00RUu|Android docs}
*/
interval?: number;
/**
* Fastest rate in milliseconds at which your app can handle location updates.
*
* Platform: Android
* Provider: ACTIVITY
*
* @default 120000
* @see {@link https://bit.ly/1x00RUu|Android docs}
*/
fastestInterval?: number;
/**
* Rate in milliseconds at which activity recognition occurs.
* Larger values will result in fewer activity detections while improving battery life.
*
* Platform: Android
* Provider: ACTIVITY
*
* @default 10000
*/
activitiesInterval?: number;
/**
* @deprecated Stop location updates, when the STILL activity is detected.
*/
stopOnStillActivity?: boolean;
/**
* Enable/disable local notifications when tracking and syncing locations.
*
* Platform: Android
* Provider: all
*
* @default true
*/
notificationsEnabled?: boolean;
/**
* Allow location sync service to run in foreground state.
* Foreground state also requires a notification to be presented to the user.
*
* Platform: Android
* Provider: all
*
* @default false
*/
startForeground?: boolean;
/**
* Custom notification title in the drawer.
*
* Platform: Android
* Provider: all
* @default "Background tracking"
*/
notificationTitle?: string;
/**
* Custom notification text in the drawer.
*
* Platform: Android
* Provider: all
*
* @default "ENABLED"
*/
notificationText?: string;
/**
* The accent color (hex triplet) to use for notification.
* Eg. <code>#4CAF50</code>.
*
* Platform: Android
* Provider: all
*/
notificationIconColor?: string;
/**
* The filename of a custom notification icon.
*
* Platform: Android
* Provider: all
*/
notificationIconLarge?: string;
/**
* The filename of a custom notification icon.
*
* Platform: Android
* Provider: all
*/
notificationIconSmall?: string;
/**
* Activity type.
* Presumably, this affects iOS GPS algorithm.
*
* Possible values:
* "AutomotiveNavigation", "OtherNavigation", "Fitness", "Other"
*
* Platform: iOS
* Provider: all
*
* @default "OtherNavigation"
* @see {@link https://apple.co/2oHofpH|Apple docs}
*/
activityType?: iOSActivityType;
/**
* Pauses location updates when app is paused.
*
* Platform: iOS
* Provider: all
*
* @default false
* @see {@link https://apple.co/2CbjEW2|Apple docs}
*/
pauseLocationUpdates?: boolean;
/**
* Switch to less accurate significant changes and region monitory when in background.
*
* Platform: iOS
* Provider: all
*
* @default false
*/
saveBatteryOnBackground?: boolean;
/**
* Server url where to send HTTP POST with recorded locations
*
* Platform: all
* Provider: all
*/
url?: string;
/**
* Server url where to send fail to post locations
*
* Platform: all
* Provider: all
*/
syncUrl?: string;
/**
* Specifies how many previously failed locations will be sent to server at once.
*
* Platform: all
* Provider: all
*
* @default 100
*/
syncThreshold?: string;
/**
* Optional HTTP headers sent along in HTTP request.
*
* Platform: all
* Provider: all
*/
httpHeaders?: any;
/**
* Limit maximum number of locations stored into db.
*
* Platform: all
* Provider: all
*
* @default 10000
*/
maxLocations?: number;
/**
* Customization post template.
*
* Platform: all
* Provider: all
*/
postTemplate?: any;
}
export interface LocationOptions {
/**
* Maximum time in milliseconds device will wait for location.
*/
timeout?: number;
/**
* Maximum age in milliseconds of a possible cached location that is acceptable to return.
*/
maximumAge?: number;
/**
* If true and if the device is able to provide a more accurate position, it will do so.
*/
enableHighAccuracy?: boolean;
}
export interface Location {
/** ID of location as stored in DB (or null) */
id: number;
/**
* Native provider reponsible for location.
*
* Possible values:
* "gps", "network", "passive" or "fused"
*/
provider: NativeProvider;
/** Configured location provider. */
locationProvider: number;
/** UTC time of this fix, in milliseconds since January 1, 1970. */
time: number;
/** Latitude, in degrees. */
latitude: number;
/** Longitude, in degrees. */
longitude: number;
/** Estimated accuracy of this location, in meters. */
accuracy: number;
/**
* Speed if it is available, in meters/second over ground.
*
* Note: Not all providers are capable of providing speed.
* Typically network providers are not able to do so.
*/
speed: number;
/** Altitude if available, in meters above the WGS 84 reference ellipsoid. */
altitude: number;
/** Bearing, in degrees. */
bearing: number;
/**
* True if location was recorded by mock provider. (ANDROID ONLY)
*
* Note: this property is not enabled by default!
* You can enable it "postTemplate" configure option.
*/
isFromMockProvider?: boolean;
/**
* True if device has mock locations enabled. (ANDROID ONLY)
*
* Note: this property is not enabled by default!
* You can enable it "postTemplate" configure option.
*/
mockLocationsEnabled?: boolean;
}
export interface StationaryLocation extends Location {
radius: number
}
export interface LocationError {
/**
* Reason of an error occurring when using the geolocating device.
*
* Possible error codes:
* 1. PERMISSION_DENIED
* 2. LOCATION_UNAVAILABLE
* 3. TIMEOUT
*/
code: LocationErrorCode;
/** Message describing the details of the error */
message: string;
}
export interface BackgroundGeolocationError {
code: number;
message: string;
}
export interface Activity {
/** Percentage indicating the likelihood user is performing this activity. */
confidence: number;
/**
* Type of the activity.
*
* Possible values:
* IN_VEHICLE, ON_BICYCLE, ON_FOOT, RUNNING, STILL, TILTING, UNKNOWN, WALKING
*/
type: ActivityType;
}
export interface ServiceStatus {
/** TRUE if service is running. */
isRunning: boolean;
/** TRUE if location services are enabled */
locationServicesEnabled: boolean;
/**
* Authorization status.
*
* Posible values:
* NOT_AUTHORIZED, AUTHORIZED, AUTHORIZED_FOREGROUND
*
* @example
* if (authorization == BackgroundGeolocation.NOT_AUTHORIZED) {...}
*/
authorization: AuthorizationStatus;
}
export interface LogEntry {
/** ID of log entry as stored in db. */
id: number;
/** Timestamp in milliseconds since beginning of UNIX epoch. */
timestamp: number;
/** Log level */
level: LogLevel;
/** Log message */
message: string;
/** Recorded stacktrace. (Android only, on iOS part of message) */
stackTrace: string;
}
export interface EventSubscription {
remove(): void;
}
export interface HeadlessTaskEvent {
/** Name of the event [ "location", "stationary", "activity" ] */
name: HeadlessTaskEventName;
/** Event parameters. */
params: any;
}
export interface BackgroundGeolocationPlugin {
DISTANCE_FILTER_PROVIDER: LocationProvider;
ACTIVITY_PROVIDER: LocationProvider;
RAW_PROVIDER: LocationProvider;
BACKGROUND_MODE: ServiceMode;
FOREGROUND_MODE: ServiceMode;
NOT_AUTHORIZED: AuthorizationStatus;
AUTHORIZED: AuthorizationStatus;
AUTHORIZED_FOREGROUND: AuthorizationStatus;
HIGH_ACCURACY: AccuracyLevel;
MEDIUM_ACCURACY: AccuracyLevel;
LOW_ACCURACY: AccuracyLevel;
PASSIVE_ACCURACY: AccuracyLevel;
LOG_ERROR: LogLevel;
LOG_WARN: LogLevel;
LOG_INFO: LogLevel;
LOG_DEBUG: LogLevel;
LOG_TRACE: LogLevel;
PERMISSION_DENIED: LocationErrorCode;
LOCATION_UNAVAILABLE: LocationErrorCode;
TIMEOUT: LocationErrorCode;
events: Event[];
/**
* Configure plugin.
* Platform: iOS, Android
*
* @param options
* @param success
* @param fail
*/
configure(
options: ConfigureOptions,
success?: () => void,
fail?: () => void
): void;
/**
* Start background geolocation.
* Platform: iOS, Android
*/
start(): void;
/**
* Stop background geolocation.
* Platform: iOS, Android
*/
stop(): void;
/**
* One time location check to get current location of the device.
*
* Platform: all
*
* @param success
* @param fail
* @param options
*/
getCurrentLocation(
success: (location: Location) => void,
fail?: (error: LocationError) => void | null,
options?: LocationOptions
): void;
/**
* Returns current stationaryLocation if available. Null if not
*
* Platform: all
*
* @param success
* @param fail
*/
getStationaryLocation(
success: (location: StationaryLocation | null) => void,
fail?: (error: BackgroundGeolocationError) => void,
): void;
/**
* Check status of the service
*
* @param success
* @param fail
*/
checkStatus(
success: (status: ServiceStatus) => void,
fail?: (error: BackgroundGeolocationError) => void
): void;
/**
* Show app settings to allow change of app location permissions.
*
* Platform: Android >= 6, iOS >= 8.0
*/
showAppSettings(): void;
/**
* Show system settings to allow configuration of current location sources.
*
* Platform: Android
*/
showLocationSettings(): void;
/**
* Return all stored locations.
* Useful for initial rendering of user location on a map just after application launch.
*
* Platform: iOS, Android
*
* @param success
* @param fail
* @see {@link https://github.com/mauron85/react-native-background-geolocation#getlocationssuccess-fail|Docs}
*/
getLocations(
success: (locations: Location[]) => void,
fail?: (error: BackgroundGeolocationError) => void
): void;
/**
* Method will return locations which have not yet been posted to server.
* Platform: iOS, Android
* @param success
* @param fail
* @see {@link https://github.com/mauron85/react-native-background-geolocation#getvalidlocationssuccess-fail|Docs}
*/
getValidLocations(
success: (location: Location[]) => void,
fail?: (error: BackgroundGeolocationError) => void
): void;
/**
* Delete location by locationId.
*
* Platform: iOS, Android
*
* @param locationId
* @param success
* @param fail
*/
deleteLocation(
locationId: number,
success?: () => void,
fail?: (error: BackgroundGeolocationError) => void
): void;
/**
* Delete all stored locations.
*
* Platform: iOS, Android
*
* Note: You don't need to delete all locations.
* The plugin manages the number of stored locations automatically and the total count never exceeds the number as defined by <code>option.maxLocations</code>.
*
* @param success
* @param fail
*/
deleteAllLocations(
success?: () => void,
fail?: (error: BackgroundGeolocationError) => void
): void;
/**
* Switch plugin operation mode,
*
* Platform: iOS
*
* Normally the plugin will handle switching between <b>BACKGROUND</b> and <b>FOREGROUND</b> mode itself.
* Calling <code>switchMode</code> you can override plugin behavior and force it to switch into other mode.
*
* @example
* // switch to FOREGROUND mode
* BackgroundGeolocation.switchMode(BackgroundGeolocation.FOREGROUND_MODE);
*
* // switch to BACKGROUND mode
* BackgroundGeolocation.switchMode(BackgroundGeolocation.BACKGROUND_MODE);
*/
switchMode(
modeId: ServiceMode,
success?: () => void,
fail?: (error: BackgroundGeolocationError) => void
): void;
/**
* Force sync of pending locations.
* Option <code>syncThreshold</code> will be ignored and all pending locations will be immediately posted to <code>syncUrl</code> in single batch.
*
* Platform: Android, iOS
*
* @param success
* @param fail
*/
forceSync(
success?: () => void,
fail?: (error: BackgroundGeolocationError) => void
): void;
/**
* Get stored configuration options.
*
* @param success
* @param fail
*/
getConfig(
success: (options: ConfigureOptions) => void,
fail?: (error: BackgroundGeolocationError) => void
): void;
/**
* Return all logged events. Useful for plugin debugging.
*
* Platform: Android, iOS
*
* @param limit Limits number of returned entries.
* @param fromId Return entries after <code>fromId</code>. Useful if you plan to implement infinite log scrolling
* @param minLevel Available levels: ["TRACE", "DEBUG", "INFO", "WARN", "ERROR"]
* @param success
* @param fail
*/
getLogEntries(
limit: number,
fromId: number,
minLevel: LogLevel,
success: (entries: LogEntry[]) => void,
fail?: (error: BackgroundGeolocationError) => void
): void;
/**
* Unregister all event listeners for given event.
*
* If parameter <code>event</code> is not provided then all event listeners will be removed.
*
* @param event
*/
removeAllListeners(event?: Event): void;
/**
* Start background task (iOS only)
*
* To perform any long running operation on iOS
* you need to create background task
* IMPORTANT: task has to be ended by endTask
*
* @param success
* @param fail
*/
startTask(
success: (taskKey: number) => void,
fail?: (error: BackgroundGeolocationError) => void
): void;
/**
* End background task indentified by taskKey (iOS only)
*
* @param taskKey
* @param success
* @param fail
*/
endTask(
taskKey: number,
success?: () => void,
fail?: (error: BackgroundGeolocationError) => void
): void;
/**
* A special task that gets executed when the app is terminated, but
* the plugin was configured to continue running in the background
* (option <code>stopOnTerminate: false</code>).
*
* In this scenario the Activity was killed by the system and all registered
* event listeners will not be triggered until the app is relaunched.
*
* @example
* BackgroundGeolocation.headlessTask(function(event) {
*
* if (event.name === 'location' || event.name === 'stationary') {
* var xhr = new XMLHttpRequest();
* xhr.open('POST', 'http://192.168.81.14:3000/headless');
* xhr.setRequestHeader('Content-Type', 'application/json');
* xhr.send(JSON.stringify(event.params));
* }
*
* return 'Processing event: ' + event.name; // will be logged
* });
*/
headlessTask(
task: (event: HeadlessTaskEvent) => void
): void;
/**
* Register location event listener.
*
* @param eventName
* @param callback
*/
on(
eventName: 'location',
callback: (location: Location) => void
): void;
/**
* Register stationary location event listener.
*
* @param eventName
* @param callback
*/
on(
eventName: 'stationary',
callback: (location: StationaryLocation) => void
): void;
/**
* Register activity monitoring listener.
*
* @param eventName
* @param callback
*/
on(
eventName: 'activity',
callback: (activity: Activity) => void
): void;
/**
* Register start event listener.
*
* Event is triggered when background service has been started succesfully.
*
* @param eventName
* @param callback
*/
on(
eventName: 'start',
callback: () => void
): void;
/**
* Register stop event listener.
*
* Triggered when background service has been stopped succesfully.
*
* @param eventName
* @param callback
*/
on(
eventName: 'stop',
callback: () => void
): void;
/**
* Register error listener.
*
* @param eventName
* @param callback
*/
on(
eventName: 'error',
callback: (error: BackgroundGeolocationError) => void
): void;
/**
* Register authorization listener.
*
* Triggered when user changes authorization/permissions for
* the app or toggles location services.
*
* @param eventName
* @param callback
*/
on(
eventName: 'authorization',
callback: (status: AuthorizationStatus) => void
): void;
/**
* Register foreground event listener.
*
* Triggered when app entered foreground state and (visible to the user).
*
* @param eventName
* @param callback
*/
on(
eventName: 'foreground',
callback: () => void
): void;
/**
* Register background event listener.
*
* Triggered when app entered background state and (not visible to the user).
*
* @param eventName
* @param callback
*/
on(
eventName: 'background',
callback: () => void
): void;
/**
* Register abort_requested event listener.
*
* Triggered when server responded with "<code>285 Updates Not Required</code>" to post/sync request.
*
* @param eventName
* @param callback
*/
on(
eventName: 'abort_requested',
callback: () => void
): void;
/**
* Register http_authorization event listener.
*
* Triggered when server responded with "<code>401 Unauthorized</code>" to post/sync request.
*
* @param eventName
* @param callback
*/
on(
eventName: 'http_authorization',
callback: () => void
): void;
}
declare const BackgroundGeolocation: BackgroundGeolocationPlugin;
export default BackgroundGeolocation;