@situm/react-native 3.15.0-beta.4 → 3.15.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 (65) hide show
  1. package/lib/commonjs/index.js +72 -0
  2. package/lib/commonjs/index.js.map +1 -0
  3. package/lib/commonjs/sdk/index.js +930 -0
  4. package/lib/commonjs/sdk/index.js.map +1 -1
  5. package/lib/commonjs/sdk/internaDelegatedState.js +48 -0
  6. package/lib/commonjs/sdk/internaDelegatedState.js.map +1 -0
  7. package/lib/commonjs/sdk/nativeInterface.js +20 -0
  8. package/lib/commonjs/sdk/nativeInterface.js.map +1 -0
  9. package/lib/commonjs/sdk/types/constants.js +73 -0
  10. package/lib/commonjs/sdk/types/index.js +414 -0
  11. package/lib/commonjs/sdk/types/index.js.map +1 -0
  12. package/lib/commonjs/sdk/utils.js +156 -0
  13. package/lib/commonjs/sdk/utils.js.map +1 -0
  14. package/lib/commonjs/utils/index.js +17 -0
  15. package/lib/commonjs/utils/logError.js +21 -0
  16. package/lib/commonjs/utils/logError.js.map +1 -0
  17. package/lib/commonjs/wayfinding/components/MapView.js +388 -0
  18. package/lib/commonjs/wayfinding/components/MapView.js.map +1 -0
  19. package/lib/commonjs/wayfinding/hooks/index.js +233 -0
  20. package/lib/commonjs/wayfinding/hooks/index.js.map +1 -0
  21. package/lib/commonjs/wayfinding/index.js +57 -0
  22. package/lib/commonjs/wayfinding/store/index.js +246 -0
  23. package/lib/commonjs/wayfinding/store/index.js.map +1 -0
  24. package/lib/commonjs/wayfinding/store/utils.js +49 -0
  25. package/lib/commonjs/wayfinding/types/constants.js +13 -0
  26. package/lib/commonjs/wayfinding/types/index.js +6 -0
  27. package/lib/commonjs/wayfinding/types/index.js.map +1 -0
  28. package/lib/commonjs/wayfinding/utils/index.js +12 -0
  29. package/lib/commonjs/wayfinding/utils/mapper.js +204 -0
  30. package/lib/commonjs/wayfinding/utils/mapper.js.map +1 -0
  31. package/lib/module/index.js +14 -0
  32. package/lib/module/index.js.map +1 -0
  33. package/lib/module/sdk/index.js +904 -0
  34. package/lib/module/sdk/index.js.map +1 -1
  35. package/lib/module/sdk/internaDelegatedState.js +43 -0
  36. package/lib/module/sdk/internaDelegatedState.js.map +1 -0
  37. package/lib/module/sdk/nativeInterface.js +20 -0
  38. package/lib/module/sdk/nativeInterface.js.map +1 -0
  39. package/lib/module/sdk/types/constants.js +70 -0
  40. package/lib/module/sdk/types/index.js +445 -0
  41. package/lib/module/sdk/types/index.js.map +1 -0
  42. package/lib/module/sdk/utils.js +146 -0
  43. package/lib/module/sdk/utils.js.map +1 -0
  44. package/lib/module/utils/index.js +4 -0
  45. package/lib/module/utils/logError.js +17 -0
  46. package/lib/module/utils/logError.js.map +1 -0
  47. package/lib/module/wayfinding/components/MapView.js +381 -0
  48. package/lib/module/wayfinding/components/MapView.js.map +1 -0
  49. package/lib/module/wayfinding/hooks/index.js +226 -0
  50. package/lib/module/wayfinding/hooks/index.js.map +1 -0
  51. package/lib/module/wayfinding/index.js +15 -0
  52. package/lib/module/wayfinding/store/index.js +213 -0
  53. package/lib/module/wayfinding/store/index.js.map +1 -0
  54. package/lib/module/wayfinding/store/utils.js +40 -0
  55. package/lib/module/wayfinding/types/constants.js +9 -0
  56. package/lib/module/wayfinding/types/index.js +4 -0
  57. package/lib/module/wayfinding/types/index.js.map +1 -0
  58. package/lib/module/wayfinding/utils/index.js +7 -0
  59. package/lib/module/wayfinding/utils/index.js.map +1 -0
  60. package/lib/module/wayfinding/utils/mapper.js +195 -0
  61. package/lib/module/wayfinding/utils/mapper.js.map +1 -0
  62. package/lib/typescript/sdk/index.d.ts +2 -2
  63. package/lib/typescript/sdk/index.d.ts.map +1 -1
  64. package/package.json +5 -5
  65. package/src/sdk/index.ts +12 -3
