@transistorsoft/capacitor-background-geolocation 8.0.1 → 9.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. package/Package.swift +10 -16
  2. package/README.md +99 -211
  3. package/TransistorsoftCapacitorBackgroundGeolocation.podspec +7 -5
  4. package/android/build.gradle +16 -54
  5. package/android/src/main/java/com/transistorsoft/bggeo/capacitor/BackgroundGeolocationPlugin.java +132 -70
  6. package/dist/index.js +198 -189
  7. package/dist/index.js.map +1 -1
  8. package/dist/plugin.cjs.js +255 -205
  9. package/dist/plugin.cjs.js.map +1 -1
  10. package/dist/plugin.js +1141 -1092
  11. package/dist/plugin.js.map +1 -1
  12. package/ios/Sources/BackgroundGeolocationPlugin/BackgroundGeolocationPlugin.swift +353 -306
  13. package/package.json +14 -15
  14. package/src/index.d.ts +10 -0
  15. package/android/libs/com/transistorsoft/tslocationmanager/3.7.0/tslocationmanager-3.7.0.aar +0 -0
  16. package/android/libs/com/transistorsoft/tslocationmanager/3.7.0/tslocationmanager-3.7.0.aar.md5 +0 -1
  17. package/android/libs/com/transistorsoft/tslocationmanager/3.7.0/tslocationmanager-3.7.0.aar.sha1 +0 -1
  18. package/android/libs/com/transistorsoft/tslocationmanager/3.7.0/tslocationmanager-3.7.0.aar.sha256 +0 -1
  19. package/android/libs/com/transistorsoft/tslocationmanager/3.7.0/tslocationmanager-3.7.0.aar.sha512 +0 -1
  20. package/android/libs/com/transistorsoft/tslocationmanager/3.7.0/tslocationmanager-3.7.0.pom +0 -9
  21. package/android/libs/com/transistorsoft/tslocationmanager/3.7.0/tslocationmanager-3.7.0.pom.md5 +0 -1
  22. package/android/libs/com/transistorsoft/tslocationmanager/3.7.0/tslocationmanager-3.7.0.pom.sha1 +0 -1
  23. package/android/libs/com/transistorsoft/tslocationmanager/3.7.0/tslocationmanager-3.7.0.pom.sha256 +0 -1
  24. package/android/libs/com/transistorsoft/tslocationmanager/3.7.0/tslocationmanager-3.7.0.pom.sha512 +0 -1
  25. package/android/libs/com/transistorsoft/tslocationmanager/maven-metadata.xml +0 -13
  26. package/android/libs/com/transistorsoft/tslocationmanager-v21/3.7.0/tslocationmanager-v21-3.7.0.aar +0 -0
  27. package/android/libs/com/transistorsoft/tslocationmanager-v21/3.7.0/tslocationmanager-v21-3.7.0.aar.md5 +0 -1
  28. package/android/libs/com/transistorsoft/tslocationmanager-v21/3.7.0/tslocationmanager-v21-3.7.0.aar.sha1 +0 -1
  29. package/android/libs/com/transistorsoft/tslocationmanager-v21/3.7.0/tslocationmanager-v21-3.7.0.aar.sha256 +0 -1
  30. package/android/libs/com/transistorsoft/tslocationmanager-v21/3.7.0/tslocationmanager-v21-3.7.0.aar.sha512 +0 -1
  31. package/android/libs/com/transistorsoft/tslocationmanager-v21/3.7.0/tslocationmanager-v21-3.7.0.pom +0 -9
  32. package/android/libs/com/transistorsoft/tslocationmanager-v21/3.7.0/tslocationmanager-v21-3.7.0.pom.md5 +0 -1
  33. package/android/libs/com/transistorsoft/tslocationmanager-v21/3.7.0/tslocationmanager-v21-3.7.0.pom.sha1 +0 -1
  34. package/android/libs/com/transistorsoft/tslocationmanager-v21/3.7.0/tslocationmanager-v21-3.7.0.pom.sha256 +0 -1
  35. package/android/libs/com/transistorsoft/tslocationmanager-v21/3.7.0/tslocationmanager-v21-3.7.0.pom.sha512 +0 -1
  36. package/android/libs/com/transistorsoft/tslocationmanager-v21/maven-metadata.xml +0 -13
  37. package/dist/Events.js +0 -19
  38. package/dist/Events.js.map +0 -1
  39. package/dist/declarations/BackgroundGeolocation.d.ts +0 -1632
  40. package/dist/declarations/interfaces/Authorization.d.ts +0 -185
  41. package/dist/declarations/interfaces/AuthorizationEvent.d.ts +0 -34
  42. package/dist/declarations/interfaces/Config.d.ts +0 -2474
  43. package/dist/declarations/interfaces/ConnectivityChangeEvent.d.ts +0 -18
  44. package/dist/declarations/interfaces/CurrentPositionRequest.d.ts +0 -45
  45. package/dist/declarations/interfaces/DeviceInfo.d.ts +0 -33
  46. package/dist/declarations/interfaces/DeviceSettings.d.ts +0 -223
  47. package/dist/declarations/interfaces/Geofence.d.ts +0 -319
  48. package/dist/declarations/interfaces/GeofenceEvent.d.ts +0 -35
  49. package/dist/declarations/interfaces/GeofencesChangeEvent.d.ts +0 -22
  50. package/dist/declarations/interfaces/HeartbeatEvent.d.ts +0 -20
  51. package/dist/declarations/interfaces/HttpEvent.d.ts +0 -313
  52. package/dist/declarations/interfaces/Location.d.ts +0 -257
  53. package/dist/declarations/interfaces/LocationAuthorizationAlert.d.ts +0 -41
  54. package/dist/declarations/interfaces/Logger.d.ts +0 -359
  55. package/dist/declarations/interfaces/MotionActivityEvent.d.ts +0 -34
  56. package/dist/declarations/interfaces/MotionChangeEvent.d.ts +0 -15
  57. package/dist/declarations/interfaces/Notification.d.ts +0 -491
  58. package/dist/declarations/interfaces/PermissionRationale.d.ts +0 -31
  59. package/dist/declarations/interfaces/ProviderChangeEvent.d.ts +0 -74
  60. package/dist/declarations/interfaces/SQLQuery.d.ts +0 -60
  61. package/dist/declarations/interfaces/Sensors.d.ts +0 -31
  62. package/dist/declarations/interfaces/State.d.ts +0 -51
  63. package/dist/declarations/interfaces/Subscription.d.ts +0 -104
  64. package/dist/declarations/interfaces/TransistorAuthorizationToken.d.ts +0 -63
  65. package/dist/declarations/interfaces/WatchPositionRequest.d.ts +0 -45
  66. package/dist/declarations/types.d.ts +0 -188
  67. package/dist/index.d.ts +0 -3
