@situm/react-native 3.15.0-beta.4 → 3.15.0-beta.5

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 (60) hide show
  1. package/lib/commonjs/index.js +73 -0
  2. package/lib/commonjs/index.js.map +1 -0
  3. package/lib/commonjs/sdk/index.js +920 -0
  4. package/lib/commonjs/sdk/internaDelegatedState.js +48 -0
  5. package/lib/commonjs/sdk/internaDelegatedState.js.map +1 -0
  6. package/lib/commonjs/sdk/nativeInterface.js +20 -0
  7. package/lib/commonjs/sdk/nativeInterface.js.map +1 -0
  8. package/lib/commonjs/sdk/types/constants.js +73 -0
  9. package/lib/commonjs/sdk/types/index.js +414 -0
  10. package/lib/commonjs/sdk/types/index.js.map +1 -0
  11. package/lib/commonjs/sdk/utils.js +156 -0
  12. package/lib/commonjs/sdk/utils.js.map +1 -0
  13. package/lib/commonjs/utils/index.js +17 -0
  14. package/lib/commonjs/utils/logError.js +21 -0
  15. package/lib/commonjs/utils/logError.js.map +1 -0
  16. package/lib/commonjs/wayfinding/components/MapView.js +389 -0
  17. package/lib/commonjs/wayfinding/components/MapView.js.map +1 -0
  18. package/lib/commonjs/wayfinding/hooks/index.js +233 -0
  19. package/lib/commonjs/wayfinding/hooks/index.js.map +1 -0
  20. package/lib/commonjs/wayfinding/index.js +57 -0
  21. package/lib/commonjs/wayfinding/store/index.js +247 -0
  22. package/lib/commonjs/wayfinding/store/index.js.map +1 -0
  23. package/lib/commonjs/wayfinding/store/utils.js +49 -0
  24. package/lib/commonjs/wayfinding/types/constants.js +13 -0
  25. package/lib/commonjs/wayfinding/types/index.js +6 -0
  26. package/lib/commonjs/wayfinding/types/index.js.map +1 -0
  27. package/lib/commonjs/wayfinding/utils/index.js +12 -0
  28. package/lib/commonjs/wayfinding/utils/mapper.js +204 -0
  29. package/lib/commonjs/wayfinding/utils/mapper.js.map +1 -0
  30. package/lib/module/index.js +14 -0
  31. package/lib/module/index.js.map +1 -0
  32. package/lib/module/sdk/index.js +894 -0
  33. package/lib/module/sdk/internaDelegatedState.js +43 -0
  34. package/lib/module/sdk/internaDelegatedState.js.map +1 -0
  35. package/lib/module/sdk/nativeInterface.js +20 -0
  36. package/lib/module/sdk/nativeInterface.js.map +1 -0
  37. package/lib/module/sdk/types/constants.js +70 -0
  38. package/lib/module/sdk/types/index.js +445 -0
  39. package/lib/module/sdk/types/index.js.map +1 -0
  40. package/lib/module/sdk/utils.js +146 -0
  41. package/lib/module/sdk/utils.js.map +1 -0
  42. package/lib/module/utils/index.js +4 -0
  43. package/lib/module/utils/logError.js +17 -0
  44. package/lib/module/utils/logError.js.map +1 -0
  45. package/lib/module/wayfinding/components/MapView.js +381 -0
  46. package/lib/module/wayfinding/components/MapView.js.map +1 -0
  47. package/lib/module/wayfinding/hooks/index.js +226 -0
  48. package/lib/module/wayfinding/hooks/index.js.map +1 -0
  49. package/lib/module/wayfinding/index.js +15 -0
  50. package/lib/module/wayfinding/store/index.js +213 -0
  51. package/lib/module/wayfinding/store/index.js.map +1 -0
  52. package/lib/module/wayfinding/store/utils.js +40 -0
  53. package/lib/module/wayfinding/types/constants.js +9 -0
  54. package/lib/module/wayfinding/types/index.js +4 -0
  55. package/lib/module/wayfinding/types/index.js.map +1 -0
  56. package/lib/module/wayfinding/utils/index.js +7 -0
  57. package/lib/module/wayfinding/utils/index.js.map +1 -0
  58. package/lib/module/wayfinding/utils/mapper.js +195 -0
  59. package/lib/module/wayfinding/utils/mapper.js.map +1 -0
  60. package/package.json +3 -3
