@transistorsoft/capacitor-background-geolocation 6.1.5 → 7.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/android/build.gradle +3 -3
  2. package/android/libs/com/transistorsoft/tslocationmanager/{3.6.4/tslocationmanager-3.6.4.aar → 3.6.5/tslocationmanager-3.6.5.aar} +0 -0
  3. package/android/libs/com/transistorsoft/tslocationmanager/3.6.5/tslocationmanager-3.6.5.aar.md5 +1 -0
  4. package/android/libs/com/transistorsoft/tslocationmanager/3.6.5/tslocationmanager-3.6.5.aar.sha1 +1 -0
  5. package/android/libs/com/transistorsoft/tslocationmanager/3.6.5/tslocationmanager-3.6.5.aar.sha256 +1 -0
  6. package/android/libs/com/transistorsoft/tslocationmanager/3.6.5/tslocationmanager-3.6.5.aar.sha512 +1 -0
  7. package/android/libs/com/transistorsoft/tslocationmanager/{3.6.4/tslocationmanager-3.6.4.pom → 3.6.5/tslocationmanager-3.6.5.pom} +1 -1
  8. package/android/libs/com/transistorsoft/tslocationmanager/3.6.5/tslocationmanager-3.6.5.pom.md5 +1 -0
  9. package/android/libs/com/transistorsoft/tslocationmanager/3.6.5/tslocationmanager-3.6.5.pom.sha1 +1 -0
  10. package/android/libs/com/transistorsoft/tslocationmanager/3.6.5/tslocationmanager-3.6.5.pom.sha256 +1 -0
  11. package/android/libs/com/transistorsoft/tslocationmanager/3.6.5/tslocationmanager-3.6.5.pom.sha512 +1 -0
  12. package/android/libs/com/transistorsoft/tslocationmanager/maven-metadata.xml +4 -3
  13. package/android/libs/com/transistorsoft/tslocationmanager-v21/{3.6.4/tslocationmanager-v21-3.6.4.aar → 3.6.5/tslocationmanager-v21-3.6.5.aar} +0 -0
  14. package/android/libs/com/transistorsoft/tslocationmanager-v21/3.6.5/tslocationmanager-v21-3.6.5.aar.md5 +1 -0
  15. package/android/libs/com/transistorsoft/tslocationmanager-v21/3.6.5/tslocationmanager-v21-3.6.5.aar.sha1 +1 -0
  16. package/android/libs/com/transistorsoft/tslocationmanager-v21/3.6.5/tslocationmanager-v21-3.6.5.aar.sha256 +1 -0
  17. package/android/libs/com/transistorsoft/tslocationmanager-v21/3.6.5/tslocationmanager-v21-3.6.5.aar.sha512 +1 -0
  18. package/android/libs/com/transistorsoft/tslocationmanager-v21/{3.6.4/tslocationmanager-v21-3.6.4.pom → 3.6.5/tslocationmanager-v21-3.6.5.pom} +1 -1
  19. package/android/libs/com/transistorsoft/tslocationmanager-v21/3.6.5/tslocationmanager-v21-3.6.5.pom.md5 +1 -0
  20. package/android/libs/com/transistorsoft/tslocationmanager-v21/3.6.5/tslocationmanager-v21-3.6.5.pom.sha1 +1 -0
  21. package/android/libs/com/transistorsoft/tslocationmanager-v21/3.6.5/tslocationmanager-v21-3.6.5.pom.sha256 +1 -0
  22. package/android/libs/com/transistorsoft/tslocationmanager-v21/3.6.5/tslocationmanager-v21-3.6.5.pom.sha512 +1 -0
  23. package/android/libs/com/transistorsoft/tslocationmanager-v21/maven-metadata.xml +4 -3
  24. package/dist/index.js +223 -3
  25. package/dist/index.js.map +1 -1
  26. package/dist/plugin.cjs.js +90 -87
  27. package/dist/plugin.cjs.js.map +1 -1
  28. package/dist/plugin.js +1098 -0
  29. package/dist/plugin.js.map +1 -0
  30. package/package.json +20 -19
  31. package/android/libs/com/transistorsoft/tslocationmanager/3.6.4/tslocationmanager-3.6.4.aar.md5 +0 -1
  32. package/android/libs/com/transistorsoft/tslocationmanager/3.6.4/tslocationmanager-3.6.4.aar.sha1 +0 -1
  33. package/android/libs/com/transistorsoft/tslocationmanager/3.6.4/tslocationmanager-3.6.4.aar.sha256 +0 -1
  34. package/android/libs/com/transistorsoft/tslocationmanager/3.6.4/tslocationmanager-3.6.4.aar.sha512 +0 -1
  35. package/android/libs/com/transistorsoft/tslocationmanager/3.6.4/tslocationmanager-3.6.4.pom.md5 +0 -1
  36. package/android/libs/com/transistorsoft/tslocationmanager/3.6.4/tslocationmanager-3.6.4.pom.sha1 +0 -1
  37. package/android/libs/com/transistorsoft/tslocationmanager/3.6.4/tslocationmanager-3.6.4.pom.sha256 +0 -1
  38. package/android/libs/com/transistorsoft/tslocationmanager/3.6.4/tslocationmanager-3.6.4.pom.sha512 +0 -1
  39. package/android/libs/com/transistorsoft/tslocationmanager-v21/3.6.4/tslocationmanager-v21-3.6.4.aar.md5 +0 -1
  40. package/android/libs/com/transistorsoft/tslocationmanager-v21/3.6.4/tslocationmanager-v21-3.6.4.aar.sha1 +0 -1
  41. package/android/libs/com/transistorsoft/tslocationmanager-v21/3.6.4/tslocationmanager-v21-3.6.4.aar.sha256 +0 -1
  42. package/android/libs/com/transistorsoft/tslocationmanager-v21/3.6.4/tslocationmanager-v21-3.6.4.aar.sha512 +0 -1
  43. package/android/libs/com/transistorsoft/tslocationmanager-v21/3.6.4/tslocationmanager-v21-3.6.4.pom.md5 +0 -1
  44. package/android/libs/com/transistorsoft/tslocationmanager-v21/3.6.4/tslocationmanager-v21-3.6.4.pom.sha1 +0 -1
  45. package/android/libs/com/transistorsoft/tslocationmanager-v21/3.6.4/tslocationmanager-v21-3.6.4.pom.sha256 +0 -1
  46. package/android/libs/com/transistorsoft/tslocationmanager-v21/3.6.4/tslocationmanager-v21-3.6.4.pom.sha512 +0 -1
  47. package/dist/DeviceSettings.js +0 -56
  48. package/dist/DeviceSettings.js.map +0 -1
  49. package/dist/Logger.js +0 -97
  50. package/dist/Logger.js.map +0 -1
  51. package/dist/TransistorAuthorizationToken.js +0 -73
  52. package/dist/TransistorAuthorizationToken.js.map +0 -1
package/dist/plugin.js ADDED
@@ -0,0 +1,1098 @@
1
+ var capacitorBackgroundGeolocation = (function (core) {
2
+ 'use strict';
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
+ };
22
+
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 + "'");
1003
+ }
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
+ }());
1094
+
1095
+ return BackgroundGeolocation;
1096
+
1097
+ })(capacitorExports);
1098
+ //# sourceMappingURL=plugin.js.map