@@ -0,0 +1,904 @@
1
+ "use strict";
2
+
3
+ /* eslint-disable @typescript-eslint/no-explicit-any */
4
+ /* eslint-disable @typescript-eslint/ban-types */
5
+
6
+ import { NativeEventEmitter, NativeModules, Platform } from "react-native";
7
+ import { logError } from "../utils/logError";
8
+ import { DelegatedStateManager } from "./internaDelegatedState";
9
+ import { ErrorCode, ErrorType, InternalCall } from "./types";
10
+ import { InternalCallType, SdkNavigationUpdateType } from "./types/constants";
11
+ import { exceptionWrapper, locationErrorAdapter, locationStatusAdapter, promiseWrapper } from "./utils";
12
+ export * from "./types";
13
+ export * from "./types/constants";
14
+ const LINKING_ERROR = `The package 'react-native' doesn't seem to be linked. Make sure: \n\n` + Platform.select({
15
+ ios: "- You have run 'pod install'\n",
16
+ default: ""
17
+ }) + "- You rebuilt the app after installing the package\n" + "- You are not using Expo managed workflow\n";
18
+ const RNCSitumPlugin = NativeModules.RNCSitumPlugin || new Proxy({}, {
19
+ get() {
20
+ throw new Error(LINKING_ERROR);
21
+ }
22
+ });
23
+ const SitumPluginEventEmitter = new NativeEventEmitter(RNCSitumPlugin);
24
+
25
+ // TODO: these do not act as state, not reliable
26
+ let positioningRunning = false;
27
+ let navigationRunning = false;
28
+ let realtimeSubscriptions = [];
29
+
30
+ // Internal method call (MapView) delegate:
31
+ let internalMethodCallMapDelegate = _ => {
32
+ // internalMethodCallMapDelegate is an empty function by default.
33
+ };
34
+
35
+ // TODO: For now, I am keeping this behavior as it was, but it seems like a candidate for refactoring.
36
+ const locationCallbackForNavigation = loc => {
37
+ if (!SitumPlugin.navigationIsRunning()) return;
38
+ SitumPlugin.updateNavigationWithLocation(loc);
39
+ };
40
+
41
+ // Client callbacks:
42
+ /* eslint-disable @typescript-eslint/no-empty-function */
43
+
44
+ let locationCallback = _ => {};
45
+ let locationStatusCallback = _ => {};
46
+ let locationStoppedCallback = () => {};
47
+ let locationErrorCallback = _ => {};
48
+ let navigationStartedCallback = _ => {};
49
+ let navigationProgressCallback = _ => {};
50
+ let navigationDestinationReachedCallback = _ => {};
51
+ let navigationOutOfRouteCallback = () => {};
52
+ let navigationFinishedCallback = () => {}; // Deprecated!
53
+ let navigationCancellationCallback = () => {};
54
+ let navigationErrorCallback = _ => {};
55
+ let enterGeofencesCallback = _ => {};
56
+ let exitGeofencesCallback = _ => {};
57
+
58
+ /* eslint-enable @typescript-eslint/no-empty-function */
59
+
60
+ // Internal callbacks:
61
+ // These callback functions will be added as listeners to SitumPluginEventEmitter as soon as possible and will be
62
+ // listening events for all the plugin lifecycle. They will forward calls to both client callbacks and the MapView
63
+ // internal callback.
64
+
65
+ const _internalLocationCallback = loc => {
66
+ DelegatedStateManager.getInstance().updateLocation(loc);
67
+ // MapView internal callback:
68
+ internalMethodCallMapDelegate(new InternalCall(InternalCallType.LOCATION, loc));
69
+ // Navigation internal callback: TODO review this, seems to be different to other plugins and candidate for refactoring.
70
+ locationCallbackForNavigation(loc);
71
+ // Client callback:
72
+ locationCallback(loc);
73
+ };
74
+ const _internalLocationStatusCallback = status => {
75
+ const mapViewStatusName = locationStatusAdapter(status.statusName);
76
+ DelegatedStateManager.getInstance().updateStatus(mapViewStatusName);
77
+ internalMethodCallMapDelegate(new InternalCall(InternalCallType.LOCATION_STATUS, mapViewStatusName));
78
+ // TODO: we are delegating different values to the internal and client callbacks. The viewer only understands
79
+ // the states defined in LocationStatusName, but the integrator might be interested in any state from the SDK.
80
+ locationStatusCallback?.(status);
81
+ };
82
+ const _internalLocationStoppedCallback = () => {
83
+ internalMethodCallMapDelegate(new InternalCall(InternalCallType.LOCATION_STOPPED, undefined));
84
+ // TODO: this callback is used only in RN, delete!
85
+ locationStoppedCallback?.();
86
+ };
87
+ const _internalLocationErrorCallback = error => {
88
+ const adaptedError = locationErrorAdapter(error);
89
+ DelegatedStateManager.getInstance().updateError(adaptedError);
90
+ internalMethodCallMapDelegate(new InternalCall(InternalCallType.LOCATION_ERROR, adaptedError));
91
+ locationErrorCallback?.(adaptedError);
92
+ };
93
+ const _internalNavigationStartedCallback = route => {
94
+ internalMethodCallMapDelegate(new InternalCall(InternalCallType.NAVIGATION_START, route));
95
+ navigationStartedCallback?.(route);
96
+ };
97
+ const _internalNavigationProgressCallback = progress => {
98
+ internalMethodCallMapDelegate(new InternalCall(InternalCallType.NAVIGATION_PROGRESS, progress));
99
+ navigationProgressCallback?.(progress);
100
+ };
101
+ const _internalNavigationDestinationReachedCallback = route => {
102
+ internalMethodCallMapDelegate(new InternalCall(InternalCallType.NAVIGATION_DESTINATION_REACHED, route));
103
+ navigationDestinationReachedCallback?.(route);
104
+ };
105
+ const _internalNavigationOutOfRouteCallback = () => {
106
+ internalMethodCallMapDelegate(new InternalCall(InternalCallType.NAVIGATION_OUT_OF_ROUTE, undefined));
107
+ navigationOutOfRouteCallback?.();
108
+ };
109
+ const _internalNavigationFinishedCallback = () => {
110
+ // Deprecated!
111
+ internalMethodCallMapDelegate(new InternalCall(InternalCallType.NAVIGATION_CANCELLATION, undefined));
112
+ navigationFinishedCallback?.();
113
+ };
114
+ const _internalNavigationCancellationCallback = () => {
115
+ internalMethodCallMapDelegate(new InternalCall(InternalCallType.NAVIGATION_CANCELLATION, undefined));
116
+ navigationCancellationCallback?.();
117
+ };
118
+ const _internalNavigationErrorCallback = error => {
119
+ internalMethodCallMapDelegate(new InternalCall(InternalCallType.NAVIGATION_ERROR, error));
120
+ navigationErrorCallback?.(error);
121
+ };
122
+ const _internalEnterGeofencesCallback = data => {
123
+ internalMethodCallMapDelegate(new InternalCall(InternalCallType.GEOFENCES_ENTER, data));
124
+ enterGeofencesCallback?.(data);
125
+ };
126
+ const _internalExitGeofencesCallback = data => {
127
+ internalMethodCallMapDelegate(new InternalCall(InternalCallType.GEOFENCES_EXIT, data));
128
+ exitGeofencesCallback?.(data);
129
+ };
130
+ const _registerCallbacks = () => {
131
+ const callbacksMap = {
132
+ locationChanged: _internalLocationCallback,
133
+ statusChanged: _internalLocationStatusCallback,
134
+ locationStopped: _internalLocationStoppedCallback,
135
+ locationError: _internalLocationErrorCallback,
136
+ [SdkNavigationUpdateType.START]: _internalNavigationStartedCallback,
137
+ [SdkNavigationUpdateType.PROGRESS]: _internalNavigationProgressCallback,
138
+ [SdkNavigationUpdateType.DESTINATION_REACHED]: _internalNavigationDestinationReachedCallback,
139
+ [SdkNavigationUpdateType.OUTSIDE_ROUTE]: _internalNavigationOutOfRouteCallback,
140
+ [SdkNavigationUpdateType.FINISHED]: _internalNavigationFinishedCallback,
141
+ [SdkNavigationUpdateType.CANCELLATION]: _internalNavigationCancellationCallback,
142
+ [SdkNavigationUpdateType.ERROR]: _internalNavigationErrorCallback,
143
+ onEnterGeofences: _internalEnterGeofencesCallback,
144
+ onExitGeofences: _internalExitGeofencesCallback
145
+ };
146
+ Object.entries(callbacksMap).forEach(([eventName, callback]) => {
147
+ console.log("Event emitter add listener: ", eventName);
148
+ SitumPluginEventEmitter.removeAllListeners(eventName);
149
+ SitumPluginEventEmitter.addListener(eventName, callback);
150
+ console.log("Event emitter add listener finished: ", eventName);
151
+ });
152
+ };
153
+
154
+ // End Internal callbacks --
155
+
156
+ export default class SitumPlugin {
157
+ /**
158
+ * Whether the positioning is currently in execution.
159
+ * @returns boolean
160
+ */
161
+ static positioningIsRunning = () => positioningRunning;
162
+
163
+ /**
164
+ * Whether the navigation is currently in execution.
165
+ * @returns boolean
166
+ */
167
+ static navigationIsRunning = () => navigationRunning;
168
+
169
+ /**
170
+ * Initializes {@link SitumPlugin}.
171
+ *
172
+ * This method must be called before invoking any other methods.
173
+ * This method can be safely called many times as it will only initialise the SDK
174
+ * if it is not already initialised.
175
+ *
176
+ * @returns void
177
+ * @throw Exception
178
+ */
179
+ static init = () => {
180
+ _registerCallbacks();
181
+ return exceptionWrapper(() => {
182
+ RNCSitumPlugin.initSitumSDK();
183
+ });
184
+ };
185
+
186
+ /**
187
+ * Provides your API key to the Situm SDK.
188
+ *
189
+ * This key is generated for your application in the Dashboard.
190
+ * Old credentials will be removed.
191
+ *
192
+ * @param apiKey user's apikey.
193
+ *
194
+ * @returns void
195
+ * @throw Exception
196
+ */
197
+ static setApiKey = apiKey => {
198
+ return exceptionWrapper(({
199
+ onCallback
200
+ }) => {
201
+ RNCSitumPlugin.setApiKey("email@email.com", apiKey, response => {
202
+ onCallback(response, "Failed to set API key.");
203
+ });
204
+ });
205
+ };
206
+
207
+ /**
208
+ * Provides user's email and password. This credentials will be used to obtain a
209
+ * valid user token to authenticate the server request, when necessary. Token
210
+ * obtaining is not necessary done when this method is executed. Old credentials
211
+ * will be removed.
212
+ *
213
+ * @param email user's email.
214
+ * @param password user's password.
215
+ *
216
+ * @returns void
217
+ * @throw Exception
218
+ */
219
+ static setUserPass = (email, password) => {
220
+ return exceptionWrapper(({
221
+ onCallback
222
+ }) => {
223
+ RNCSitumPlugin.setUserPass(email, password, response => {
224
+ onCallback(response, "Failed to set user credentials.");
225
+ });
226
+ });
227
+ };
228
+
229
+ /**
230
+ * Sets the API's base URL to retrieve the data.
231
+ *
232
+ * @param url user's email.
233
+ *
234
+ * @returns void
235
+ * @throw Exception
236
+ */
237
+
238
+ static setDashboardURL = url => {
239
+ return exceptionWrapper(({
240
+ onCallback
241
+ }) => {
242
+ RNCSitumPlugin.setDashboardURL(url, response => {
243
+ onCallback(response, "Failed to set dashboard URL.");
244
+ });
245
+ });
246
+ };
247
+
248
+ /**
249
+ * Set to true if you want the SDK to download the configuration from the Situm API
250
+ * and use it by default. Right now it only affects the {@link LocationRequest}.
251
+ * Default value is true from SDK version 2.83.5
252
+ *
253
+ * @param useRemoteConfig
254
+ *
255
+ * @returns void
256
+ * @throw Exception
257
+ */
258
+ static setUseRemoteConfig = useRemoteConfig => {
259
+ return exceptionWrapper(({
260
+ onCallback
261
+ }) => {
262
+ RNCSitumPlugin.setUseRemoteConfig(useRemoteConfig ? "true" : "false", response => {
263
+ onCallback(response, "Failed to set remote config");
264
+ });
265
+ });
266
+ };
267
+
268
+ /**
269
+ * Sets the max seconds the cache is valid
270
+ *
271
+ * @returns void
272
+ * @throw Exception
273
+ */
274
+ static setMaxCacheAge = cacheAge => {
275
+ return exceptionWrapper(({
276
+ onCallback
277
+ }) => {
278
+ RNCSitumPlugin.setCacheMaxAge(cacheAge, response => {
279
+ onCallback(response, "Failed to set cache max age");
280
+ });
281
+ });
282
+ };
283
+
284
+ /**
285
+ * Sets the SDK {@link ConfigurationOptions}.
286
+ *
287
+ * @param options {@link ConfigurationOptions}
288
+ *
289
+ * @returns void
290
+ * @throw Exception
291
+ */
292
+ static setConfiguration = options => {
293
+ return exceptionWrapper(() => {
294
+ if (options.useRemoteConfig !== undefined) {
295
+ SitumPlugin.setUseRemoteConfig(options.useRemoteConfig);
296
+ }
297
+ if (options.cacheMaxAge !== undefined) {
298
+ SitumPlugin.setMaxCacheAge(options.cacheMaxAge);
299
+ }
300
+
301
+ // Handle rest of configuration options
302
+ });
303
+ };
304
+
305
+ /**
306
+ * Invalidate all the resources in the cache
307
+ *
308
+ * @returns void
309
+ * @throw Exception
310
+ */
311
+ static invalidateCache = () => {
312
+ return exceptionWrapper(() => {
313
+ RNCSitumPlugin.invalidateCache();
314
+ });
315
+ };
316
+
317
+ /**
318
+ * @deprecated
319
+ * DEPRECATED: this method will not work anymore.
320
+ *
321
+ * Gets the list of versions for the current plugin and environment
322
+ *
323
+ * @returns void
324
+ * @throw Exception
325
+ */
326
+ static sdkVersion = () => {
327
+ return exceptionWrapper(({
328
+ onSuccess
329
+ }) => {
330
+ const versions = {
331
+ react_native: "",
332
+ ios: "",
333
+ android: ""
334
+ };
335
+ onSuccess(versions);
336
+ });
337
+ };
338
+
339
+ /**
340
+ * Returns the device identifier that has generated the location
341
+ */
342
+ static getDeviceId = () => {
343
+ return promiseWrapper(({
344
+ onSuccess,
345
+ onError
346
+ }) => {
347
+ RNCSitumPlugin.getDeviceId(response => {
348
+ //@ts-ignore
349
+ if (response?.deviceId) {
350
+ // Resolve with the actual deviceId
351
+ //@ts-ignore
352
+ onSuccess(response.deviceId);
353
+ } else {
354
+ // Reject if deviceId is not available in the response
355
+ onError({
356
+ code: ErrorCode.UNKNOWN,
357
+ message: "Couldn't get device ID",
358
+ type: ErrorType.CRITICAL
359
+ });
360
+ }
361
+ });
362
+ });
363
+ };
364
+
365
+ /**
366
+ * Downloads all the {@link Building}s for the current user.
367
+ */
368
+ static fetchBuildings = () => {
369
+ return promiseWrapper(({
370
+ onSuccess,
371
+ onError
372
+ }) => {
373
+ RNCSitumPlugin.fetchBuildings(onSuccess, onError);
374
+ });
375
+ };
376
+
377
+ /**
378
+ * Downloads all the building data for the selected building. This info includes
379
+ * {@link Floor}, indoor and outdoor {@link Poi}s, events and paths. Also it download floor
380
+ * maps and {@link PoiCategory} icons to local storage.
381
+ *
382
+ * @param building {@link Building}
383
+ */
384
+ static fetchBuildingInfo = building => {
385
+ return promiseWrapper(({
386
+ onSuccess,
387
+ onError
388
+ }) => {
389
+ RNCSitumPlugin.fetchBuildingInfo(building, onSuccess, onError);
390
+ });
391
+ };
392
+
393
+ /**
394
+ * (Experimental) Downloads the tiled-map of a certain building
395
+ *
396
+ * @param building {@link Building} whose tiles will be downloaded
397
+ */
398
+ static fetchTilesFromBuilding = building => {
399
+ return promiseWrapper(({
400
+ onSuccess,
401
+ onError
402
+ }) => {
403
+ RNCSitumPlugin.fetchTilesFromBuilding(building, onSuccess, onError);
404
+ });
405
+ };
406
+
407
+ /**
408
+ * Downloads all the floors of a building
409
+ *
410
+ * @param building {@link Building}
411
+ */
412
+ static fetchFloorsFromBuilding = building => {
413
+ return promiseWrapper(({
414
+ onSuccess,
415
+ onError
416
+ }) => {
417
+ RNCSitumPlugin.fetchFloorsFromBuilding(building, onSuccess, onError);
418
+ });
419
+ };
420
+
421
+ /**
422
+ * Downloads the map image of a {@link Floor}
423
+ *
424
+ * @param floor {@link Floor}
425
+ */
426
+ static fetchMapFromFloor = floor => {
427
+ return promiseWrapper(({
428
+ onSuccess,
429
+ onError
430
+ }) => {
431
+ RNCSitumPlugin.fetchMapFromFloor(floor, onSuccess, onError);
432
+ });
433
+ };
434
+
435
+ /**
436
+ * Get the geofences of a {@link Building}
437
+ *
438
+ * @param building {@link Building}
439
+ */
440
+ static fetchGeofencesFromBuilding = building => {
441
+ return promiseWrapper(({
442
+ onSuccess,
443
+ onError
444
+ }) => {
445
+ RNCSitumPlugin.fetchGeofencesFromBuilding(building, onSuccess, onError);
446
+ });
447
+ };
448
+
449
+ /**
450
+ * Get all {@link PoiCategory}, download and cache their icons asynchronously.
451
+ */
452
+ static fetchPoiCategories = () => {
453
+ return promiseWrapper(({
454
+ onSuccess,
455
+ onError
456
+ }) => {
457
+ RNCSitumPlugin.fetchPoiCategories(onSuccess, onError);
458
+ });
459
+ };
460
+
461
+ /**
462
+ * Get the normal {@link PoiIcon} for a category
463
+ *
464
+ * @param category {@link PoiCategory}. Not null.
465
+ */
466
+ static fetchPoiCategoryIconNormal = category => {
467
+ return promiseWrapper(({
468
+ onSuccess,
469
+ onError
470
+ }) => {
471
+ RNCSitumPlugin.fetchPoiCategoryIconNormal(category, onSuccess, onError);
472
+ });
473
+ };
474
+
475
+ /**
476
+ * Get the selected {@link PoiIcon} for a {@link PoiCategory}
477
+ *
478
+ * @param category {@link PoiCategory}. Not null.
479
+ */
480
+ static fetchPoiCategoryIconSelected = category => {
481
+ return promiseWrapper(({
482
+ onSuccess,
483
+ onError
484
+ }) => {
485
+ RNCSitumPlugin.fetchPoiCategoryIconSelected(category, onSuccess, onError);
486
+ });
487
+ };
488
+
489
+ /**
490
+ * Download the indoor {@link Poi}s of a {@link Building}
491
+ *
492
+ * @param building {@link Building}
493
+ */
494
+ static fetchIndoorPOIsFromBuilding = building => {
495
+ return promiseWrapper(({
496
+ onSuccess,
497
+ onError
498
+ }) => {
499
+ RNCSitumPlugin.fetchIndoorPOIsFromBuilding(building, onSuccess, onError);
500
+ });
501
+ };
502
+
503
+ /**
504
+ * Download the outdoor {@link Poi}s of a {@link Building}
505
+ *
506
+ * @param building {@link Building}
507
+ */
508
+ static fetchOutdoorPOIsFromBuilding = building => {
509
+ return promiseWrapper(({
510
+ onSuccess,
511
+ onError
512
+ }) => {
513
+ RNCSitumPlugin.fetchOutdoorPOIsFromBuilding(building, onSuccess, onError);
514
+ });
515
+ };
516
+
517
+ /**
518
+ * Starts positioning.
519
+ *
520
+ * @param {LocationRequest} locationRequest Positioning options to configure how positioning will behave
521
+ */
522
+ static requestLocationUpdates = locationRequest => {
523
+ return exceptionWrapper(() => {
524
+ if (SitumPlugin.positioningIsRunning()) return;
525
+ RNCSitumPlugin.startPositioning(locationRequest || {});
526
+ positioningRunning = true;
527
+ });
528
+ };
529
+
530
+ /**
531
+ * Stops positioning, removing all location updates
532
+ */
533
+ static removeLocationUpdates = () => {
534
+ return exceptionWrapper(() => {
535
+ if (!SitumPlugin.positioningIsRunning()) return;
536
+ RNCSitumPlugin.stopPositioning(response => {
537
+ if (response.success) {
538
+ positioningRunning = false;
539
+ } else {
540
+ throw "Situm > hook > Could not stop positioning";
541
+ }
542
+ });
543
+ });
544
+ };
545
+
546
+ /**
547
+ * Calculates a route between two points. The result is provided
548
+ * asynchronously using the callback.
549
+ *
550
+ * @param building {@link Building}
551
+ * @param from {@link Point} route origin
552
+ * @param to {@link Point} route destination
553
+ * @param directionOptions {@link DirectionsOptions}
554
+ */
555
+ static requestDirections = (building, from, to, directionOptions) => {
556
+ return promiseWrapper(({
557
+ onSuccess,
558
+ onError
559
+ }) => {
560
+ const params = [building, from, to, directionOptions || {}];
561
+ RNCSitumPlugin.requestDirections(params, onSuccess, onError);
562
+ });
563
+ };
564
+
565
+ /**
566
+ * Set the navigation params, and the listener that receives the updated
567
+ * navigation progress.
568
+ *
569
+ * Can only exist one navigation with one listener at a time. If this method was
570
+ * previously invoked, but removeLocationUpdates() wasn't, removeLocationUpdates()
571
+ * is called internally.
572
+ *
573
+ * @param options {@link NavigationRequest}
574
+ */
575
+ static requestNavigationUpdates = options => {
576
+ return exceptionWrapper(() => {
577
+ RNCSitumPlugin.requestNavigationUpdates(options || {});
578
+ navigationRunning = true;
579
+ });
580
+ };
581
+
582
+ /**
583
+ * Informs NavigationManager object the change of the user's location
584
+ *
585
+ * @param location new {@link Location} of the user. If null, nothing is done
586
+ */
587
+ static updateNavigationWithLocation = location => {
588
+ return exceptionWrapper(({
589
+ onSuccess,
590
+ onError
591
+ }) => {
592
+ if (!SitumPlugin.navigationIsRunning()) {
593
+ throw "Situm > hook > No active navigation";
594
+ }
595
+ RNCSitumPlugin.updateNavigationWithLocation(location, onSuccess, onError);
596
+ });
597
+ };
598
+
599
+ /**
600
+ * Removes all location updates. This removes the internal state of the manager,
601
+ * including the listener provided in requestNavigationUpdates(NavigationRequest,
602
+ * NavigationListener), so it won't receive more progress updates.
603
+ *
604
+ */
605
+ static removeNavigationUpdates = () => {
606
+ return promiseWrapper(({
607
+ onCallback
608
+ }) => {
609
+ if (!SitumPlugin.navigationIsRunning()) return;
610
+ navigationRunning = false;
611
+ RNCSitumPlugin.removeNavigationUpdates(response => {
612
+ onCallback(response, "Failed to remove navigation updates");
613
+ });
614
+ });
615
+ };
616
+
617
+ /**
618
+ * Requests a real time devices positions
619
+ *
620
+ * @param realtimeUpdates callback to use when new device positions are updated
621
+ * @param error callback to use when an error on navigation udpates raises
622
+ * @param options Represents the configuration for getting realtime devices positions in
623
+ */
624
+
625
+ static requestRealTimeUpdates = (realtimeUpdates, error, options) => {
626
+ return exceptionWrapper(() => {
627
+ RNCSitumPlugin.requestRealTimeUpdates(options || {});
628
+ realtimeSubscriptions.push([SitumPluginEventEmitter.addListener("realtimeUpdated", realtimeUpdates), error ? SitumPluginEventEmitter.addListener("realtimeError", error || logError) : null]);
629
+ });
630
+ };
631
+
632
+ /**
633
+ * Removes all real time updates listners.
634
+ *
635
+ * @param _callback
636
+ */
637
+ static removeRealTimeUpdates = _callback => {
638
+ return exceptionWrapper(() => {
639
+ realtimeSubscriptions = [];
640
+ RNCSitumPlugin.removeRealTimeUpdates();
641
+ });
642
+ };
643
+
644
+ /**
645
+ * Checks if a point is inside a {@link Geofence}
646
+ *
647
+ */
648
+ static checkIfPointInsideGeofence = (request, callback) => {
649
+ const noop = () => {}; // eslint-disable-line @typescript-eslint/no-empty-function
650
+ RNCSitumPlugin.checkIfPointInsideGeofence(request, callback || noop);
651
+ };
652
+
653
+ /**
654
+ * Automatically assists users in resolving app-related permission and sensor issues.
655
+ *
656
+ * This method tells the native SDKs to present a user interface that explains detected
657
+ * configuration issues and guides users through the required steps to resolve them,
658
+ * following best practices for runtime permission requests.
659
+ *
660
+ * Issues addressed include:
661
+ * - Missing permissions for Location or Bluetooth.
662
+ * - Disabled Location or Bluetooth sensors.
663
+ *
664
+ * Use the <code>userHelperOptions</code> parameter to configure the available options.
665
+ * Call {@link enableUserHelper} as a shortcut to enable the user helper with default configuration.
666
+ * Call {@link disableUserHelper} as a shortcut to disable the user helper.
667
+ *
668
+ * @param {UserHelperOptions} userHelperOptions - Options for the user helper.
669
+ */
670
+ static configureUserHelper = userHelperOptions => {
671
+ _registerCallbacks();
672
+ return exceptionWrapper(({
673
+ onSuccess,
674
+ onError
675
+ }) => {
676
+ RNCSitumPlugin.configureUserHelper(userHelperOptions, onSuccess, onError);
677
+ });
678
+ };
679
+
680
+ /**
681
+ * Enables the user helper.
682
+ *
683
+ * Shortcut for {@link configureUserHelper} with <code>{enabled: true}</code>.
684
+ */
685
+ static enableUserHelper = () => {
686
+ SitumPlugin.configureUserHelper({
687
+ enabled: true,
688
+ colorScheme: undefined
689
+ });
690
+ };
691
+
692
+ /**
693
+ * Disables the user helper.
694
+ *
695
+ * Shortcut for {@link configureUserHelper} with <code>{enabled: false}</code>.
696
+ *
697
+ */
698
+ static disableUserHelper = () => {
699
+ SitumPlugin.configureUserHelper({
700
+ enabled: false,
701
+ colorScheme: undefined
702
+ });
703
+ };
704
+
705
+ /**
706
+ * INTERNAL METHOD.
707
+ *
708
+ * Update SDK with the viewer navigation states.
709
+ * Do not use this method as it is intended for internal use
710
+ * by the map viewer module.
711
+ *
712
+ * @param externalNavigation
713
+ */
714
+ static updateNavigationState = externalNavigation => {
715
+ return exceptionWrapper(() => {
716
+ RNCSitumPlugin.updateNavigationState(externalNavigation);
717
+ });
718
+ };
719
+
720
+ /**
721
+ * INTERNAL METHOD.
722
+ *
723
+ * Validate if the mapView internal settings have been properly configured
724
+ * Do not use this method as it is intended for internal use
725
+ * by the map viewer module.
726
+ *
727
+ * @param validateMapViewProjectSettings
728
+ */
729
+ static validateMapViewProjectSettings = () => {
730
+ if (Platform.OS === "ios") {
731
+ return exceptionWrapper(() => {
732
+ RNCSitumPlugin.validateMapViewProjectSettings();
733
+ });
734
+ }
735
+ };
736
+
737
+ /**
738
+ * INTERNAL METHOD.
739
+ *
740
+ * Set a native MethodCall delegate. Do not use this method as it is intended for internal use by the map viewer module.
741
+ * @param callback
742
+ */
743
+ static internalSetMethodCallMapDelegate = callback => {
744
+ internalMethodCallMapDelegate = callback;
745
+ const lastValues = DelegatedStateManager.getInstance().getValues();
746
+ // Forward last received values as soon as possible:
747
+ if (lastValues.location) {
748
+ internalMethodCallMapDelegate(new InternalCall(InternalCallType.LOCATION, lastValues.location));
749
+ }
750
+ if (lastValues.status) {
751
+ internalMethodCallMapDelegate(new InternalCall(InternalCallType.LOCATION_STATUS, lastValues.status));
752
+ }
753
+ if (lastValues.error) {
754
+ internalMethodCallMapDelegate(new InternalCall(InternalCallType.LOCATION_ERROR, lastValues.error));
755
+ }
756
+ };
757
+
758
+ //-----------------------------------------------------------------------------//
759
+ //-----------------------------GEOFENCES CALLBACKS-----------------------------//
760
+ //-----------------------------------------------------------------------------//
761
+
762
+ /**
763
+ * Callback that notifies when the user enters a {@link Geofence}.
764
+ *
765
+ * In order to use correctly these callbacks you must know the following:
766
+ * - Positioning geofences (with trainer_metadata custom field) won't be notified.
767
+ * - These callbacks only work with indoor locations. Any outdoor location will
768
+ * produce a call to onExitedGeofences with the last positioned geofences as argument.
769
+ *
770
+ * @param callback the function called when the user enters a {@link Geofence}
771
+ */
772
+ static onEnterGeofences = callback => {
773
+ RNCSitumPlugin.onEnterGeofences();
774
+ // Adopts SDK behavior (setter):
775
+ enterGeofencesCallback = callback;
776
+ };
777
+
778
+ /**
779
+ * Callback that notifies when the user exits a {@link Geofence}.
780
+ *
781
+ * In order to use correctly these callbacks you must know the following:
782
+ * - Positioning geofences (with trainer_metadata custom field) won't be notified.
783
+ * - These callbacks only work with indoor locations. Any outdoor location will
784
+ * produce a call to onExitedGeofences with the last positioned geofences as argument.
785
+ *
786
+ * @param callback the function called when the user exits a {@link Geofence}
787
+ */
788
+ static onExitGeofences = callback => {
789
+ RNCSitumPlugin.onExitGeofences();
790
+ exitGeofencesCallback = callback;
791
+ };
792
+
793
+ //-----------------------------------------------------------------------------//
794
+ //-----------------------------LOCATION CALLBACKS------------------------------//
795
+ //-----------------------------------------------------------------------------//
796
+
797
+ /**
798
+ * Callback that notifies when the user {@link Location} changes.
799
+ *
800
+ * @param callback the function called when the user {@link Location} changes
801
+ */
802
+ static onLocationUpdate = callback => {
803
+ locationCallback = callback;
804
+ };
805
+
806
+ /**
807
+ * Callback that notifies when the user {@link LocationStatus} changes.
808
+ *
809
+ * @param callback the function called when the user {@link LocationStatus} changes
810
+ */
811
+ static onLocationStatus = callback => {
812
+ locationStatusCallback = callback;
813
+ };
814
+
815
+ /**
816
+ * Callback that notifies when there is an error while the user is positioining.
817
+ *
818
+ * @param callback the function called when there is an error
819
+ */
820
+ static onLocationError = callback => {
821
+ locationErrorCallback = callback;
822
+ };
823
+
824
+ /**
825
+ * Callback that notifies when the user stops positioning.
826
+ *
827
+ * @param callback the function called when the user stops positioning.
828
+ */
829
+ static onLocationStopped = callback => {
830
+ locationStoppedCallback = callback;
831
+ };
832
+
833
+ //-----------------------------------------------------------------------------//
834
+ //-----------------------------NAVIGATION CALLBACKS----------------------------//
835
+ //-----------------------------------------------------------------------------//
836
+
837
+ /**
838
+ * Callback that notifies when navigation starts.
839
+ *
840
+ * @param callback a function that returns the initial {@link Route} by parameters.
841
+ */
842
+ static onNavigationStart = callback => {
843
+ navigationStartedCallback = callback;
844
+ };
845
+
846
+ /**
847
+ * Callback that notifies every progress the user makes while navigating.
848
+ *
849
+ * @param callback a function that returns the {@link NavigationProgress} by parameters.
850
+ */
851
+ static onNavigationProgress = callback => {
852
+ navigationProgressCallback = callback;
853
+ };
854
+
855
+ /**
856
+ * Callback that notifies when the user reaches the destination POI.
857
+ *
858
+ * @param callback a function that returns the completed {@link Route} by parameters.
859
+ */
860
+ static onNavigationDestinationReached = callback => {
861
+ navigationDestinationReachedCallback = callback;
862
+ };
863
+
864
+ /**
865
+ * Callback that notifies when the user gets out of the current route.
866
+ *
867
+ * @param callback the function called when the user gets out of the current route.
868
+ */
869
+ static onNavigationOutOfRoute = callback => {
870
+ navigationOutOfRouteCallback = callback;
871
+ };
872
+
873
+ /**
874
+ * @deprecated
875
+ * DEPRECATED: Use instead onNavigationCancellation()
876
+ * and onNavigationDestinationReached() to determine why did the navigation end.
877
+ *
878
+ * Callback that notifies when the user finishes the route.
879
+ *
880
+ * @param callback the function called when the user finishes the route.
881
+ */
882
+ static onNavigationFinished = callback => {
883
+ navigationFinishedCallback = callback;
884
+ };
885
+
886
+ /**
887
+ * Callback that notifies when the user does cancel the navigation.
888
+ *
889
+ * @param callback the function called when the user cancels the navigation.
890
+ */
891
+ static onNavigationCancellation = callback => {
892
+ navigationCancellationCallback = callback;
893
+ };
894
+
895
+ /**
896
+ * Callback that notifies when there is an error during navigation.
897
+ *
898
+ * @param callback the function called when there is an error during navigation.
899
+ */
900
+ static onNavigationError = callback => {
901
+ navigationErrorCallback = callback;
902
+ };
903
+ }
904
+ //# sourceMappingURL=index.js.map