@@ -0,0 +1,894 @@
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 { ErrorCode, ErrorType, InternalCall } from "./types";
9
+ import { InternalCallType, SdkNavigationUpdateType } from "./types/constants";
10
+ import { exceptionWrapper, locationErrorAdapter, locationStatusAdapter, promiseWrapper } from "./utils";
11
+ import { DelegatedStateManager } from "./internaDelegatedState";
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 "";
328
+ };
329
+
330
+ /**
331
+ * Returns the device identifier that has generated the location
332
+ */
333
+ static getDeviceId = () => {
334
+ return promiseWrapper(({
335
+ onSuccess,
336
+ onError
337
+ }) => {
338
+ RNCSitumPlugin.getDeviceId(response => {
339
+ //@ts-ignore
340
+ if (response?.deviceId) {
341
+ // Resolve with the actual deviceId
342
+ //@ts-ignore
343
+ onSuccess(response.deviceId);
344
+ } else {
345
+ // Reject if deviceId is not available in the response
346
+ onError({
347
+ code: ErrorCode.UNKNOWN,
348
+ message: "Couldn't get device ID",
349
+ type: ErrorType.CRITICAL
350
+ });
351
+ }
352
+ });
353
+ });
354
+ };
355
+
356
+ /**
357
+ * Downloads all the {@link Building}s for the current user.
358
+ */
359
+ static fetchBuildings = () => {
360
+ return promiseWrapper(({
361
+ onSuccess,
362
+ onError
363
+ }) => {
364
+ RNCSitumPlugin.fetchBuildings(onSuccess, onError);
365
+ });
366
+ };
367
+
368
+ /**
369
+ * Downloads all the building data for the selected building. This info includes
370
+ * {@link Floor}, indoor and outdoor {@link Poi}s, events and paths. Also it download floor
371
+ * maps and {@link PoiCategory} icons to local storage.
372
+ *
373
+ * @param building {@link Building}
374
+ */
375
+ static fetchBuildingInfo = building => {
376
+ return promiseWrapper(({
377
+ onSuccess,
378
+ onError
379
+ }) => {
380
+ RNCSitumPlugin.fetchBuildingInfo(building, onSuccess, onError);
381
+ });
382
+ };
383
+
384
+ /**
385
+ * (Experimental) Downloads the tiled-map of a certain building
386
+ *
387
+ * @param building {@link Building} whose tiles will be downloaded
388
+ */
389
+ static fetchTilesFromBuilding = building => {
390
+ return promiseWrapper(({
391
+ onSuccess,
392
+ onError
393
+ }) => {
394
+ RNCSitumPlugin.fetchTilesFromBuilding(building, onSuccess, onError);
395
+ });
396
+ };
397
+
398
+ /**
399
+ * Downloads all the floors of a building
400
+ *
401
+ * @param building {@link Building}
402
+ */
403
+ static fetchFloorsFromBuilding = building => {
404
+ return promiseWrapper(({
405
+ onSuccess,
406
+ onError
407
+ }) => {
408
+ RNCSitumPlugin.fetchFloorsFromBuilding(building, onSuccess, onError);
409
+ });
410
+ };
411
+
412
+ /**
413
+ * Downloads the map image of a {@link Floor}
414
+ *
415
+ * @param floor {@link Floor}
416
+ */
417
+ static fetchMapFromFloor = floor => {
418
+ return promiseWrapper(({
419
+ onSuccess,
420
+ onError
421
+ }) => {
422
+ RNCSitumPlugin.fetchMapFromFloor(floor, onSuccess, onError);
423
+ });
424
+ };
425
+
426
+ /**
427
+ * Get the geofences of a {@link Building}
428
+ *
429
+ * @param building {@link Building}
430
+ */
431
+ static fetchGeofencesFromBuilding = building => {
432
+ return promiseWrapper(({
433
+ onSuccess,
434
+ onError
435
+ }) => {
436
+ RNCSitumPlugin.fetchGeofencesFromBuilding(building, onSuccess, onError);
437
+ });
438
+ };
439
+
440
+ /**
441
+ * Get all {@link PoiCategory}, download and cache their icons asynchronously.
442
+ */
443
+ static fetchPoiCategories = () => {
444
+ return promiseWrapper(({
445
+ onSuccess,
446
+ onError
447
+ }) => {
448
+ RNCSitumPlugin.fetchPoiCategories(onSuccess, onError);
449
+ });
450
+ };
451
+
452
+ /**
453
+ * Get the normal {@link PoiIcon} for a category
454
+ *
455
+ * @param category {@link PoiCategory}. Not null.
456
+ */
457
+ static fetchPoiCategoryIconNormal = category => {
458
+ return promiseWrapper(({
459
+ onSuccess,
460
+ onError
461
+ }) => {
462
+ RNCSitumPlugin.fetchPoiCategoryIconNormal(category, onSuccess, onError);
463
+ });
464
+ };
465
+
466
+ /**
467
+ * Get the selected {@link PoiIcon} for a {@link PoiCategory}
468
+ *
469
+ * @param category {@link PoiCategory}. Not null.
470
+ */
471
+ static fetchPoiCategoryIconSelected = category => {
472
+ return promiseWrapper(({
473
+ onSuccess,
474
+ onError
475
+ }) => {
476
+ RNCSitumPlugin.fetchPoiCategoryIconSelected(category, onSuccess, onError);
477
+ });
478
+ };
479
+
480
+ /**
481
+ * Download the indoor {@link Poi}s of a {@link Building}
482
+ *
483
+ * @param building {@link Building}
484
+ */
485
+ static fetchIndoorPOIsFromBuilding = building => {
486
+ return promiseWrapper(({
487
+ onSuccess,
488
+ onError
489
+ }) => {
490
+ RNCSitumPlugin.fetchIndoorPOIsFromBuilding(building, onSuccess, onError);
491
+ });
492
+ };
493
+
494
+ /**
495
+ * Download the outdoor {@link Poi}s of a {@link Building}
496
+ *
497
+ * @param building {@link Building}
498
+ */
499
+ static fetchOutdoorPOIsFromBuilding = building => {
500
+ return promiseWrapper(({
501
+ onSuccess,
502
+ onError
503
+ }) => {
504
+ RNCSitumPlugin.fetchOutdoorPOIsFromBuilding(building, onSuccess, onError);
505
+ });
506
+ };
507
+
508
+ /**
509
+ * Starts positioning.
510
+ *
511
+ * @param {LocationRequest} locationRequest Positioning options to configure how positioning will behave
512
+ */
513
+ static requestLocationUpdates = locationRequest => {
514
+ return exceptionWrapper(() => {
515
+ if (SitumPlugin.positioningIsRunning()) return;
516
+ RNCSitumPlugin.startPositioning(locationRequest || {});
517
+ positioningRunning = true;
518
+ });
519
+ };
520
+
521
+ /**
522
+ * Stops positioning, removing all location updates
523
+ */
524
+ static removeLocationUpdates = () => {
525
+ return exceptionWrapper(() => {
526
+ if (!SitumPlugin.positioningIsRunning()) return;
527
+ RNCSitumPlugin.stopPositioning(response => {
528
+ if (response.success) {
529
+ positioningRunning = false;
530
+ } else {
531
+ throw "Situm > hook > Could not stop positioning";
532
+ }
533
+ });
534
+ });
535
+ };
536
+
537
+ /**
538
+ * Calculates a route between two points. The result is provided
539
+ * asynchronously using the callback.
540
+ *
541
+ * @param building {@link Building}
542
+ * @param from {@link Point} route origin
543
+ * @param to {@link Point} route destination
544
+ * @param directionOptions {@link DirectionsOptions}
545
+ */
546
+ static requestDirections = (building, from, to, directionOptions) => {
547
+ return promiseWrapper(({
548
+ onSuccess,
549
+ onError
550
+ }) => {
551
+ const params = [building, from, to, directionOptions || {}];
552
+ RNCSitumPlugin.requestDirections(params, onSuccess, onError);
553
+ });
554
+ };
555
+
556
+ /**
557
+ * Set the navigation params, and the listener that receives the updated
558
+ * navigation progress.
559
+ *
560
+ * Can only exist one navigation with one listener at a time. If this method was
561
+ * previously invoked, but removeLocationUpdates() wasn't, removeLocationUpdates()
562
+ * is called internally.
563
+ *
564
+ * @param options {@link NavigationRequest}
565
+ */
566
+ static requestNavigationUpdates = options => {
567
+ return exceptionWrapper(() => {
568
+ RNCSitumPlugin.requestNavigationUpdates(options || {});
569
+ navigationRunning = true;
570
+ });
571
+ };
572
+
573
+ /**
574
+ * Informs NavigationManager object the change of the user's location
575
+ *
576
+ * @param location new {@link Location} of the user. If null, nothing is done
577
+ */
578
+ static updateNavigationWithLocation = location => {
579
+ return exceptionWrapper(({
580
+ onSuccess,
581
+ onError
582
+ }) => {
583
+ if (!SitumPlugin.navigationIsRunning()) {
584
+ throw "Situm > hook > No active navigation";
585
+ }
586
+ RNCSitumPlugin.updateNavigationWithLocation(location, onSuccess, onError);
587
+ });
588
+ };
589
+
590
+ /**
591
+ * Removes all location updates. This removes the internal state of the manager,
592
+ * including the listener provided in requestNavigationUpdates(NavigationRequest,
593
+ * NavigationListener), so it won't receive more progress updates.
594
+ *
595
+ */
596
+ static removeNavigationUpdates = () => {
597
+ return promiseWrapper(({
598
+ onCallback
599
+ }) => {
600
+ if (!SitumPlugin.navigationIsRunning()) return;
601
+ navigationRunning = false;
602
+ RNCSitumPlugin.removeNavigationUpdates(response => {
603
+ onCallback(response, "Failed to remove navigation updates");
604
+ });
605
+ });
606
+ };
607
+
608
+ /**
609
+ * Requests a real time devices positions
610
+ *
611
+ * @param realtimeUpdates callback to use when new device positions are updated
612
+ * @param error callback to use when an error on navigation udpates raises
613
+ * @param options Represents the configuration for getting realtime devices positions in
614
+ */
615
+
616
+ static requestRealTimeUpdates = (realtimeUpdates, error, options) => {
617
+ return exceptionWrapper(() => {
618
+ RNCSitumPlugin.requestRealTimeUpdates(options || {});
619
+ realtimeSubscriptions.push([SitumPluginEventEmitter.addListener("realtimeUpdated", realtimeUpdates), error ? SitumPluginEventEmitter.addListener("realtimeError", error || logError) : null]);
620
+ });
621
+ };
622
+
623
+ /**
624
+ * Removes all real time updates listners.
625
+ *
626
+ * @param _callback
627
+ */
628
+ static removeRealTimeUpdates = _callback => {
629
+ return exceptionWrapper(() => {
630
+ realtimeSubscriptions = [];
631
+ RNCSitumPlugin.removeRealTimeUpdates();
632
+ });
633
+ };
634
+
635
+ /**
636
+ * Checks if a point is inside a {@link Geofence}
637
+ *
638
+ */
639
+ static checkIfPointInsideGeofence = (request, callback) => {
640
+ RNCSitumPlugin.checkIfPointInsideGeofence(request, callback || (() => {}));
641
+ };
642
+
643
+ /**
644
+ * Automatically assists users in resolving app-related permission and sensor issues.
645
+ *
646
+ * This method tells the native SDKs to present a user interface that explains detected
647
+ * configuration issues and guides users through the required steps to resolve them,
648
+ * following best practices for runtime permission requests.
649
+ *
650
+ * Issues addressed include:
651
+ * - Missing permissions for Location or Bluetooth.
652
+ * - Disabled Location or Bluetooth sensors.
653
+ *
654
+ * Use the <code>userHelperOptions</code> parameter to configure the available options.
655
+ * Call {@link enableUserHelper} as a shortcut to enable the user helper with default configuration.
656
+ * Call {@link disableUserHelper} as a shortcut to disable the user helper.
657
+ *
658
+ * @param {UserHelperOptions} userHelperOptions - Options for the user helper.
659
+ */
660
+ static configureUserHelper = userHelperOptions => {
661
+ _registerCallbacks();
662
+ return exceptionWrapper(({
663
+ onSuccess,
664
+ onError
665
+ }) => {
666
+ RNCSitumPlugin.configureUserHelper(userHelperOptions, onSuccess, onError);
667
+ });
668
+ };
669
+
670
+ /**
671
+ * Enables the user helper.
672
+ *
673
+ * Shortcut for {@link configureUserHelper} with <code>{enabled: true}</code>.
674
+ */
675
+ static enableUserHelper = () => {
676
+ SitumPlugin.configureUserHelper({
677
+ enabled: true,
678
+ colorScheme: undefined
679
+ });
680
+ };
681
+
682
+ /**
683
+ * Disables the user helper.
684
+ *
685
+ * Shortcut for {@link configureUserHelper} with <code>{enabled: false}</code>.
686
+ *
687
+ */
688
+ static disableUserHelper = () => {
689
+ SitumPlugin.configureUserHelper({
690
+ enabled: false,
691
+ colorScheme: undefined
692
+ });
693
+ };
694
+
695
+ /**
696
+ * INTERNAL METHOD.
697
+ *
698
+ * Update SDK with the viewer navigation states.
699
+ * Do not use this method as it is intended for internal use
700
+ * by the map viewer module.
701
+ *
702
+ * @param externalNavigation
703
+ */
704
+ static updateNavigationState = externalNavigation => {
705
+ return exceptionWrapper(() => {
706
+ RNCSitumPlugin.updateNavigationState(externalNavigation);
707
+ });
708
+ };
709
+
710
+ /**
711
+ * INTERNAL METHOD.
712
+ *
713
+ * Validate if the mapView internal settings have been properly configured
714
+ * Do not use this method as it is intended for internal use
715
+ * by the map viewer module.
716
+ *
717
+ * @param validateMapViewProjectSettings
718
+ */
719
+ static validateMapViewProjectSettings = () => {
720
+ if (Platform.OS === "ios") {
721
+ return exceptionWrapper(() => {
722
+ RNCSitumPlugin.validateMapViewProjectSettings();
723
+ });
724
+ }
725
+ };
726
+
727
+ /**
728
+ * INTERNAL METHOD.
729
+ *
730
+ * Set a native MethodCall delegate. Do not use this method as it is intended for internal use by the map viewer module.
731
+ * @param callback
732
+ */
733
+ static internalSetMethodCallMapDelegate = callback => {
734
+ internalMethodCallMapDelegate = callback;
735
+ const lastValues = DelegatedStateManager.getInstance().getValues();
736
+ // Forward last received values as soon as possible:
737
+ if (lastValues.location) {
738
+ internalMethodCallMapDelegate(new InternalCall(InternalCallType.LOCATION, lastValues.location));
739
+ }
740
+ if (lastValues.status) {
741
+ internalMethodCallMapDelegate(new InternalCall(InternalCallType.LOCATION_STATUS, lastValues.status));
742
+ }
743
+ if (lastValues.error) {
744
+ internalMethodCallMapDelegate(new InternalCall(InternalCallType.LOCATION_ERROR, lastValues.error));
745
+ }
746
+ };
747
+
748
+ //-----------------------------------------------------------------------------//
749
+ //-----------------------------GEOFENCES CALLBACKS-----------------------------//
750
+ //-----------------------------------------------------------------------------//
751
+
752
+ /**
753
+ * Callback that notifies when the user enters a {@link Geofence}.
754
+ *
755
+ * In order to use correctly these callbacks you must know the following:
756
+ * - Positioning geofences (with trainer_metadata custom field) won't be notified.
757
+ * - These callbacks only work with indoor locations. Any outdoor location will
758
+ * produce a call to onExitedGeofences with the last positioned geofences as argument.
759
+ *
760
+ * @param callback the function called when the user enters a {@link Geofence}
761
+ */
762
+ static onEnterGeofences = callback => {
763
+ RNCSitumPlugin.onEnterGeofences();
764
+ // Adopts SDK behavior (setter):
765
+ enterGeofencesCallback = callback;
766
+ };
767
+
768
+ /**
769
+ * Callback that notifies when the user exits a {@link Geofence}.
770
+ *
771
+ * In order to use correctly these callbacks you must know the following:
772
+ * - Positioning geofences (with trainer_metadata custom field) won't be notified.
773
+ * - These callbacks only work with indoor locations. Any outdoor location will
774
+ * produce a call to onExitedGeofences with the last positioned geofences as argument.
775
+ *
776
+ * @param callback the function called when the user exits a {@link Geofence}
777
+ */
778
+ static onExitGeofences = callback => {
779
+ RNCSitumPlugin.onExitGeofences();
780
+ exitGeofencesCallback = callback;
781
+ };
782
+
783
+ //-----------------------------------------------------------------------------//
784
+ //-----------------------------LOCATION CALLBACKS------------------------------//
785
+ //-----------------------------------------------------------------------------//
786
+
787
+ /**
788
+ * Callback that notifies when the user {@link Location} changes.
789
+ *
790
+ * @param callback the function called when the user {@link Location} changes
791
+ */
792
+ static onLocationUpdate = callback => {
793
+ locationCallback = callback;
794
+ };
795
+
796
+ /**
797
+ * Callback that notifies when the user {@link LocationStatus} changes.
798
+ *
799
+ * @param callback the function called when the user {@link LocationStatus} changes
800
+ */
801
+ static onLocationStatus = callback => {
802
+ locationStatusCallback = callback;
803
+ };
804
+
805
+ /**
806
+ * Callback that notifies when there is an error while the user is positioining.
807
+ *
808
+ * @param callback the function called when there is an error
809
+ */
810
+ static onLocationError = callback => {
811
+ locationErrorCallback = callback;
812
+ };
813
+
814
+ /**
815
+ * Callback that notifies when the user stops positioning.
816
+ *
817
+ * @param callback the function called when the user stops positioning.
818
+ */
819
+ static onLocationStopped = callback => {
820
+ locationStoppedCallback = callback;
821
+ };
822
+
823
+ //-----------------------------------------------------------------------------//
824
+ //-----------------------------NAVIGATION CALLBACKS----------------------------//
825
+ //-----------------------------------------------------------------------------//
826
+
827
+ /**
828
+ * Callback that notifies when navigation starts.
829
+ *
830
+ * @param callback a function that returns the initial {@link Route} by parameters.
831
+ */
832
+ static onNavigationStart = callback => {
833
+ navigationStartedCallback = callback;
834
+ };
835
+
836
+ /**
837
+ * Callback that notifies every progress the user makes while navigating.
838
+ *
839
+ * @param callback a function that returns the {@link NavigationProgress} by parameters.
840
+ */
841
+ static onNavigationProgress = callback => {
842
+ navigationProgressCallback = callback;
843
+ };
844
+
845
+ /**
846
+ * Callback that notifies when the user reaches the destination POI.
847
+ *
848
+ * @param callback a function that returns the completed {@link Route} by parameters.
849
+ */
850
+ static onNavigationDestinationReached = callback => {
851
+ navigationDestinationReachedCallback = callback;
852
+ };
853
+
854
+ /**
855
+ * Callback that notifies when the user gets out of the current route.
856
+ *
857
+ * @param callback the function called when the user gets out of the current route.
858
+ */
859
+ static onNavigationOutOfRoute = callback => {
860
+ navigationOutOfRouteCallback = callback;
861
+ };
862
+
863
+ /**
864
+ * @deprecated
865
+ * DEPRECATED: Use instead onNavigationCancellation()
866
+ * and onNavigationDestinationReached() to determine why did the navigation end.
867
+ *
868
+ * Callback that notifies when the user finishes the route.
869
+ *
870
+ * @param callback the function called when the user finishes the route.
871
+ */
872
+ static onNavigationFinished = callback => {
873
+ navigationFinishedCallback = callback;
874
+ };
875
+
876
+ /**
877
+ * Callback that notifies when the user does cancel the navigation.
878
+ *
879
+ * @param callback the function called when the user cancels the navigation.
880
+ */
881
+ static onNavigationCancellation = callback => {
882
+ navigationCancellationCallback = callback;
883
+ };
884
+
885
+ /**
886
+ * Callback that notifies when there is an error during navigation.
887
+ *
888
+ * @param callback the function called when there is an error during navigation.
889
+ */
890
+ static onNavigationError = callback => {
891
+ navigationErrorCallback = callback;
892
+ };
893
+ }
894
+ //# sourceMappingURL=index.js.map