package/dist/plugin.js CHANGED
@@ -1,1098 +1,1147 @@
1
- var capacitorBackgroundGeolocation = (function (core) {
2
- 'use strict';
1
+ var capacitorBackgroundGeolocation = (function (core, backgroundGeolocationTypes) {
2
+ 'use strict';
3
3
 
4
- var Events = {
5
- BOOT: "boot",
6
- TERMINATE: "terminate",
7
- LOCATION: "location",
8
- HTTP: "http",
9
- MOTIONCHANGE: "motionchange",
10
- PROVIDERCHANGE: "providerchange",
11
- HEARTBEAT: "heartbeat",
12
- ACTIVITYCHANGE: "activitychange",
13
- GEOFENCE: "geofence",
14
- GEOFENCESCHANGE: "geofenceschange",
15
- SCHEDULE: "schedule",
16
- CONNECTIVITYCHANGE: "connectivitychange",
17
- ENABLEDCHANGE: "enabledchange",
18
- POWERSAVECHANGE: "powersavechange",
19
- NOTIFICATIONACTION: "notificationaction",
20
- AUTHORIZATION: "authorization",
21
- };
4
+ /******************************************************************************
5
+ Copyright (c) Microsoft Corporation.
22
6
 
23
- var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
24
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
25
- return new (P || (P = Promise))(function (resolve, reject) {
26
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
27
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
28
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
29
- step((generator = generator.apply(thisArg, _arguments || [])).next());
30
- });
31
- };
32
- var __generator = (undefined && undefined.__generator) || function (thisArg, body) {
33
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
34
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
35
- function verb(n) { return function (v) { return step([n, v]); }; }
36
- function step(op) {
37
- if (f) throw new TypeError("Generator is already executing.");
38
- while (_) try {
39
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
40
- if (y = 0, t) op = [op[0] & 2, t.value];
41
- switch (op[0]) {
42
- case 0: case 1: t = op; break;
43
- case 4: _.label++; return { value: op[1], done: false };
44
- case 5: _.label++; y = op[1]; op = [0]; continue;
45
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
46
- default:
47
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
48
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
49
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
50
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
51
- if (t[2]) _.ops.pop();
52
- _.trys.pop(); continue;
53
- }
54
- op = body.call(thisArg, _);
55
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
56
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : undefined, done: true };
57
- }
58
- };
59
- var NativeModule = core.registerPlugin('BackgroundGeolocation');
60
- /**
61
- * Logger
62
- */
63
- var LOGGER_LOG_LEVEL_DEBUG = "debug";
64
- var LOGGER_LOG_LEVEL_NOTICE = "notice";
65
- var LOGGER_LOG_LEVEL_INFO = "info";
66
- var LOGGER_LOG_LEVEL_WARN = "warn";
67
- var LOGGER_LOG_LEVEL_ERROR = "error";
68
- var ORDER_ASC = 1;
69
- var ORDER_DESC = -1;
70
- function log(level, msg) {
71
- return NativeModule.log({
72
- level: level,
73
- message: msg
74
- });
75
- }
76
- function validateQuery(query) {
77
- if (typeof (query) !== 'object')
78
- return {};
79
- if (query.hasOwnProperty('start') && isNaN(query.start)) {
80
- throw new Error('Invalid SQLQuery.start. Expected unix timestamp but received: ' + query.start);
81
- }
82
- if (query.hasOwnProperty('end') && isNaN(query.end)) {
83
- throw new Error('Invalid SQLQuery.end. Expected unix timestamp but received: ' + query.end);
84
- }
85
- return query;
86
- }
87
- var Logger = /** @class */ (function () {
88
- function Logger() {
89
- }
90
- Object.defineProperty(Logger, "ORDER_ASC", {
91
- get: function () { return ORDER_ASC; },
92
- enumerable: false,
93
- configurable: true
94
- });
95
- Object.defineProperty(Logger, "ORDER_DESC", {
96
- get: function () { return ORDER_DESC; },
97
- enumerable: false,
98
- configurable: true
99
- });
100
- Logger.debug = function (msg) {
101
- return log(LOGGER_LOG_LEVEL_DEBUG, msg);
102
- };
103
- Logger.error = function (msg) {
104
- return log(LOGGER_LOG_LEVEL_ERROR, msg);
105
- };
106
- Logger.warn = function (msg) {
107
- return log(LOGGER_LOG_LEVEL_WARN, msg);
108
- };
109
- Logger.info = function (msg) {
110
- return log(LOGGER_LOG_LEVEL_INFO, msg);
111
- };
112
- Logger.notice = function (msg) {
113
- return log(LOGGER_LOG_LEVEL_NOTICE, msg);
114
- };
115
- Logger.getLog = function (query) {
116
- query = validateQuery(query);
117
- return new Promise(function (resolve, reject) {
118
- NativeModule.getLog({ options: query }).then(function (result) {
119
- resolve(result.log);
120
- }).catch(function (error) {
121
- reject(error.message);
122
- });
123
- });
124
- };
125
- Logger.destroyLog = function () {
126
- return new Promise(function (resolve, reject) {
127
- NativeModule.destroyLog().then(function () {
128
- resolve();
129
- }).catch(function (error) {
130
- reject(error.message);
131
- });
132
- });
133
- };
134
- Logger.emailLog = function (email, query) {
135
- query = validateQuery(query);
136
- return new Promise(function (resolve, reject) {
137
- NativeModule.emailLog({ email: email, query: query }).then(function (result) {
138
- resolve(result);
139
- }).catch(function (error) {
140
- reject(error.message);
141
- });
142
- });
143
- };
144
- Logger.uploadLog = function (url, query) {
145
- query = validateQuery(query);
146
- return new Promise(function (resolve, reject) {
147
- NativeModule.uploadLog({ url: url, query: query }).then(function () {
148
- resolve();
149
- }).catch(function (error) {
150
- reject(error.message);
151
- });
152
- });
153
- };
154
- return Logger;
155
- }());
156
- /**
157
- * TransistorAuthorizationToken
158
- */
159
- var DEFAULT_URL = 'http://tracker.transistorsoft.com';
160
- var DUMMY_TOKEN = 'DUMMY_TOKEN';
161
- var REFRESH_PAYLOAD = {
162
- refresh_token: '{refreshToken}'
163
- };
164
- var LOCATIONS_PATH = '/api/locations';
165
- var REFRESH_TOKEN_PATH = '/api/refresh_token';
166
- var TransistorAuthorizationToken = /** @class */ (function () {
167
- function TransistorAuthorizationToken() {
168
- }
169
- TransistorAuthorizationToken.findOrCreate = function (orgname, username, url) {
170
- if (url === undefined) { url = DEFAULT_URL; }
171
- return new Promise(function (resolve, reject) {
172
- NativeModule.getTransistorToken({
173
- org: orgname,
174
- username: username,
175
- url: url
176
- }).then(function (result) {
177
- if (result.success) {
178
- var token = result.token;
179
- token.url = url;
180
- resolve(token);
181
- }
182
- else {
183
- console.warn('[TransistorAuthorizationToken findOrCreate] ERROR: ', result);
184
- if (result.status == '403') {
185
- reject(result);
186
- return;
187
- }
188
- resolve({
189
- accessToken: DUMMY_TOKEN,
190
- refreshToken: DUMMY_TOKEN,
191
- expires: -1,
192
- url: url
193
- });
194
- }
195
- }).catch(function (error) {
196
- reject(error);
197
- });
198
- });
199
- };
200
- TransistorAuthorizationToken.destroy = function (url) {
201
- if (url === undefined) { url = DEFAULT_URL; }
202
- return new Promise(function (resolve, reject) {
203
- NativeModule.destroyTransistorToken({ url: url }).then(function () {
204
- resolve();
205
- }).catch(function (error) {
206
- reject(error.message);
207
- });
208
- });
209
- };
210
- TransistorAuthorizationToken.applyIf = function (config) {
211
- if (!config.transistorAuthorizationToken)
212
- return config;
213
- var token = config.transistorAuthorizationToken;
214
- delete config.transistorAuthorizationToken;
215
- config.url = token.url + LOCATIONS_PATH;
216
- config.authorization = {
217
- strategy: 'JWT',
218
- accessToken: token.accessToken,
219
- refreshToken: token.refreshToken,
220
- refreshUrl: token.url + REFRESH_TOKEN_PATH,
221
- refreshPayload: REFRESH_PAYLOAD,
222
- expires: token.expires
223
- };
224
- return config;
225
- };
226
- return TransistorAuthorizationToken;
227
- }());
228
- /**
229
- * DeviceSettings
230
- */
231
- var IGNORE_BATTERY_OPTIMIZATIONS = "IGNORE_BATTERY_OPTIMIZATIONS";
232
- var POWER_MANAGER = "POWER_MANAGER";
233
- var resolveSettingsRequest = function (resolve, request) {
234
- if (request.lastSeenAt > 0) {
235
- request.lastSeenAt = new Date(request.lastSeenAt);
236
- }
237
- resolve(request);
238
- };
239
- var DeviceSettings = /** @class */ (function () {
240
- function DeviceSettings() {
241
- }
242
- DeviceSettings.isIgnoringBatteryOptimizations = function () {
243
- return new Promise(function (resolve, reject) {
244
- NativeModule.isIgnoringBatteryOptimizations().then(function (result) {
245
- resolve(result.isIgnoringBatteryOptimizations);
246
- }).catch(function (error) {
247
- reject(error.message);
248
- });
249
- });
250
- };
251
- DeviceSettings.showIgnoreBatteryOptimizations = function () {
252
- return new Promise(function (resolve, reject) {
253
- var args = { action: IGNORE_BATTERY_OPTIMIZATIONS };
254
- NativeModule.requestSettings(args).then(function (result) {
255
- resolveSettingsRequest(resolve, result);
256
- }).catch(function (error) {
257
- reject(error.message);
258
- });
259
- });
260
- };
261
- DeviceSettings.showPowerManager = function () {
262
- return new Promise(function (resolve, reject) {
263
- var args = { action: POWER_MANAGER };
264
- NativeModule.requestSettings(args).then(function (result) {
265
- resolveSettingsRequest(resolve, result);
266
- }).catch(function (error) {
267
- reject(error.message);
268
- });
269
- });
270
- };
271
- DeviceSettings.show = function (request) {
272
- return new Promise(function (resolve, reject) {
273
- var args = { action: request.action };
274
- NativeModule.showSettings(args).then(function () {
275
- resolve();
276
- }).catch(function (error) {
277
- reject(error.message);
278
- });
279
- });
280
- };
281
- return DeviceSettings;
282
- }());
283
- var TAG = "TSLocationManager";
284
- /// Container for event-subscriptions.
285
- var EVENT_SUBSCRIPTIONS = [];
286
- /// Container for watchPostion subscriptions.
287
- var WATCH_POSITION_SUBSCRIPTIONS = [];
288
- /// Event handler Subscription
289
- ///
290
- var Subscription = /** @class */ (function () {
291
- function Subscription(event, subscription, callback) {
292
- this.event = event;
293
- this.subscription = subscription;
294
- this.callback = callback;
295
- }
296
- return Subscription;
297
- }());
298
- /// Validate provided config for #ready, #setConfig, #reset.
299
- var validateConfig = function (config) {
300
- // Detect obsolete notification* fields and re-map to Notification instance.
301
- if ((config.notificationPriority) ||
302
- (config.notificationText) ||
303
- (config.notificationTitle) ||
304
- (config.notificationChannelName) ||
305
- (config.notificationColor) ||
306
- (config.notificationSmallIcon) ||
307
- (config.notificationLargeIcon)) {
308
- console.warn('[BackgroundGeolocation] WARNING: Config.notification* fields (eg: notificationText) are all deprecated in favor of notification: {title: "My Title", text: "My Text"} See docs for "Notification" class');
309
- config.notification = {
310
- text: config.notificationText,
311
- title: config.notificationTitle,
312
- color: config.notificationColor,
313
- channelName: config.notificationChannelName,
314
- smallIcon: config.notificationSmallIcon,
315
- largeIcon: config.notificationLargeIcon,
316
- priority: config.notificationPriority
317
- };
318
- }
319
- config = TransistorAuthorizationToken.applyIf(config);
320
- return config;
321
- };
322
- var LOG_LEVEL_OFF = 0;
323
- var LOG_LEVEL_ERROR = 1;
324
- var LOG_LEVEL_WARNING = 2;
325
- var LOG_LEVEL_INFO = 3;
326
- var LOG_LEVEL_DEBUG = 4;
327
- var LOG_LEVEL_VERBOSE = 5;
328
- var DESIRED_ACCURACY_NAVIGATION = -2;
329
- var DESIRED_ACCURACY_HIGH = -1;
330
- var DESIRED_ACCURACY_MEDIUM = 10;
331
- var DESIRED_ACCURACY_LOW = 100;
332
- var DESIRED_ACCURACY_VERY_LOW = 1000;
333
- var DESIRED_ACCURACY_LOWEST = 3000;
334
- var AUTHORIZATION_STATUS_NOT_DETERMINED = 0;
335
- var AUTHORIZATION_STATUS_RESTRICTED = 1;
336
- var AUTHORIZATION_STATUS_DENIED = 2;
337
- var AUTHORIZATION_STATUS_ALWAYS = 3;
338
- var AUTHORIZATION_STATUS_WHEN_IN_USE = 4;
339
- var NOTIFICATION_PRIORITY_DEFAULT = 0;
340
- var NOTIFICATION_PRIORITY_HIGH = 1;
341
- var NOTIFICATION_PRIORITY_LOW = -1;
342
- var NOTIFICATION_PRIORITY_MAX = 2;
343
- var NOTIFICATION_PRIORITY_MIN = -2;
344
- var ACTIVITY_TYPE_OTHER = 1;
345
- var ACTIVITY_TYPE_AUTOMOTIVE_NAVIGATION = 2;
346
- var ACTIVITY_TYPE_FITNESS = 3;
347
- var ACTIVITY_TYPE_OTHER_NAVIGATION = 4;
348
- var ACTIVITY_TYPE_AIRBORNE = 5;
349
- var LOCATION_AUTHORIZATION_ALWAYS = "Always";
350
- var LOCATION_AUTHORIZATION_WHEN_IN_USE = "WhenInUse";
351
- var LOCATION_AUTHORIZATION_ANY = "Any";
352
- var PERSIST_MODE_ALL = 2;
353
- var PERSIST_MODE_LOCATION = 1;
354
- var PERSIST_MODE_GEOFENCE = -1;
355
- var PERSIST_MODE_NONE = 0;
356
- var ACCURACY_AUTHORIZATION_FULL = 0;
357
- var ACCURACY_AUTHORIZATION_REDUCED = 1;
358
- /// BackgroundGeolocation JS API
359
- var BackgroundGeolocation = /** @class */ (function () {
360
- function BackgroundGeolocation() {
361
- }
362
- Object.defineProperty(BackgroundGeolocation, "EVENT_BOOT", {
363
- /// Events
364
- get: function () { return Events.BOOT; },
365
- enumerable: false,
366
- configurable: true
367
- });
368
- Object.defineProperty(BackgroundGeolocation, "EVENT_TERMINATE", {
369
- get: function () { return Events.TERMINATE; },
370
- enumerable: false,
371
- configurable: true
372
- });
373
- Object.defineProperty(BackgroundGeolocation, "EVENT_LOCATION", {
374
- get: function () { return Events.LOCATION; },
375
- enumerable: false,
376
- configurable: true
377
- });
378
- Object.defineProperty(BackgroundGeolocation, "EVENT_MOTIONCHANGE", {
379
- get: function () { return Events.MOTIONCHANGE; },
380
- enumerable: false,
381
- configurable: true
382
- });
383
- Object.defineProperty(BackgroundGeolocation, "EVENT_HTTP", {
384
- get: function () { return Events.HTTP; },
385
- enumerable: false,
386
- configurable: true
387
- });
388
- Object.defineProperty(BackgroundGeolocation, "EVENT_HEARTBEAT", {
389
- get: function () { return Events.HEARTBEAT; },
390
- enumerable: false,
391
- configurable: true
392
- });
393
- Object.defineProperty(BackgroundGeolocation, "EVENT_PROVIDERCHANGE", {
394
- get: function () { return Events.PROVIDERCHANGE; },
395
- enumerable: false,
396
- configurable: true
397
- });
398
- Object.defineProperty(BackgroundGeolocation, "EVENT_ACTIVITYCHANGE", {
399
- get: function () { return Events.ACTIVITYCHANGE; },
400
- enumerable: false,
401
- configurable: true
402
- });
403
- Object.defineProperty(BackgroundGeolocation, "EVENT_GEOFENCE", {
404
- get: function () { return Events.GEOFENCE; },
405
- enumerable: false,
406
- configurable: true
407
- });
408
- Object.defineProperty(BackgroundGeolocation, "EVENT_GEOFENCESCHANGE", {
409
- get: function () { return Events.GEOFENCESCHANGE; },
410
- enumerable: false,
411
- configurable: true
412
- });
413
- Object.defineProperty(BackgroundGeolocation, "EVENT_ENABLEDCHANGE", {
414
- get: function () { return Events.ENABLEDCHANGE; },
415
- enumerable: false,
416
- configurable: true
417
- });
418
- Object.defineProperty(BackgroundGeolocation, "EVENT_CONNECTIVITYCHANGE", {
419
- get: function () { return Events.CONNECTIVITYCHANGE; },
420
- enumerable: false,
421
- configurable: true
422
- });
423
- Object.defineProperty(BackgroundGeolocation, "EVENT_SCHEDULE", {
424
- get: function () { return Events.SCHEDULE; },
425
- enumerable: false,
426
- configurable: true
427
- });
428
- Object.defineProperty(BackgroundGeolocation, "EVENT_POWERSAVECHANGE", {
429
- get: function () { return Events.POWERSAVECHANGE; },
430
- enumerable: false,
431
- configurable: true
432
- });
433
- Object.defineProperty(BackgroundGeolocation, "EVENT_NOTIFICATIONACTION", {
434
- get: function () { return Events.NOTIFICATIONACTION; },
435
- enumerable: false,
436
- configurable: true
437
- });
438
- Object.defineProperty(BackgroundGeolocation, "EVENT_AUTHORIZATION", {
439
- get: function () { return Events.AUTHORIZATION; },
440
- enumerable: false,
441
- configurable: true
442
- });
443
- Object.defineProperty(BackgroundGeolocation, "LOG_LEVEL_OFF", {
444
- get: function () { return LOG_LEVEL_OFF; },
445
- enumerable: false,
446
- configurable: true
447
- });
448
- Object.defineProperty(BackgroundGeolocation, "LOG_LEVEL_ERROR", {
449
- get: function () { return LOG_LEVEL_ERROR; },
450
- enumerable: false,
451
- configurable: true
452
- });
453
- Object.defineProperty(BackgroundGeolocation, "LOG_LEVEL_WARNING", {
454
- get: function () { return LOG_LEVEL_WARNING; },
455
- enumerable: false,
456
- configurable: true
457
- });
458
- Object.defineProperty(BackgroundGeolocation, "LOG_LEVEL_INFO", {
459
- get: function () { return LOG_LEVEL_INFO; },
460
- enumerable: false,
461
- configurable: true
462
- });
463
- Object.defineProperty(BackgroundGeolocation, "LOG_LEVEL_DEBUG", {
464
- get: function () { return LOG_LEVEL_DEBUG; },
465
- enumerable: false,
466
- configurable: true
467
- });
468
- Object.defineProperty(BackgroundGeolocation, "LOG_LEVEL_VERBOSE", {
469
- get: function () { return LOG_LEVEL_VERBOSE; },
470
- enumerable: false,
471
- configurable: true
472
- });
473
- Object.defineProperty(BackgroundGeolocation, "ACTIVITY_TYPE_OTHER", {
474
- get: function () { return ACTIVITY_TYPE_OTHER; },
475
- enumerable: false,
476
- configurable: true
477
- });
478
- Object.defineProperty(BackgroundGeolocation, "ACTIVITY_TYPE_AUTOMOTIVE_NAVIGATION", {
479
- get: function () { return ACTIVITY_TYPE_AUTOMOTIVE_NAVIGATION; },
480
- enumerable: false,
481
- configurable: true
482
- });
483
- Object.defineProperty(BackgroundGeolocation, "ACTIVITY_TYPE_FITNESS", {
484
- get: function () { return ACTIVITY_TYPE_FITNESS; },
485
- enumerable: false,
486
- configurable: true
487
- });
488
- Object.defineProperty(BackgroundGeolocation, "ACTIVITY_TYPE_OTHER_NAVIGATION", {
489
- get: function () { return ACTIVITY_TYPE_OTHER_NAVIGATION; },
490
- enumerable: false,
491
- configurable: true
492
- });
493
- Object.defineProperty(BackgroundGeolocation, "ACTIVITY_TYPE_AIRBORNE", {
494
- get: function () { return ACTIVITY_TYPE_AIRBORNE; },
495
- enumerable: false,
496
- configurable: true
497
- });
498
- Object.defineProperty(BackgroundGeolocation, "DESIRED_ACCURACY_NAVIGATION", {
499
- get: function () { return DESIRED_ACCURACY_NAVIGATION; },
500
- enumerable: false,
501
- configurable: true
502
- });
503
- Object.defineProperty(BackgroundGeolocation, "DESIRED_ACCURACY_HIGH", {
504
- get: function () { return DESIRED_ACCURACY_HIGH; },
505
- enumerable: false,
506
- configurable: true
507
- });
508
- Object.defineProperty(BackgroundGeolocation, "DESIRED_ACCURACY_MEDIUM", {
509
- get: function () { return DESIRED_ACCURACY_MEDIUM; },
510
- enumerable: false,
511
- configurable: true
512
- });
513
- Object.defineProperty(BackgroundGeolocation, "DESIRED_ACCURACY_LOW", {
514
- get: function () { return DESIRED_ACCURACY_LOW; },
515
- enumerable: false,
516
- configurable: true
517
- });
518
- Object.defineProperty(BackgroundGeolocation, "DESIRED_ACCURACY_VERY_LOW", {
519
- get: function () { return DESIRED_ACCURACY_VERY_LOW; },
520
- enumerable: false,
521
- configurable: true
522
- });
523
- Object.defineProperty(BackgroundGeolocation, "DESIRED_ACCURACY_LOWEST", {
524
- get: function () { return DESIRED_ACCURACY_LOWEST; },
525
- enumerable: false,
526
- configurable: true
527
- });
528
- Object.defineProperty(BackgroundGeolocation, "AUTHORIZATION_STATUS_NOT_DETERMINED", {
529
- get: function () { return AUTHORIZATION_STATUS_NOT_DETERMINED; },
530
- enumerable: false,
531
- configurable: true
532
- });
533
- Object.defineProperty(BackgroundGeolocation, "AUTHORIZATION_STATUS_RESTRICTED", {
534
- get: function () { return AUTHORIZATION_STATUS_RESTRICTED; },
535
- enumerable: false,
536
- configurable: true
537
- });
538
- Object.defineProperty(BackgroundGeolocation, "AUTHORIZATION_STATUS_DENIED", {
539
- get: function () { return AUTHORIZATION_STATUS_DENIED; },
540
- enumerable: false,
541
- configurable: true
542
- });
543
- Object.defineProperty(BackgroundGeolocation, "AUTHORIZATION_STATUS_ALWAYS", {
544
- get: function () { return AUTHORIZATION_STATUS_ALWAYS; },
545
- enumerable: false,
546
- configurable: true
547
- });
548
- Object.defineProperty(BackgroundGeolocation, "AUTHORIZATION_STATUS_WHEN_IN_USE", {
549
- get: function () { return AUTHORIZATION_STATUS_WHEN_IN_USE; },
550
- enumerable: false,
551
- configurable: true
552
- });
553
- Object.defineProperty(BackgroundGeolocation, "NOTIFICATION_PRIORITY_DEFAULT", {
554
- get: function () { return NOTIFICATION_PRIORITY_DEFAULT; },
555
- enumerable: false,
556
- configurable: true
557
- });
558
- Object.defineProperty(BackgroundGeolocation, "NOTIFICATION_PRIORITY_HIGH", {
559
- get: function () { return NOTIFICATION_PRIORITY_HIGH; },
560
- enumerable: false,
561
- configurable: true
562
- });
563
- Object.defineProperty(BackgroundGeolocation, "NOTIFICATION_PRIORITY_LOW", {
564
- get: function () { return NOTIFICATION_PRIORITY_LOW; },
565
- enumerable: false,
566
- configurable: true
567
- });
568
- Object.defineProperty(BackgroundGeolocation, "NOTIFICATION_PRIORITY_MAX", {
569
- get: function () { return NOTIFICATION_PRIORITY_MAX; },
570
- enumerable: false,
571
- configurable: true
572
- });
573
- Object.defineProperty(BackgroundGeolocation, "NOTIFICATION_PRIORITY_MIN", {
574
- get: function () { return NOTIFICATION_PRIORITY_MIN; },
575
- enumerable: false,
576
- configurable: true
577
- });
578
- Object.defineProperty(BackgroundGeolocation, "LOCATION_AUTHORIZATION_ALWAYS", {
579
- get: function () { return LOCATION_AUTHORIZATION_ALWAYS; },
580
- enumerable: false,
581
- configurable: true
582
- });
583
- Object.defineProperty(BackgroundGeolocation, "LOCATION_AUTHORIZATION_WHEN_IN_USE", {
584
- get: function () { return LOCATION_AUTHORIZATION_WHEN_IN_USE; },
585
- enumerable: false,
586
- configurable: true
587
- });
588
- Object.defineProperty(BackgroundGeolocation, "LOCATION_AUTHORIZATION_ANY", {
589
- get: function () { return LOCATION_AUTHORIZATION_ANY; },
590
- enumerable: false,
591
- configurable: true
592
- });
593
- Object.defineProperty(BackgroundGeolocation, "PERSIST_MODE_ALL", {
594
- get: function () { return PERSIST_MODE_ALL; },
595
- enumerable: false,
596
- configurable: true
597
- });
598
- Object.defineProperty(BackgroundGeolocation, "PERSIST_MODE_LOCATION", {
599
- get: function () { return PERSIST_MODE_LOCATION; },
600
- enumerable: false,
601
- configurable: true
602
- });
603
- Object.defineProperty(BackgroundGeolocation, "PERSIST_MODE_GEOFENCE", {
604
- get: function () { return PERSIST_MODE_GEOFENCE; },
605
- enumerable: false,
606
- configurable: true
607
- });
608
- Object.defineProperty(BackgroundGeolocation, "PERSIST_MODE_NONE", {
609
- get: function () { return PERSIST_MODE_NONE; },
610
- enumerable: false,
611
- configurable: true
612
- });
613
- Object.defineProperty(BackgroundGeolocation, "ACCURACY_AUTHORIZATION_FULL", {
614
- get: function () { return ACCURACY_AUTHORIZATION_FULL; },
615
- enumerable: false,
616
- configurable: true
617
- });
618
- Object.defineProperty(BackgroundGeolocation, "ACCURACY_AUTHORIZATION_REDUCED", {
619
- get: function () { return ACCURACY_AUTHORIZATION_REDUCED; },
620
- enumerable: false,
621
- configurable: true
622
- });
623
- Object.defineProperty(BackgroundGeolocation, "logger", {
624
- get: function () { return Logger; },
625
- enumerable: false,
626
- configurable: true
627
- });
628
- Object.defineProperty(BackgroundGeolocation, "deviceSettings", {
629
- get: function () { return DeviceSettings; },
630
- enumerable: false,
631
- configurable: true
632
- });
633
- BackgroundGeolocation.ready = function (config) {
634
- return NativeModule.ready({ options: validateConfig(config) });
635
- };
636
- BackgroundGeolocation.reset = function (config) {
637
- return NativeModule.reset({ options: validateConfig(config) });
638
- };
639
- BackgroundGeolocation.start = function () {
640
- return NativeModule.start();
641
- };
642
- BackgroundGeolocation.stop = function () {
643
- return NativeModule.stop();
644
- };
645
- BackgroundGeolocation.startSchedule = function () {
646
- return NativeModule.startSchedule();
647
- };
648
- BackgroundGeolocation.stopSchedule = function () {
649
- return NativeModule.stopSchedule();
650
- };
651
- BackgroundGeolocation.startGeofences = function () {
652
- return NativeModule.startGeofences();
653
- };
654
- BackgroundGeolocation.setConfig = function (config) {
655
- return NativeModule.setConfig({ options: validateConfig(config) });
656
- };
657
- BackgroundGeolocation.getState = function () {
658
- return NativeModule.getState();
659
- };
660
- BackgroundGeolocation.changePace = function (isMoving) {
661
- return new Promise(function (resolve, reject) {
662
- NativeModule.changePace({ isMoving: isMoving }).then(function () {
663
- resolve();
664
- }).catch(function (error) {
665
- reject(error.errorMessage);
666
- });
667
- });
668
- };
669
- BackgroundGeolocation.getCurrentPosition = function (options) {
670
- options = options || {};
671
- return new Promise(function (resolve, reject) {
672
- NativeModule.getCurrentPosition({ options: options }).then(function (result) {
673
- resolve(result);
674
- }).catch(function (error) {
675
- reject(error.code);
676
- });
677
- });
678
- };
679
- BackgroundGeolocation.watchPosition = function (onLocation, onError, options) {
680
- var _this = this;
681
- options = options || {};
682
- return new Promise(function (resolve, reject) { return __awaiter(_this, undefined, undefined, function () {
683
- var handler, listener;
684
- return __generator(this, function (_a) {
685
- switch (_a.label) {
686
- case 0:
687
- handler = function (response) {
688
- if (response.hasOwnProperty("error") && (response.error != null)) {
689
- if (typeof (onError) === 'function') {
690
- onError(response.error.code);
691
- }
692
- else {
693
- console.warn('[BackgroundGeolocation watchPostion] DEFAULT ERROR HANDLER. Provide an onError handler to watchPosition to receive this message: ', response.error);
694
- }
695
- }
696
- else {
697
- onLocation(response);
698
- }
699
- };
700
- return [4 /*yield*/, NativeModule.addListener("watchposition", handler)];
701
- case 1:
702
- listener = _a.sent();
703
- NativeModule.watchPosition({ options: options }).then(function () {
704
- WATCH_POSITION_SUBSCRIPTIONS.push(listener);
705
- resolve();
706
- }).catch(function (error) {
707
- listener.remove();
708
- reject(error.message);
709
- });
710
- return [2 /*return*/];
711
- }
712
- });
713
- }); });
714
- };
715
- BackgroundGeolocation.stopWatchPosition = function () {
716
- for (var n = 0; n < WATCH_POSITION_SUBSCRIPTIONS.length; n++) {
717
- var subscription = WATCH_POSITION_SUBSCRIPTIONS[n];
718
- subscription.remove();
719
- }
720
- return NativeModule.stopWatchPosition();
721
- };
722
- BackgroundGeolocation.requestPermission = function () {
723
- return new Promise(function (resolve, reject) {
724
- NativeModule.requestPermission().then(function (result) {
725
- if (result.success) {
726
- resolve(result.status);
727
- }
728
- else {
729
- reject(result.status);
730
- }
731
- });
732
- });
733
- };
734
- BackgroundGeolocation.requestTemporaryFullAccuracy = function (purpose) {
735
- return new Promise(function (resolve, reject) {
736
- NativeModule.requestTemporaryFullAccuracy({ purpose: purpose }).then(function (result) {
737
- resolve(result.accuracyAuthorization);
738
- }).catch(function (error) {
739
- reject(error.message);
740
- });
741
- });
742
- };
743
- BackgroundGeolocation.getProviderState = function () {
744
- return NativeModule.getProviderState();
745
- };
746
- /// Locations database
747
- ///
748
- BackgroundGeolocation.getLocations = function () {
749
- return new Promise(function (resolve, reject) {
750
- NativeModule.getLocations().then(function (result) {
751
- resolve(result.locations);
752
- }).catch(function (error) {
753
- reject(error.message);
754
- });
755
- });
756
- };
757
- BackgroundGeolocation.insertLocation = function (params) {
758
- return new Promise(function (resolve, reject) {
759
- NativeModule.insertLocation({ options: params }).then(function (result) {
760
- resolve(result.uuid);
761
- }).catch(function (error) {
762
- reject(error.message);
763
- });
764
- });
765
- };
766
- BackgroundGeolocation.destroyLocations = function () {
767
- return new Promise(function (resolve, reject) {
768
- NativeModule.destroyLocations().then(function () {
769
- resolve();
770
- }).catch(function (error) {
771
- reject(error.message);
772
- });
773
- });
774
- };
775
- BackgroundGeolocation.destroyLocation = function (uuid) {
776
- return new Promise(function (resolve, reject) {
777
- NativeModule.destroyLocation({ uuid: uuid }).then(function () {
778
- resolve();
779
- }).catch(function (error) {
780
- reject(error.message);
781
- });
782
- });
783
- };
784
- BackgroundGeolocation.getCount = function () {
785
- return new Promise(function (resolve, reject) {
786
- NativeModule.getCount().then(function (result) {
787
- resolve(result.count);
788
- }).catch(function (error) {
789
- reject(error.message);
790
- });
791
- });
792
- };
793
- BackgroundGeolocation.sync = function () {
794
- return new Promise(function (resolve, reject) {
795
- NativeModule.sync().then(function (result) {
796
- resolve(result.locations);
797
- }).catch(function (error) {
798
- reject(error.message);
799
- });
800
- });
801
- };
802
- /// Geofencing
803
- ///
804
- BackgroundGeolocation.addGeofence = function (params) {
805
- return new Promise(function (resolve, reject) {
806
- NativeModule.addGeofence({ options: params }).then(function () {
807
- resolve();
808
- }).catch(function (error) {
809
- reject(error.message);
810
- });
811
- });
812
- };
813
- BackgroundGeolocation.addGeofences = function (params) {
814
- return new Promise(function (resolve, reject) {
815
- NativeModule.addGeofences({ options: params }).then(function () {
816
- resolve();
817
- }).catch(function (error) {
818
- reject(error.message);
819
- });
820
- });
821
- };
822
- BackgroundGeolocation.getGeofences = function () {
823
- return new Promise(function (resolve, reject) {
824
- NativeModule.getGeofences().then(function (result) {
825
- resolve(result.geofences);
826
- }).catch(function (error) {
827
- reject(error.message);
828
- });
829
- });
830
- };
831
- BackgroundGeolocation.getGeofence = function (identifier) {
832
- return new Promise(function (resolve, reject) {
833
- if (identifier === null) {
834
- reject('identifier is null');
835
- return;
836
- }
837
- NativeModule.getGeofence({ identifier: identifier }).then(function (result) {
838
- resolve(result);
839
- }).catch(function (error) {
840
- reject(error.message);
841
- });
842
- });
843
- };
844
- BackgroundGeolocation.geofenceExists = function (identifier) {
845
- return new Promise(function (resolve, reject) {
846
- if (identifier === null) {
847
- reject('identifier is null');
848
- return;
849
- }
850
- NativeModule.geofenceExists({ identifier: identifier }).then(function (result) {
851
- resolve(result.exists);
852
- }).catch(function (error) {
853
- reject(error.message);
854
- });
855
- });
856
- };
857
- BackgroundGeolocation.removeGeofence = function (identifier) {
858
- return new Promise(function (resolve, reject) {
859
- if (identifier === null) {
860
- reject('identifier is null');
861
- return;
862
- }
863
- NativeModule.removeGeofence({ identifier: identifier }).then(function () {
864
- resolve();
865
- }).catch(function (error) {
866
- reject(error.message);
867
- });
868
- });
869
- };
870
- BackgroundGeolocation.removeGeofences = function (identifiers) {
871
- identifiers = identifiers || [];
872
- return new Promise(function (resolve, reject) {
873
- NativeModule.removeGeofences({ identifiers: identifiers }).then(function () {
874
- resolve();
875
- }).catch(function (error) {
876
- reject(error.message);
877
- });
878
- });
879
- };
880
- /// Odometer
881
- ///
882
- BackgroundGeolocation.getOdometer = function () {
883
- return new Promise(function (resolve, reject) {
884
- NativeModule.getOdometer().then(function (result) {
885
- resolve(result.odometer);
886
- }).catch(function (error) {
887
- reject(error.message);
888
- });
889
- });
890
- };
891
- BackgroundGeolocation.setOdometer = function (value) {
892
- return new Promise(function (resolve, reject) {
893
- NativeModule.setOdometer({ "odometer": value }).then(function (result) {
894
- resolve(result);
895
- }).catch(function (error) {
896
- reject(error.message);
897
- });
898
- });
899
- };
900
- BackgroundGeolocation.resetOdometer = function () {
901
- return BackgroundGeolocation.setOdometer(0);
902
- };
903
- /// Background Tasks
904
- ///
905
- BackgroundGeolocation.startBackgroundTask = function () {
906
- return new Promise(function (resolve, reject) {
907
- NativeModule.startBackgroundTask().then(function (result) {
908
- resolve(result.taskId);
909
- }).catch(function (error) {
910
- reject(error.message);
911
- });
912
- });
913
- };
914
- BackgroundGeolocation.stopBackgroundTask = function (taskId) {
915
- return new Promise(function (resolve, reject) {
916
- NativeModule.stopBackgroundTask({ taskId: taskId }).then(function () {
917
- resolve();
918
- }).catch(function (error) {
919
- reject(error.message);
920
- });
921
- });
922
- };
923
- /// @alias stopBackgroundTask
924
- BackgroundGeolocation.finish = function (taskId) {
925
- return BackgroundGeolocation.stopBackgroundTask(taskId);
926
- };
927
- BackgroundGeolocation.getDeviceInfo = function () {
928
- return NativeModule.getDeviceInfo();
929
- };
930
- BackgroundGeolocation.playSound = function (soundId) {
931
- return NativeModule.playSound({ soundId: soundId });
932
- };
933
- BackgroundGeolocation.isPowerSaveMode = function () {
934
- return new Promise(function (resolve, reject) {
935
- NativeModule.isPowerSaveMode().then(function (result) {
936
- resolve(result.isPowerSaveMode);
937
- }).catch(function (error) {
938
- reject(error.message);
939
- });
940
- });
941
- };
942
- BackgroundGeolocation.getSensors = function () {
943
- return NativeModule.getSensors();
944
- };
945
- /// TransistorAuthorizationToken
946
- ///
947
- BackgroundGeolocation.findOrCreateTransistorAuthorizationToken = function (orgname, username, url) {
948
- return TransistorAuthorizationToken.findOrCreate(orgname, username, url);
949
- };
950
- BackgroundGeolocation.destroyTransistorAuthorizationToken = function (url) {
951
- return TransistorAuthorizationToken.destroy(url);
952
- };
953
- /// Event Handling
954
- ///
955
- BackgroundGeolocation.onLocation = function (success, failure) {
956
- return BackgroundGeolocation.addListener(Events.LOCATION, success, failure);
957
- };
958
- BackgroundGeolocation.onMotionChange = function (success) {
959
- return BackgroundGeolocation.addListener(Events.MOTIONCHANGE, success);
960
- };
961
- BackgroundGeolocation.onHttp = function (success) {
962
- return BackgroundGeolocation.addListener(Events.HTTP, success);
963
- };
964
- BackgroundGeolocation.onHeartbeat = function (success) {
965
- return BackgroundGeolocation.addListener(Events.HEARTBEAT, success);
966
- };
967
- BackgroundGeolocation.onProviderChange = function (success) {
968
- return BackgroundGeolocation.addListener(Events.PROVIDERCHANGE, success);
969
- };
970
- BackgroundGeolocation.onActivityChange = function (success) {
971
- return BackgroundGeolocation.addListener(Events.ACTIVITYCHANGE, success);
972
- };
973
- BackgroundGeolocation.onGeofence = function (success) {
974
- return BackgroundGeolocation.addListener(Events.GEOFENCE, success);
975
- };
976
- BackgroundGeolocation.onGeofencesChange = function (success) {
977
- return BackgroundGeolocation.addListener(Events.GEOFENCESCHANGE, success);
978
- };
979
- BackgroundGeolocation.onSchedule = function (success) {
980
- return BackgroundGeolocation.addListener(Events.SCHEDULE, success);
981
- };
982
- BackgroundGeolocation.onEnabledChange = function (success) {
983
- return BackgroundGeolocation.addListener(Events.ENABLEDCHANGE, success);
984
- };
985
- BackgroundGeolocation.onConnectivityChange = function (success) {
986
- return BackgroundGeolocation.addListener(Events.CONNECTIVITYCHANGE, success);
987
- };
988
- BackgroundGeolocation.onPowerSaveChange = function (success) {
989
- return BackgroundGeolocation.addListener(Events.POWERSAVECHANGE, success);
990
- };
991
- BackgroundGeolocation.onNotificationAction = function (success) {
992
- return BackgroundGeolocation.addListener(Events.NOTIFICATIONACTION, success);
993
- };
994
- BackgroundGeolocation.onAuthorization = function (success) {
995
- return BackgroundGeolocation.addListener(Events.AUTHORIZATION, success);
996
- };
997
- ///
998
- /// Listen to a plugin event
999
- ///
1000
- BackgroundGeolocation.addListener = function (event, success, failure) {
1001
- if (!Events[event.toUpperCase()]) {
1002
- throw (TAG + "#addListener - Unknown event '" + event + "'");
7
+ Permission to use, copy, modify, and/or distribute this software for any
8
+ purpose with or without fee is hereby granted.
9
+
10
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
11
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
12
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
13
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
14
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
15
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
16
+ PERFORMANCE OF THIS SOFTWARE.
17
+ ***************************************************************************** */
18
+ /* global Reflect, Promise, SuppressedError, Symbol, Iterator */
19
+
20
+
21
+ function __awaiter(thisArg, _arguments, P, generator) {
22
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
23
+ return new (P || (P = Promise))(function (resolve, reject) {
24
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
25
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
26
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
27
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
28
+ });
29
+ }
30
+
31
+ function __generator(thisArg, body) {
32
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
33
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
34
+ function verb(n) { return function (v) { return step([n, v]); }; }
35
+ function step(op) {
36
+ if (f) throw new TypeError("Generator is already executing.");
37
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
38
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
39
+ if (y = 0, t) op = [op[0] & 2, t.value];
40
+ switch (op[0]) {
41
+ case 0: case 1: t = op; break;
42
+ case 4: _.label++; return { value: op[1], done: false };
43
+ case 5: _.label++; y = op[1]; op = [0]; continue;
44
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
45
+ default:
46
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
47
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
48
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
49
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
50
+ if (t[2]) _.ops.pop();
51
+ _.trys.pop(); continue;
1003
52
  }
1004
- var handler = function (response) {
1005
- if (response.hasOwnProperty("value")) {
1006
- response = response.value;
1007
- }
1008
- if (response.hasOwnProperty("error") && (response.error != null)) {
1009
- if (typeof (failure) === 'function') {
1010
- failure(response.error);
1011
- }
1012
- else {
1013
- success(response);
1014
- }
1015
- }
1016
- else {
1017
- success(response);
1018
- }
1019
- };
1020
- // Create a flag to capture edge-case where the developer subscribes to an event then IMMEDIATELY calls subscription.remove()
1021
- // before NativeModule.addListener has resolved.
1022
- // The developer would have to do something weird like this:
1023
- // const subscription = BackgroundGeolocation.onLocation(this.onLocation);
1024
- // subscription.remove();
1025
- //
1026
- // The reason for this is I don't want developers to have to await calls to BackgroundGeolocation.onXXX(myHandler).
1027
- //
1028
- var isRemoved = false;
1029
- var subscriptionProxy = {
1030
- remove: function () {
1031
- // EmptyFn until NativeModule.addListener resolves and re-writes this function
1032
- isRemoved = true;
1033
- console.warn('[BackgroundGeolocation.addListener] Unexpected call to subscription.remove() on subscriptionProxy. Waiting for NativeModule.addListener to resolve.');
1034
- }
1035
- };
1036
- // Now add the listener and re-write subscriptionProxy.remove.
1037
- NativeModule.addListener(event, handler).then(function (listener) {
1038
- var subscription = new Subscription(event, listener, success);
1039
- EVENT_SUBSCRIPTIONS.push(subscription);
1040
- subscriptionProxy.remove = function () {
1041
- listener.remove();
1042
- // Remove from EVENT_SUBSCRIPTIONS.
1043
- if (EVENT_SUBSCRIPTIONS.indexOf(subscription) >= 0) {
1044
- EVENT_SUBSCRIPTIONS.splice(EVENT_SUBSCRIPTIONS.indexOf(subscription), 1);
1045
- }
1046
- };
1047
- if (isRemoved) {
1048
- // Caught edge-case. Developer added an event-handler then immediately call subscription.remove().
1049
- subscriptionProxy.remove();
1050
- }
1051
- });
1052
- return subscriptionProxy;
1053
- };
1054
- BackgroundGeolocation.removeListener = function (event, callback) {
1055
- console.warn('BackgroundGeolocation.removeListener is deprecated. Event-listener methods (eg: onLocation) now return a Subscription instance. Call subscription.remove() on the returned subscription instead. Eg:\nconst subscription = BackgroundGeolocation.onLocation(myLocationHandler)\n...\nsubscription.remove()');
1056
- return new Promise(function (resolve, reject) {
1057
- var found = null;
1058
- for (var n = 0, len = EVENT_SUBSCRIPTIONS.length; n < len; n++) {
1059
- var sub = EVENT_SUBSCRIPTIONS[n];
1060
- if ((sub.event === event) && (sub.callback === callback)) {
1061
- found = sub;
1062
- break;
1063
- }
1064
- }
1065
- if (found !== null) {
1066
- EVENT_SUBSCRIPTIONS.splice(EVENT_SUBSCRIPTIONS.indexOf(found), 1);
1067
- found.subscription.remove();
1068
- resolve();
1069
- }
1070
- else {
1071
- console.warn(TAG + ' Failed to find listener for event ' + event);
1072
- reject();
1073
- }
1074
- });
1075
- };
1076
- BackgroundGeolocation.removeListeners = function () {
1077
- var _this = this;
1078
- return new Promise(function (resolve) { return __awaiter(_this, undefined, undefined, function () {
1079
- return __generator(this, function (_a) {
1080
- switch (_a.label) {
1081
- case 0:
1082
- EVENT_SUBSCRIPTIONS = [];
1083
- return [4 /*yield*/, NativeModule.removeAllEventListeners()];
1084
- case 1:
1085
- _a.sent();
1086
- resolve();
1087
- return [2 /*return*/];
1088
- }
1089
- });
1090
- }); });
1091
- };
1092
- return BackgroundGeolocation;
1093
- }());
53
+ op = body.call(thisArg, _);
54
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
55
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : undefined, done: true };
56
+ }
57
+ }
58
+
59
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
60
+ var e = new Error(message);
61
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
62
+ };
63
+
64
+ var NativeModule = core.registerPlugin('BackgroundGeolocation');
65
+ /**
66
+ * Logger
67
+ */
68
+ var LOGGER_LOG_LEVEL_DEBUG = "debug";
69
+ var LOGGER_LOG_LEVEL_NOTICE = "notice";
70
+ var LOGGER_LOG_LEVEL_INFO = "info";
71
+ var LOGGER_LOG_LEVEL_WARN = "warn";
72
+ var LOGGER_LOG_LEVEL_ERROR = "error";
73
+ var ORDER_ASC = 1;
74
+ var ORDER_DESC = -1;
75
+ function log(level, msg) {
76
+ return NativeModule.log({
77
+ level: level,
78
+ message: msg
79
+ });
80
+ }
81
+ function validateQuery(query) {
82
+ if (typeof (query) !== 'object')
83
+ return {};
84
+ if (query.hasOwnProperty('start') && isNaN(query.start)) {
85
+ throw new Error('Invalid SQLQuery.start. Expected unix timestamp but received: ' + query.start);
86
+ }
87
+ if (query.hasOwnProperty('end') && isNaN(query.end)) {
88
+ throw new Error('Invalid SQLQuery.end. Expected unix timestamp but received: ' + query.end);
89
+ }
90
+ return query;
91
+ }
92
+ var Logger = /** @class */ (function () {
93
+ function Logger() {
94
+ }
95
+ Object.defineProperty(Logger, "ORDER_ASC", {
96
+ get: function () { return ORDER_ASC; },
97
+ enumerable: false,
98
+ configurable: true
99
+ });
100
+ Object.defineProperty(Logger, "ORDER_DESC", {
101
+ get: function () { return ORDER_DESC; },
102
+ enumerable: false,
103
+ configurable: true
104
+ });
105
+ Logger.debug = function (msg) {
106
+ return log(LOGGER_LOG_LEVEL_DEBUG, msg);
107
+ };
108
+ Logger.error = function (msg) {
109
+ return log(LOGGER_LOG_LEVEL_ERROR, msg);
110
+ };
111
+ Logger.warn = function (msg) {
112
+ return log(LOGGER_LOG_LEVEL_WARN, msg);
113
+ };
114
+ Logger.info = function (msg) {
115
+ return log(LOGGER_LOG_LEVEL_INFO, msg);
116
+ };
117
+ Logger.notice = function (msg) {
118
+ return log(LOGGER_LOG_LEVEL_NOTICE, msg);
119
+ };
120
+ Logger.getLog = function (query) {
121
+ query = validateQuery(query);
122
+ return new Promise(function (resolve, reject) {
123
+ NativeModule.getLog({ options: query }).then(function (result) {
124
+ resolve(result.log);
125
+ }).catch(function (error) {
126
+ reject(error.message);
127
+ });
128
+ });
129
+ };
130
+ Logger.destroyLog = function () {
131
+ return new Promise(function (resolve, reject) {
132
+ NativeModule.destroyLog().then(function () {
133
+ resolve();
134
+ }).catch(function (error) {
135
+ reject(error.message);
136
+ });
137
+ });
138
+ };
139
+ Logger.emailLog = function (email, query) {
140
+ query = validateQuery(query);
141
+ return new Promise(function (resolve, reject) {
142
+ NativeModule.emailLog({ email: email, query: query }).then(function (result) {
143
+ resolve(result);
144
+ }).catch(function (error) {
145
+ reject(error.message);
146
+ });
147
+ });
148
+ };
149
+ Logger.uploadLog = function (url, query) {
150
+ query = validateQuery(query);
151
+ return new Promise(function (resolve, reject) {
152
+ NativeModule.uploadLog({ url: url, query: query }).then(function () {
153
+ resolve();
154
+ }).catch(function (error) {
155
+ reject(error.message);
156
+ });
157
+ });
158
+ };
159
+ return Logger;
160
+ }());
161
+ /**
162
+ * TransistorAuthorizationToken
163
+ */
164
+ var DEFAULT_URL = 'http://tracker.transistorsoft.com';
165
+ var DUMMY_TOKEN = 'DUMMY_TOKEN';
166
+ var REFRESH_PAYLOAD = {
167
+ refresh_token: '{refreshToken}'
168
+ };
169
+ var LOCATIONS_PATH = '/api/locations';
170
+ var REFRESH_TOKEN_PATH = '/api/refresh_token';
171
+ var TransistorAuthorizationToken = /** @class */ (function () {
172
+ function TransistorAuthorizationToken() {
173
+ }
174
+ TransistorAuthorizationToken.findOrCreate = function (orgname, username, url) {
175
+ if (url === undefined) { url = DEFAULT_URL; }
176
+ return new Promise(function (resolve, reject) {
177
+ NativeModule.getTransistorToken({
178
+ org: orgname,
179
+ username: username,
180
+ url: url
181
+ }).then(function (result) {
182
+ if (result.success) {
183
+ var token = result.token;
184
+ token.url = url;
185
+ resolve(token);
186
+ }
187
+ else {
188
+ console.warn('[TransistorAuthorizationToken findOrCreate] ERROR: ', result);
189
+ if (result.status == '403') {
190
+ reject(result);
191
+ return;
192
+ }
193
+ resolve({
194
+ accessToken: DUMMY_TOKEN,
195
+ refreshToken: DUMMY_TOKEN,
196
+ expires: -1,
197
+ url: url
198
+ });
199
+ }
200
+ }).catch(function (error) {
201
+ reject(error);
202
+ });
203
+ });
204
+ };
205
+ TransistorAuthorizationToken.destroy = function (url) {
206
+ if (url === undefined) { url = DEFAULT_URL; }
207
+ return new Promise(function (resolve, reject) {
208
+ NativeModule.destroyTransistorToken({ url: url }).then(function () {
209
+ resolve();
210
+ }).catch(function (error) {
211
+ reject(error.message);
212
+ });
213
+ });
214
+ };
215
+ TransistorAuthorizationToken.applyIf = function (config) {
216
+ if (!config.transistorAuthorizationToken)
217
+ return config;
218
+ var token = config.transistorAuthorizationToken;
219
+ delete config.transistorAuthorizationToken;
220
+ if (!config.http) {
221
+ config.http = {};
222
+ }
223
+ config.http.url = token.url + LOCATIONS_PATH;
224
+ config.authorization = {
225
+ strategy: 'JWT',
226
+ accessToken: token.accessToken,
227
+ refreshToken: token.refreshToken,
228
+ refreshUrl: token.url + REFRESH_TOKEN_PATH,
229
+ refreshPayload: REFRESH_PAYLOAD,
230
+ expires: token.expires
231
+ };
232
+ return config;
233
+ };
234
+ return TransistorAuthorizationToken;
235
+ }());
236
+ /**
237
+ * DeviceSettings
238
+ */
239
+ var IGNORE_BATTERY_OPTIMIZATIONS = "IGNORE_BATTERY_OPTIMIZATIONS";
240
+ var POWER_MANAGER = "POWER_MANAGER";
241
+ var resolveSettingsRequest = function (resolve, request) {
242
+ // lastSeenAt arrives from the native bridge as a unix timestamp (number); convert to Date.
243
+ var lastSeenAt = request.lastSeenAt;
244
+ if (lastSeenAt > 0) {
245
+ request.lastSeenAt = new Date(lastSeenAt);
246
+ }
247
+ resolve(request);
248
+ };
249
+ var DeviceSettings = /** @class */ (function () {
250
+ function DeviceSettings() {
251
+ }
252
+ DeviceSettings.isIgnoringBatteryOptimizations = function () {
253
+ return new Promise(function (resolve, reject) {
254
+ NativeModule.isIgnoringBatteryOptimizations().then(function (result) {
255
+ resolve(result.isIgnoringBatteryOptimizations);
256
+ }).catch(function (error) {
257
+ reject(error.message);
258
+ });
259
+ });
260
+ };
261
+ DeviceSettings.showIgnoreBatteryOptimizations = function () {
262
+ return new Promise(function (resolve, reject) {
263
+ var args = { action: IGNORE_BATTERY_OPTIMIZATIONS };
264
+ NativeModule.requestSettings(args).then(function (result) {
265
+ resolveSettingsRequest(resolve, result);
266
+ }).catch(function (error) {
267
+ reject(error.message);
268
+ });
269
+ });
270
+ };
271
+ DeviceSettings.showPowerManager = function () {
272
+ return new Promise(function (resolve, reject) {
273
+ var args = { action: POWER_MANAGER };
274
+ NativeModule.requestSettings(args).then(function (result) {
275
+ resolveSettingsRequest(resolve, result);
276
+ }).catch(function (error) {
277
+ reject(error.message);
278
+ });
279
+ });
280
+ };
281
+ DeviceSettings.show = function (request) {
282
+ return new Promise(function (resolve, reject) {
283
+ var args = { action: request.action };
284
+ NativeModule.showSettings(args).then(function () {
285
+ resolve();
286
+ }).catch(function (error) {
287
+ reject(error.message);
288
+ });
289
+ });
290
+ };
291
+ return DeviceSettings;
292
+ }());
293
+ var TAG = "TSLocationManager";
294
+ /// Container for event-subscriptions.
295
+ var EVENT_SUBSCRIPTIONS = [];
296
+ /// Container for watchPosition subscriptions, keyed by watchId.
297
+ var WATCH_POSITION_SUBSCRIPTIONS = new Map();
298
+ /// Event handler Subscription
299
+ ///
300
+ var Subscription = /** @class */ (function () {
301
+ function Subscription(event, subscription, callback) {
302
+ this.event = event;
303
+ this.subscription = subscription;
304
+ this.callback = callback;
305
+ }
306
+ return Subscription;
307
+ }());
308
+ var LOG_LEVEL_OFF = backgroundGeolocationTypes.LogLevel.Off;
309
+ var LOG_LEVEL_ERROR = backgroundGeolocationTypes.LogLevel.Error;
310
+ var LOG_LEVEL_WARNING = backgroundGeolocationTypes.LogLevel.Warning;
311
+ var LOG_LEVEL_INFO = backgroundGeolocationTypes.LogLevel.Info;
312
+ var LOG_LEVEL_DEBUG = backgroundGeolocationTypes.LogLevel.Debug;
313
+ var LOG_LEVEL_VERBOSE = backgroundGeolocationTypes.LogLevel.Verbose;
314
+ var DESIRED_ACCURACY_NAVIGATION = backgroundGeolocationTypes.DesiredAccuracy.Navigation;
315
+ var DESIRED_ACCURACY_HIGH = backgroundGeolocationTypes.DesiredAccuracy.High;
316
+ var DESIRED_ACCURACY_MEDIUM = backgroundGeolocationTypes.DesiredAccuracy.Medium;
317
+ var DESIRED_ACCURACY_LOW = backgroundGeolocationTypes.DesiredAccuracy.Low;
318
+ var DESIRED_ACCURACY_VERY_LOW = backgroundGeolocationTypes.DesiredAccuracy.VeryLow;
319
+ var DESIRED_ACCURACY_LOWEST = backgroundGeolocationTypes.DesiredAccuracy.Lowest;
320
+ var AUTHORIZATION_STATUS_NOT_DETERMINED = backgroundGeolocationTypes.AuthorizationStatus.NotDetermined;
321
+ var AUTHORIZATION_STATUS_RESTRICTED = backgroundGeolocationTypes.AuthorizationStatus.Restricted;
322
+ var AUTHORIZATION_STATUS_DENIED = backgroundGeolocationTypes.AuthorizationStatus.Denied;
323
+ var AUTHORIZATION_STATUS_ALWAYS = backgroundGeolocationTypes.AuthorizationStatus.Always;
324
+ var AUTHORIZATION_STATUS_WHEN_IN_USE = backgroundGeolocationTypes.AuthorizationStatus.WhenInUse;
325
+ var NOTIFICATION_PRIORITY_DEFAULT = backgroundGeolocationTypes.NotificationPriority.Default;
326
+ var NOTIFICATION_PRIORITY_HIGH = backgroundGeolocationTypes.NotificationPriority.High;
327
+ var NOTIFICATION_PRIORITY_LOW = backgroundGeolocationTypes.NotificationPriority.Low;
328
+ var NOTIFICATION_PRIORITY_MAX = backgroundGeolocationTypes.NotificationPriority.Max;
329
+ var NOTIFICATION_PRIORITY_MIN = backgroundGeolocationTypes.NotificationPriority.Min;
330
+ var ACTIVITY_TYPE_OTHER = backgroundGeolocationTypes.ActivityType.Other;
331
+ var ACTIVITY_TYPE_AUTOMOTIVE_NAVIGATION = backgroundGeolocationTypes.ActivityType.AutomotiveNavigation;
332
+ var ACTIVITY_TYPE_FITNESS = backgroundGeolocationTypes.ActivityType.Fitness;
333
+ var ACTIVITY_TYPE_OTHER_NAVIGATION = backgroundGeolocationTypes.ActivityType.OtherNavigation;
334
+ var ACTIVITY_TYPE_AIRBORNE = backgroundGeolocationTypes.ActivityType.Airborne;
335
+ var LOCATION_AUTHORIZATION_ALWAYS = backgroundGeolocationTypes.LocationRequest.Always;
336
+ var LOCATION_AUTHORIZATION_WHEN_IN_USE = backgroundGeolocationTypes.LocationRequest.WhenInUse;
337
+ var LOCATION_AUTHORIZATION_ANY = backgroundGeolocationTypes.LocationRequest.Any;
338
+ var PERSIST_MODE_ALL = backgroundGeolocationTypes.PersistMode.All;
339
+ var PERSIST_MODE_LOCATION = backgroundGeolocationTypes.PersistMode.Location;
340
+ var PERSIST_MODE_GEOFENCE = backgroundGeolocationTypes.PersistMode.Geofence;
341
+ var PERSIST_MODE_NONE = backgroundGeolocationTypes.PersistMode.None;
342
+ var ACCURACY_AUTHORIZATION_FULL = backgroundGeolocationTypes.AccuracyAuthorization.Full;
343
+ var ACCURACY_AUTHORIZATION_REDUCED = backgroundGeolocationTypes.AccuracyAuthorization.Reduced;
344
+ /// BackgroundGeolocation JS API
345
+ var BackgroundGeolocation = /** @class */ (function () {
346
+ function BackgroundGeolocation() {
347
+ }
348
+ Object.defineProperty(BackgroundGeolocation, "LogLevel", {
349
+ get: function () { return backgroundGeolocationTypes.LogLevel; },
350
+ enumerable: false,
351
+ configurable: true
352
+ });
353
+ Object.defineProperty(BackgroundGeolocation, "DesiredAccuracy", {
354
+ get: function () { return backgroundGeolocationTypes.DesiredAccuracy; },
355
+ enumerable: false,
356
+ configurable: true
357
+ });
358
+ Object.defineProperty(BackgroundGeolocation, "PersistMode", {
359
+ get: function () { return backgroundGeolocationTypes.PersistMode; },
360
+ enumerable: false,
361
+ configurable: true
362
+ });
363
+ Object.defineProperty(BackgroundGeolocation, "AuthorizationStatus", {
364
+ get: function () { return backgroundGeolocationTypes.AuthorizationStatus; },
365
+ enumerable: false,
366
+ configurable: true
367
+ });
368
+ Object.defineProperty(BackgroundGeolocation, "AccuracyAuthorization", {
369
+ get: function () { return backgroundGeolocationTypes.AccuracyAuthorization; },
370
+ enumerable: false,
371
+ configurable: true
372
+ });
373
+ Object.defineProperty(BackgroundGeolocation, "AuthorizationStrategy", {
374
+ get: function () { return backgroundGeolocationTypes.AuthorizationStrategy; },
375
+ enumerable: false,
376
+ configurable: true
377
+ });
378
+ Object.defineProperty(BackgroundGeolocation, "LocationFilterPolicy", {
379
+ get: function () { return backgroundGeolocationTypes.LocationFilterPolicy; },
380
+ enumerable: false,
381
+ configurable: true
382
+ });
383
+ Object.defineProperty(BackgroundGeolocation, "KalmanProfile", {
384
+ get: function () { return backgroundGeolocationTypes.KalmanProfile; },
385
+ enumerable: false,
386
+ configurable: true
387
+ });
388
+ Object.defineProperty(BackgroundGeolocation, "HttpMethod", {
389
+ get: function () { return backgroundGeolocationTypes.HttpMethod; },
390
+ enumerable: false,
391
+ configurable: true
392
+ });
393
+ Object.defineProperty(BackgroundGeolocation, "TriggerActivity", {
394
+ get: function () { return backgroundGeolocationTypes.TriggerActivity; },
395
+ enumerable: false,
396
+ configurable: true
397
+ });
398
+ Object.defineProperty(BackgroundGeolocation, "EVENT_BOOT", {
399
+ /// Events
400
+ get: function () { return backgroundGeolocationTypes.Event.Boot; },
401
+ enumerable: false,
402
+ configurable: true
403
+ });
404
+ Object.defineProperty(BackgroundGeolocation, "EVENT_TERMINATE", {
405
+ get: function () { return backgroundGeolocationTypes.Event.Terminate; },
406
+ enumerable: false,
407
+ configurable: true
408
+ });
409
+ Object.defineProperty(BackgroundGeolocation, "EVENT_LOCATION", {
410
+ get: function () { return backgroundGeolocationTypes.Event.Location; },
411
+ enumerable: false,
412
+ configurable: true
413
+ });
414
+ Object.defineProperty(BackgroundGeolocation, "EVENT_MOTIONCHANGE", {
415
+ get: function () { return backgroundGeolocationTypes.Event.MotionChange; },
416
+ enumerable: false,
417
+ configurable: true
418
+ });
419
+ Object.defineProperty(BackgroundGeolocation, "EVENT_HTTP", {
420
+ get: function () { return backgroundGeolocationTypes.Event.Http; },
421
+ enumerable: false,
422
+ configurable: true
423
+ });
424
+ Object.defineProperty(BackgroundGeolocation, "EVENT_HEARTBEAT", {
425
+ get: function () { return backgroundGeolocationTypes.Event.Heartbeat; },
426
+ enumerable: false,
427
+ configurable: true
428
+ });
429
+ Object.defineProperty(BackgroundGeolocation, "EVENT_PROVIDERCHANGE", {
430
+ get: function () { return backgroundGeolocationTypes.Event.ProviderChange; },
431
+ enumerable: false,
432
+ configurable: true
433
+ });
434
+ Object.defineProperty(BackgroundGeolocation, "EVENT_ACTIVITYCHANGE", {
435
+ get: function () { return backgroundGeolocationTypes.Event.ActivityChange; },
436
+ enumerable: false,
437
+ configurable: true
438
+ });
439
+ Object.defineProperty(BackgroundGeolocation, "EVENT_GEOFENCE", {
440
+ get: function () { return backgroundGeolocationTypes.Event.Geofence; },
441
+ enumerable: false,
442
+ configurable: true
443
+ });
444
+ Object.defineProperty(BackgroundGeolocation, "EVENT_GEOFENCESCHANGE", {
445
+ get: function () { return backgroundGeolocationTypes.Event.GeofencesChange; },
446
+ enumerable: false,
447
+ configurable: true
448
+ });
449
+ Object.defineProperty(BackgroundGeolocation, "EVENT_ENABLEDCHANGE", {
450
+ get: function () { return backgroundGeolocationTypes.Event.EnabledChange; },
451
+ enumerable: false,
452
+ configurable: true
453
+ });
454
+ Object.defineProperty(BackgroundGeolocation, "EVENT_CONNECTIVITYCHANGE", {
455
+ get: function () { return backgroundGeolocationTypes.Event.ConnectivityChange; },
456
+ enumerable: false,
457
+ configurable: true
458
+ });
459
+ Object.defineProperty(BackgroundGeolocation, "EVENT_SCHEDULE", {
460
+ get: function () { return backgroundGeolocationTypes.Event.Schedule; },
461
+ enumerable: false,
462
+ configurable: true
463
+ });
464
+ Object.defineProperty(BackgroundGeolocation, "EVENT_POWERSAVECHANGE", {
465
+ get: function () { return backgroundGeolocationTypes.Event.PowerSaveChange; },
466
+ enumerable: false,
467
+ configurable: true
468
+ });
469
+ Object.defineProperty(BackgroundGeolocation, "EVENT_NOTIFICATIONACTION", {
470
+ get: function () { return "notificationaction"; } // <-- TODO : Add to background-geolocation-types
471
+ ,
472
+ enumerable: false,
473
+ configurable: true
474
+ });
475
+ Object.defineProperty(BackgroundGeolocation, "EVENT_AUTHORIZATION", {
476
+ get: function () { return backgroundGeolocationTypes.Event.Authorization; },
477
+ enumerable: false,
478
+ configurable: true
479
+ });
480
+ Object.defineProperty(BackgroundGeolocation, "LOG_LEVEL_OFF", {
481
+ get: function () { return LOG_LEVEL_OFF; },
482
+ enumerable: false,
483
+ configurable: true
484
+ });
485
+ Object.defineProperty(BackgroundGeolocation, "LOG_LEVEL_ERROR", {
486
+ get: function () { return LOG_LEVEL_ERROR; },
487
+ enumerable: false,
488
+ configurable: true
489
+ });
490
+ Object.defineProperty(BackgroundGeolocation, "LOG_LEVEL_WARNING", {
491
+ get: function () { return LOG_LEVEL_WARNING; },
492
+ enumerable: false,
493
+ configurable: true
494
+ });
495
+ Object.defineProperty(BackgroundGeolocation, "LOG_LEVEL_INFO", {
496
+ get: function () { return LOG_LEVEL_INFO; },
497
+ enumerable: false,
498
+ configurable: true
499
+ });
500
+ Object.defineProperty(BackgroundGeolocation, "LOG_LEVEL_DEBUG", {
501
+ get: function () { return LOG_LEVEL_DEBUG; },
502
+ enumerable: false,
503
+ configurable: true
504
+ });
505
+ Object.defineProperty(BackgroundGeolocation, "LOG_LEVEL_VERBOSE", {
506
+ get: function () { return LOG_LEVEL_VERBOSE; },
507
+ enumerable: false,
508
+ configurable: true
509
+ });
510
+ Object.defineProperty(BackgroundGeolocation, "ACTIVITY_TYPE_OTHER", {
511
+ get: function () { return ACTIVITY_TYPE_OTHER; },
512
+ enumerable: false,
513
+ configurable: true
514
+ });
515
+ Object.defineProperty(BackgroundGeolocation, "ACTIVITY_TYPE_AUTOMOTIVE_NAVIGATION", {
516
+ get: function () { return ACTIVITY_TYPE_AUTOMOTIVE_NAVIGATION; },
517
+ enumerable: false,
518
+ configurable: true
519
+ });
520
+ Object.defineProperty(BackgroundGeolocation, "ACTIVITY_TYPE_FITNESS", {
521
+ get: function () { return ACTIVITY_TYPE_FITNESS; },
522
+ enumerable: false,
523
+ configurable: true
524
+ });
525
+ Object.defineProperty(BackgroundGeolocation, "ACTIVITY_TYPE_OTHER_NAVIGATION", {
526
+ get: function () { return ACTIVITY_TYPE_OTHER_NAVIGATION; },
527
+ enumerable: false,
528
+ configurable: true
529
+ });
530
+ Object.defineProperty(BackgroundGeolocation, "ACTIVITY_TYPE_AIRBORNE", {
531
+ get: function () { return ACTIVITY_TYPE_AIRBORNE; },
532
+ enumerable: false,
533
+ configurable: true
534
+ });
535
+ Object.defineProperty(BackgroundGeolocation, "DESIRED_ACCURACY_NAVIGATION", {
536
+ get: function () { return DESIRED_ACCURACY_NAVIGATION; },
537
+ enumerable: false,
538
+ configurable: true
539
+ });
540
+ Object.defineProperty(BackgroundGeolocation, "DESIRED_ACCURACY_HIGH", {
541
+ get: function () { return DESIRED_ACCURACY_HIGH; },
542
+ enumerable: false,
543
+ configurable: true
544
+ });
545
+ Object.defineProperty(BackgroundGeolocation, "DESIRED_ACCURACY_MEDIUM", {
546
+ get: function () { return DESIRED_ACCURACY_MEDIUM; },
547
+ enumerable: false,
548
+ configurable: true
549
+ });
550
+ Object.defineProperty(BackgroundGeolocation, "DESIRED_ACCURACY_LOW", {
551
+ get: function () { return DESIRED_ACCURACY_LOW; },
552
+ enumerable: false,
553
+ configurable: true
554
+ });
555
+ Object.defineProperty(BackgroundGeolocation, "DESIRED_ACCURACY_VERY_LOW", {
556
+ get: function () { return DESIRED_ACCURACY_VERY_LOW; },
557
+ enumerable: false,
558
+ configurable: true
559
+ });
560
+ Object.defineProperty(BackgroundGeolocation, "DESIRED_ACCURACY_LOWEST", {
561
+ get: function () { return DESIRED_ACCURACY_LOWEST; },
562
+ enumerable: false,
563
+ configurable: true
564
+ });
565
+ Object.defineProperty(BackgroundGeolocation, "AUTHORIZATION_STATUS_NOT_DETERMINED", {
566
+ get: function () { return AUTHORIZATION_STATUS_NOT_DETERMINED; },
567
+ enumerable: false,
568
+ configurable: true
569
+ });
570
+ Object.defineProperty(BackgroundGeolocation, "AUTHORIZATION_STATUS_RESTRICTED", {
571
+ get: function () { return AUTHORIZATION_STATUS_RESTRICTED; },
572
+ enumerable: false,
573
+ configurable: true
574
+ });
575
+ Object.defineProperty(BackgroundGeolocation, "AUTHORIZATION_STATUS_DENIED", {
576
+ get: function () { return AUTHORIZATION_STATUS_DENIED; },
577
+ enumerable: false,
578
+ configurable: true
579
+ });
580
+ Object.defineProperty(BackgroundGeolocation, "AUTHORIZATION_STATUS_ALWAYS", {
581
+ get: function () { return AUTHORIZATION_STATUS_ALWAYS; },
582
+ enumerable: false,
583
+ configurable: true
584
+ });
585
+ Object.defineProperty(BackgroundGeolocation, "AUTHORIZATION_STATUS_WHEN_IN_USE", {
586
+ get: function () { return AUTHORIZATION_STATUS_WHEN_IN_USE; },
587
+ enumerable: false,
588
+ configurable: true
589
+ });
590
+ Object.defineProperty(BackgroundGeolocation, "NOTIFICATION_PRIORITY_DEFAULT", {
591
+ get: function () { return NOTIFICATION_PRIORITY_DEFAULT; },
592
+ enumerable: false,
593
+ configurable: true
594
+ });
595
+ Object.defineProperty(BackgroundGeolocation, "NOTIFICATION_PRIORITY_HIGH", {
596
+ get: function () { return NOTIFICATION_PRIORITY_HIGH; },
597
+ enumerable: false,
598
+ configurable: true
599
+ });
600
+ Object.defineProperty(BackgroundGeolocation, "NOTIFICATION_PRIORITY_LOW", {
601
+ get: function () { return NOTIFICATION_PRIORITY_LOW; },
602
+ enumerable: false,
603
+ configurable: true
604
+ });
605
+ Object.defineProperty(BackgroundGeolocation, "NOTIFICATION_PRIORITY_MAX", {
606
+ get: function () { return NOTIFICATION_PRIORITY_MAX; },
607
+ enumerable: false,
608
+ configurable: true
609
+ });
610
+ Object.defineProperty(BackgroundGeolocation, "NOTIFICATION_PRIORITY_MIN", {
611
+ get: function () { return NOTIFICATION_PRIORITY_MIN; },
612
+ enumerable: false,
613
+ configurable: true
614
+ });
615
+ Object.defineProperty(BackgroundGeolocation, "LOCATION_AUTHORIZATION_ALWAYS", {
616
+ get: function () { return LOCATION_AUTHORIZATION_ALWAYS; },
617
+ enumerable: false,
618
+ configurable: true
619
+ });
620
+ Object.defineProperty(BackgroundGeolocation, "LOCATION_AUTHORIZATION_WHEN_IN_USE", {
621
+ get: function () { return LOCATION_AUTHORIZATION_WHEN_IN_USE; },
622
+ enumerable: false,
623
+ configurable: true
624
+ });
625
+ Object.defineProperty(BackgroundGeolocation, "LOCATION_AUTHORIZATION_ANY", {
626
+ get: function () { return LOCATION_AUTHORIZATION_ANY; },
627
+ enumerable: false,
628
+ configurable: true
629
+ });
630
+ Object.defineProperty(BackgroundGeolocation, "PERSIST_MODE_ALL", {
631
+ get: function () { return PERSIST_MODE_ALL; },
632
+ enumerable: false,
633
+ configurable: true
634
+ });
635
+ Object.defineProperty(BackgroundGeolocation, "PERSIST_MODE_LOCATION", {
636
+ get: function () { return PERSIST_MODE_LOCATION; },
637
+ enumerable: false,
638
+ configurable: true
639
+ });
640
+ Object.defineProperty(BackgroundGeolocation, "PERSIST_MODE_GEOFENCE", {
641
+ get: function () { return PERSIST_MODE_GEOFENCE; },
642
+ enumerable: false,
643
+ configurable: true
644
+ });
645
+ Object.defineProperty(BackgroundGeolocation, "PERSIST_MODE_NONE", {
646
+ get: function () { return PERSIST_MODE_NONE; },
647
+ enumerable: false,
648
+ configurable: true
649
+ });
650
+ Object.defineProperty(BackgroundGeolocation, "ACCURACY_AUTHORIZATION_FULL", {
651
+ get: function () { return ACCURACY_AUTHORIZATION_FULL; },
652
+ enumerable: false,
653
+ configurable: true
654
+ });
655
+ Object.defineProperty(BackgroundGeolocation, "ACCURACY_AUTHORIZATION_REDUCED", {
656
+ get: function () { return ACCURACY_AUTHORIZATION_REDUCED; },
657
+ enumerable: false,
658
+ configurable: true
659
+ });
660
+ Object.defineProperty(BackgroundGeolocation, "logger", {
661
+ get: function () { return Logger; },
662
+ enumerable: false,
663
+ configurable: true
664
+ });
665
+ Object.defineProperty(BackgroundGeolocation, "deviceSettings", {
666
+ get: function () { return DeviceSettings; },
667
+ enumerable: false,
668
+ configurable: true
669
+ });
670
+ BackgroundGeolocation.ready = function (config) {
671
+ return NativeModule.ready({ options: config });
672
+ };
673
+ BackgroundGeolocation.reset = function (config) {
674
+ return NativeModule.reset({ options: config });
675
+ };
676
+ BackgroundGeolocation.start = function () {
677
+ return NativeModule.start();
678
+ };
679
+ BackgroundGeolocation.stop = function () {
680
+ return NativeModule.stop();
681
+ };
682
+ BackgroundGeolocation.startSchedule = function () {
683
+ return NativeModule.startSchedule();
684
+ };
685
+ BackgroundGeolocation.stopSchedule = function () {
686
+ return NativeModule.stopSchedule();
687
+ };
688
+ BackgroundGeolocation.startGeofences = function () {
689
+ return NativeModule.startGeofences();
690
+ };
691
+ BackgroundGeolocation.setConfig = function (config) {
692
+ return NativeModule.setConfig({ options: config });
693
+ };
694
+ BackgroundGeolocation.getState = function () {
695
+ return NativeModule.getState();
696
+ };
697
+ BackgroundGeolocation.changePace = function (isMoving) {
698
+ return new Promise(function (resolve, reject) {
699
+ NativeModule.changePace({ isMoving: isMoving }).then(function () {
700
+ resolve();
701
+ }).catch(function (error) {
702
+ reject(error.errorMessage);
703
+ });
704
+ });
705
+ };
706
+ BackgroundGeolocation.getCurrentPosition = function (options) {
707
+ options = options || {};
708
+ return new Promise(function (resolve, reject) {
709
+ NativeModule.getCurrentPosition({ options: options }).then(function (result) {
710
+ resolve(result);
711
+ }).catch(function (error) {
712
+ reject(error.code);
713
+ });
714
+ });
715
+ };
716
+ BackgroundGeolocation.watchPosition = function (options, onLocation, onError) {
717
+ options = options || {};
718
+ var isRemoved = false;
719
+ var nativeWatchId = null;
720
+ var subscriptionProxy = {
721
+ remove: function () {
722
+ isRemoved = true;
723
+ if (nativeWatchId !== null) {
724
+ var listener = WATCH_POSITION_SUBSCRIPTIONS.get(nativeWatchId);
725
+ if (listener) {
726
+ listener.remove();
727
+ WATCH_POSITION_SUBSCRIPTIONS.delete(nativeWatchId);
728
+ }
729
+ NativeModule.stopWatchPosition({ watchId: nativeWatchId });
730
+ nativeWatchId = null;
731
+ }
732
+ }
733
+ };
734
+ var handler = function (response) {
735
+ if (response.hasOwnProperty("error") && (response.error != null)) {
736
+ if (typeof (onError) === 'function') {
737
+ onError(response.error.code);
738
+ }
739
+ else {
740
+ console.warn('[BackgroundGeolocation watchPosition] DEFAULT ERROR HANDLER. Provide an onError callback to watchPosition to receive this message: ', response.error);
741
+ }
742
+ }
743
+ else {
744
+ onLocation(response);
745
+ }
746
+ };
747
+ NativeModule.addListener("watchposition", handler).then(function (listener) {
748
+ NativeModule.watchPosition({ options: options }).then(function (result) {
749
+ nativeWatchId = result.watchId;
750
+ if (isRemoved) {
751
+ // remove() was called before the native async call resolved — honour it now.
752
+ listener.remove();
753
+ NativeModule.stopWatchPosition({ watchId: nativeWatchId });
754
+ }
755
+ else {
756
+ WATCH_POSITION_SUBSCRIPTIONS.set(nativeWatchId, listener);
757
+ }
758
+ }).catch(function () {
759
+ listener.remove();
760
+ });
761
+ });
762
+ return subscriptionProxy;
763
+ };
764
+ BackgroundGeolocation.stopWatchPosition = function (watchId) {
765
+ if (watchId !== undefined) {
766
+ var listener = WATCH_POSITION_SUBSCRIPTIONS.get(watchId);
767
+ if (listener) {
768
+ listener.remove();
769
+ WATCH_POSITION_SUBSCRIPTIONS.delete(watchId);
770
+ }
771
+ NativeModule.stopWatchPosition({ watchId: watchId });
772
+ }
773
+ };
774
+ BackgroundGeolocation.requestPermission = function () {
775
+ return new Promise(function (resolve, reject) {
776
+ NativeModule.requestPermission().then(function (result) {
777
+ if (result.success) {
778
+ resolve(result.status);
779
+ }
780
+ else {
781
+ reject(result.status);
782
+ }
783
+ });
784
+ });
785
+ };
786
+ BackgroundGeolocation.requestTemporaryFullAccuracy = function (purpose) {
787
+ return new Promise(function (resolve, reject) {
788
+ NativeModule.requestTemporaryFullAccuracy({ purpose: purpose }).then(function (result) {
789
+ resolve(result.accuracyAuthorization);
790
+ }).catch(function (error) {
791
+ reject(error.message);
792
+ });
793
+ });
794
+ };
795
+ BackgroundGeolocation.getProviderState = function () {
796
+ return NativeModule.getProviderState();
797
+ };
798
+ /// Locations database
799
+ ///
800
+ BackgroundGeolocation.getLocations = function () {
801
+ return new Promise(function (resolve, reject) {
802
+ NativeModule.getLocations().then(function (result) {
803
+ resolve(result.locations);
804
+ }).catch(function (error) {
805
+ reject(error.message);
806
+ });
807
+ });
808
+ };
809
+ BackgroundGeolocation.insertLocation = function (params) {
810
+ return new Promise(function (resolve, reject) {
811
+ NativeModule.insertLocation({ options: params }).then(function (result) {
812
+ resolve(result.uuid);
813
+ }).catch(function (error) {
814
+ reject(error.message);
815
+ });
816
+ });
817
+ };
818
+ BackgroundGeolocation.destroyLocations = function () {
819
+ return new Promise(function (resolve, reject) {
820
+ NativeModule.destroyLocations().then(function () {
821
+ resolve();
822
+ }).catch(function (error) {
823
+ reject(error.message);
824
+ });
825
+ });
826
+ };
827
+ BackgroundGeolocation.destroyLocation = function (uuid) {
828
+ return new Promise(function (resolve, reject) {
829
+ NativeModule.destroyLocation({ uuid: uuid }).then(function () {
830
+ resolve();
831
+ }).catch(function (error) {
832
+ reject(error.message);
833
+ });
834
+ });
835
+ };
836
+ BackgroundGeolocation.getCount = function () {
837
+ return new Promise(function (resolve, reject) {
838
+ NativeModule.getCount().then(function (result) {
839
+ resolve(result.count);
840
+ }).catch(function (error) {
841
+ reject(error.message);
842
+ });
843
+ });
844
+ };
845
+ BackgroundGeolocation.sync = function () {
846
+ return new Promise(function (resolve, reject) {
847
+ NativeModule.sync().then(function (result) {
848
+ resolve(result.locations);
849
+ }).catch(function (error) {
850
+ reject(error.message);
851
+ });
852
+ });
853
+ };
854
+ /// Geofencing
855
+ ///
856
+ BackgroundGeolocation.addGeofence = function (params) {
857
+ return new Promise(function (resolve, reject) {
858
+ NativeModule.addGeofence({ options: params }).then(function () {
859
+ resolve();
860
+ }).catch(function (error) {
861
+ reject(error.message);
862
+ });
863
+ });
864
+ };
865
+ BackgroundGeolocation.addGeofences = function (params) {
866
+ return new Promise(function (resolve, reject) {
867
+ NativeModule.addGeofences({ options: params }).then(function () {
868
+ resolve();
869
+ }).catch(function (error) {
870
+ reject(error.message);
871
+ });
872
+ });
873
+ };
874
+ BackgroundGeolocation.getGeofences = function () {
875
+ return new Promise(function (resolve, reject) {
876
+ NativeModule.getGeofences().then(function (result) {
877
+ resolve(result.geofences);
878
+ }).catch(function (error) {
879
+ reject(error.message);
880
+ });
881
+ });
882
+ };
883
+ BackgroundGeolocation.getGeofence = function (identifier) {
884
+ return new Promise(function (resolve, reject) {
885
+ if (identifier === null) {
886
+ reject('identifier is null');
887
+ return;
888
+ }
889
+ NativeModule.getGeofence({ identifier: identifier }).then(function (result) {
890
+ resolve(result);
891
+ }).catch(function (error) {
892
+ reject(error.message);
893
+ });
894
+ });
895
+ };
896
+ BackgroundGeolocation.geofenceExists = function (identifier) {
897
+ return new Promise(function (resolve, reject) {
898
+ if (identifier === null) {
899
+ reject('identifier is null');
900
+ return;
901
+ }
902
+ NativeModule.geofenceExists({ identifier: identifier }).then(function (result) {
903
+ resolve(result.exists);
904
+ }).catch(function (error) {
905
+ reject(error.message);
906
+ });
907
+ });
908
+ };
909
+ BackgroundGeolocation.removeGeofence = function (identifier) {
910
+ return new Promise(function (resolve, reject) {
911
+ if (identifier === null) {
912
+ reject('identifier is null');
913
+ return;
914
+ }
915
+ NativeModule.removeGeofence({ identifier: identifier }).then(function () {
916
+ resolve();
917
+ }).catch(function (error) {
918
+ reject(error.message);
919
+ });
920
+ });
921
+ };
922
+ BackgroundGeolocation.removeGeofences = function (identifiers) {
923
+ identifiers = identifiers || [];
924
+ return new Promise(function (resolve, reject) {
925
+ NativeModule.removeGeofences({ identifiers: identifiers }).then(function () {
926
+ resolve();
927
+ }).catch(function (error) {
928
+ reject(error.message);
929
+ });
930
+ });
931
+ };
932
+ /// Odometer
933
+ ///
934
+ BackgroundGeolocation.getOdometer = function () {
935
+ return new Promise(function (resolve, reject) {
936
+ NativeModule.getOdometer().then(function (result) {
937
+ resolve(result.odometer);
938
+ }).catch(function (error) {
939
+ reject(error.message);
940
+ });
941
+ });
942
+ };
943
+ BackgroundGeolocation.setOdometer = function (value) {
944
+ return new Promise(function (resolve, reject) {
945
+ NativeModule.setOdometer({ "odometer": value }).then(function (result) {
946
+ resolve(result);
947
+ }).catch(function (error) {
948
+ reject(error.message);
949
+ });
950
+ });
951
+ };
952
+ BackgroundGeolocation.resetOdometer = function () {
953
+ return BackgroundGeolocation.setOdometer(0);
954
+ };
955
+ /// Background Tasks
956
+ ///
957
+ BackgroundGeolocation.startBackgroundTask = function () {
958
+ return new Promise(function (resolve, reject) {
959
+ NativeModule.startBackgroundTask().then(function (result) {
960
+ resolve(result.taskId);
961
+ }).catch(function (error) {
962
+ reject(error.message);
963
+ });
964
+ });
965
+ };
966
+ BackgroundGeolocation.stopBackgroundTask = function (taskId) {
967
+ return new Promise(function (resolve, reject) {
968
+ NativeModule.stopBackgroundTask({ taskId: taskId }).then(function () {
969
+ resolve();
970
+ }).catch(function (error) {
971
+ reject(error.message);
972
+ });
973
+ });
974
+ };
975
+ /// @alias stopBackgroundTask
976
+ BackgroundGeolocation.finish = function (taskId) {
977
+ return BackgroundGeolocation.stopBackgroundTask(taskId);
978
+ };
979
+ BackgroundGeolocation.getDeviceInfo = function () {
980
+ return NativeModule.getDeviceInfo();
981
+ };
982
+ BackgroundGeolocation.playSound = function (soundId) {
983
+ return NativeModule.playSound({ soundId: soundId });
984
+ };
985
+ BackgroundGeolocation.isPowerSaveMode = function () {
986
+ return new Promise(function (resolve, reject) {
987
+ NativeModule.isPowerSaveMode().then(function (result) {
988
+ resolve(result.isPowerSaveMode);
989
+ }).catch(function (error) {
990
+ reject(error.message);
991
+ });
992
+ });
993
+ };
994
+ BackgroundGeolocation.getSensors = function () {
995
+ return NativeModule.getSensors();
996
+ };
997
+ /// TransistorAuthorizationToken
998
+ ///
999
+ BackgroundGeolocation.findOrCreateTransistorAuthorizationToken = function (orgname, username, url) {
1000
+ return TransistorAuthorizationToken.findOrCreate(orgname, username, url);
1001
+ };
1002
+ BackgroundGeolocation.destroyTransistorAuthorizationToken = function (url) {
1003
+ return TransistorAuthorizationToken.destroy(url);
1004
+ };
1005
+ /// Event Handling
1006
+ ///
1007
+ BackgroundGeolocation.onLocation = function (cb, onError) {
1008
+ return BackgroundGeolocation.addListener(backgroundGeolocationTypes.Event.Location, cb, onError);
1009
+ };
1010
+ BackgroundGeolocation.onMotionChange = function (cb) {
1011
+ return BackgroundGeolocation.addListener(backgroundGeolocationTypes.Event.MotionChange, cb);
1012
+ };
1013
+ BackgroundGeolocation.onHttp = function (cb) {
1014
+ return BackgroundGeolocation.addListener(backgroundGeolocationTypes.Event.Http, cb);
1015
+ };
1016
+ BackgroundGeolocation.onHeartbeat = function (cb) {
1017
+ return BackgroundGeolocation.addListener(backgroundGeolocationTypes.Event.Heartbeat, cb);
1018
+ };
1019
+ BackgroundGeolocation.onProviderChange = function (cb) {
1020
+ return BackgroundGeolocation.addListener(backgroundGeolocationTypes.Event.ProviderChange, cb);
1021
+ };
1022
+ BackgroundGeolocation.onActivityChange = function (cb) {
1023
+ return BackgroundGeolocation.addListener(backgroundGeolocationTypes.Event.ActivityChange, cb);
1024
+ };
1025
+ BackgroundGeolocation.onGeofence = function (cb) {
1026
+ return BackgroundGeolocation.addListener(backgroundGeolocationTypes.Event.Geofence, cb);
1027
+ };
1028
+ BackgroundGeolocation.onGeofencesChange = function (cb) {
1029
+ return BackgroundGeolocation.addListener(backgroundGeolocationTypes.Event.GeofencesChange, cb);
1030
+ };
1031
+ BackgroundGeolocation.onSchedule = function (cb) {
1032
+ return BackgroundGeolocation.addListener(backgroundGeolocationTypes.Event.Schedule, cb);
1033
+ };
1034
+ BackgroundGeolocation.onEnabledChange = function (cb) {
1035
+ return BackgroundGeolocation.addListener(backgroundGeolocationTypes.Event.EnabledChange, cb);
1036
+ };
1037
+ BackgroundGeolocation.onConnectivityChange = function (cb) {
1038
+ return BackgroundGeolocation.addListener(backgroundGeolocationTypes.Event.ConnectivityChange, cb);
1039
+ };
1040
+ BackgroundGeolocation.onPowerSaveChange = function (cb) {
1041
+ return BackgroundGeolocation.addListener(backgroundGeolocationTypes.Event.PowerSaveChange, cb);
1042
+ };
1043
+ BackgroundGeolocation.onNotificationAction = function (cb) {
1044
+ return BackgroundGeolocation.addListener("notificationaction", cb);
1045
+ };
1046
+ BackgroundGeolocation.onAuthorization = function (cb) {
1047
+ return BackgroundGeolocation.addListener(backgroundGeolocationTypes.Event.Authorization, cb);
1048
+ };
1049
+ ///
1050
+ /// Listen to a plugin event
1051
+ ///
1052
+ BackgroundGeolocation.addListener = function (event, success, failure) {
1053
+ var handler = function (response) {
1054
+ if (response.hasOwnProperty("value")) {
1055
+ response = response.value;
1056
+ }
1057
+ if (response.hasOwnProperty("error") && (response.error != null)) {
1058
+ if (typeof (failure) === 'function') {
1059
+ failure(response.error);
1060
+ }
1061
+ else {
1062
+ success(response);
1063
+ }
1064
+ }
1065
+ else {
1066
+ success(response);
1067
+ }
1068
+ };
1069
+ // Create a flag to capture edge-case where the developer subscribes to an event then IMMEDIATELY calls subscription.remove()
1070
+ // before NativeModule.addListener has resolved.
1071
+ // The developer would have to do something weird like this:
1072
+ // const subscription = BackgroundGeolocation.onLocation(this.onLocation);
1073
+ // subscription.remove();
1074
+ //
1075
+ // The reason for this is I don't want developers to have to await calls to BackgroundGeolocation.onXXX(myHandler).
1076
+ //
1077
+ var isRemoved = false;
1078
+ var subscriptionProxy = {
1079
+ remove: function () {
1080
+ // EmptyFn until NativeModule.addListener resolves and re-writes this function
1081
+ isRemoved = true;
1082
+ console.warn('[BackgroundGeolocation.addListener] Unexpected call to subscription.remove() on subscriptionProxy. Waiting for NativeModule.addListener to resolve.');
1083
+ }
1084
+ };
1085
+ // Now add the listener and re-write subscriptionProxy.remove.
1086
+ NativeModule.addListener(event, handler).then(function (listener) {
1087
+ var subscription = new Subscription(event, listener, success);
1088
+ EVENT_SUBSCRIPTIONS.push(subscription);
1089
+ subscriptionProxy.remove = function () {
1090
+ listener.remove();
1091
+ // Remove from EVENT_SUBSCRIPTIONS.
1092
+ if (EVENT_SUBSCRIPTIONS.indexOf(subscription) >= 0) {
1093
+ EVENT_SUBSCRIPTIONS.splice(EVENT_SUBSCRIPTIONS.indexOf(subscription), 1);
1094
+ }
1095
+ };
1096
+ if (isRemoved) {
1097
+ // Caught edge-case. Developer added an event-handler then immediately call subscription.remove().
1098
+ subscriptionProxy.remove();
1099
+ }
1100
+ });
1101
+ return subscriptionProxy;
1102
+ };
1103
+ BackgroundGeolocation.removeListener = function (event, callback) {
1104
+ console.warn('BackgroundGeolocation.removeListener is deprecated. Event-listener methods (eg: onLocation) now return a Subscription instance. Call subscription.remove() on the returned subscription instead. Eg:\nconst subscription = BackgroundGeolocation.onLocation(myLocationHandler)\n...\nsubscription.remove()');
1105
+ return new Promise(function (resolve, reject) {
1106
+ var found = null;
1107
+ for (var n = 0, len = EVENT_SUBSCRIPTIONS.length; n < len; n++) {
1108
+ var sub = EVENT_SUBSCRIPTIONS[n];
1109
+ if ((sub.event === event) && (sub.callback === callback)) {
1110
+ found = sub;
1111
+ break;
1112
+ }
1113
+ }
1114
+ if (found !== null) {
1115
+ EVENT_SUBSCRIPTIONS.splice(EVENT_SUBSCRIPTIONS.indexOf(found), 1);
1116
+ found.subscription.remove();
1117
+ resolve();
1118
+ }
1119
+ else {
1120
+ console.warn(TAG + ' Failed to find listener for event ' + event);
1121
+ reject();
1122
+ }
1123
+ });
1124
+ };
1125
+ BackgroundGeolocation.removeListeners = function () {
1126
+ var _this = this;
1127
+ return new Promise(function (resolve) { return __awaiter(_this, undefined, undefined, function () {
1128
+ return __generator(this, function (_a) {
1129
+ switch (_a.label) {
1130
+ case 0:
1131
+ EVENT_SUBSCRIPTIONS = [];
1132
+ return [4 /*yield*/, NativeModule.removeAllEventListeners()];
1133
+ case 1:
1134
+ _a.sent();
1135
+ resolve();
1136
+ return [2 /*return*/];
1137
+ }
1138
+ });
1139
+ }); });
1140
+ };
1141
+ return BackgroundGeolocation;
1142
+ }());
1094
1143
 
1095
- return BackgroundGeolocation;
1144
+ return BackgroundGeolocation;
1096
1145
 
1097
- })(capacitorExports);
1146
+ })(capacitorExports, backgroundGeolocationTypes);
1098
1147
  //# sourceMappingURL=plugin.js.map