@situm/react-native 3.0.0-beta.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 (147) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +656 -0
  3. package/ReactNativeSitumPlugin.podspec +22 -0
  4. package/SECURITY-POLICY.md +9 -0
  5. package/android/.gradle/5.6.4/fileChanges/last-build.bin +0 -0
  6. package/android/.gradle/5.6.4/fileHashes/fileHashes.lock +0 -0
  7. package/android/.gradle/5.6.4/gc.properties +0 -0
  8. package/android/.idea/.name +1 -0
  9. package/android/.idea/codeStyles/Project.xml +116 -0
  10. package/android/.idea/encodings.xml +6 -0
  11. package/android/.idea/misc.xml +31 -0
  12. package/android/.idea/sonarlint/issuestore/index.pb +15 -0
  13. package/android/.project +34 -0
  14. package/android/build.gradle +45 -0
  15. package/android/gradle/wrapper/gradle-wrapper.jar +0 -0
  16. package/android/gradle/wrapper/gradle-wrapper.properties +6 -0
  17. package/android/gradlew +172 -0
  18. package/android/gradlew.bat +84 -0
  19. package/android/src/main/AndroidManifest.xml +6 -0
  20. package/android/src/main/java/com/situm/plugin/PluginHelper.java +989 -0
  21. package/android/src/main/java/com/situm/plugin/SitumMapper.java +1206 -0
  22. package/android/src/main/java/com/situm/plugin/SitumPackage.java +29 -0
  23. package/android/src/main/java/com/situm/plugin/SitumPlugin.java +84 -0
  24. package/android/src/main/java/com/situm/plugin/SitumPluginImpl.java +344 -0
  25. package/android/src/main/java/com/situm/plugin/utils/ReactNativeJson.java +122 -0
  26. package/android/src/main/res/mipmap-hdpi/ic_launcher.png +0 -0
  27. package/android/src/main/res/mipmap-hdpi/ic_launcher_round.png +0 -0
  28. package/android/src/main/res/mipmap-mdpi/ic_launcher.png +0 -0
  29. package/android/src/main/res/mipmap-mdpi/ic_launcher_round.png +0 -0
  30. package/android/src/main/res/mipmap-xhdpi/ic_launcher.png +0 -0
  31. package/android/src/main/res/mipmap-xhdpi/ic_launcher_round.png +0 -0
  32. package/android/src/main/res/mipmap-xxhdpi/ic_launcher.png +0 -0
  33. package/android/src/main/res/mipmap-xxhdpi/ic_launcher_round.png +0 -0
  34. package/android/src/main/res/mipmap-xxxhdpi/ic_launcher.png +0 -0
  35. package/android/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png +0 -0
  36. package/android/src/main/res/values/strings.xml +3 -0
  37. package/android/src/main/res/values/styles.xml +9 -0
  38. package/ios/Constants.h +14 -0
  39. package/ios/Constants.m +14 -0
  40. package/ios/RNSitumReactNativePlugin.xcodeproj/project.pbxproj +272 -0
  41. package/ios/SitumLocationWrapper.h +112 -0
  42. package/ios/SitumLocationWrapper.m +1132 -0
  43. package/ios/SitumPlugin.h +15 -0
  44. package/ios/SitumPlugin.m +911 -0
  45. package/lib/commonjs/index.js +25 -0
  46. package/lib/commonjs/index.js.map +1 -0
  47. package/lib/commonjs/sdk/index.js +399 -0
  48. package/lib/commonjs/sdk/index.js.map +1 -0
  49. package/lib/commonjs/sdk/nativeInterface.js +20 -0
  50. package/lib/commonjs/sdk/nativeInterface.js.map +1 -0
  51. package/lib/commonjs/sdk/types/index.d.js +6 -0
  52. package/lib/commonjs/sdk/types/index.d.js.map +1 -0
  53. package/lib/commonjs/sdk/utils.js +22 -0
  54. package/lib/commonjs/sdk/utils.js.map +1 -0
  55. package/lib/commonjs/utils/requestPermission.js +73 -0
  56. package/lib/commonjs/utils/requestPermission.js.map +1 -0
  57. package/lib/commonjs/wayfinding/components/MapView.js +220 -0
  58. package/lib/commonjs/wayfinding/components/MapView.js.map +1 -0
  59. package/lib/commonjs/wayfinding/hooks/index.js +401 -0
  60. package/lib/commonjs/wayfinding/hooks/index.js.map +1 -0
  61. package/lib/commonjs/wayfinding/index.js +45 -0
  62. package/lib/commonjs/wayfinding/index.js.map +1 -0
  63. package/lib/commonjs/wayfinding/store/index.js +237 -0
  64. package/lib/commonjs/wayfinding/store/index.js.map +1 -0
  65. package/lib/commonjs/wayfinding/store/utils.js +44 -0
  66. package/lib/commonjs/wayfinding/store/utils.js.map +1 -0
  67. package/lib/commonjs/wayfinding/styles/colors.js +18 -0
  68. package/lib/commonjs/wayfinding/styles/colors.js.map +1 -0
  69. package/lib/commonjs/wayfinding/types/index.d.js +6 -0
  70. package/lib/commonjs/wayfinding/types/index.d.js.map +1 -0
  71. package/lib/commonjs/wayfinding/utils/index.js +11 -0
  72. package/lib/commonjs/wayfinding/utils/index.js.map +1 -0
  73. package/lib/commonjs/wayfinding/utils/mapper.js +106 -0
  74. package/lib/commonjs/wayfinding/utils/mapper.js.map +1 -0
  75. package/lib/module/index.js +6 -0
  76. package/lib/module/index.js.map +1 -0
  77. package/lib/module/sdk/index.js +390 -0
  78. package/lib/module/sdk/index.js.map +1 -0
  79. package/lib/module/sdk/nativeInterface.js +18 -0
  80. package/lib/module/sdk/nativeInterface.js.map +1 -0
  81. package/lib/module/sdk/types/index.d.js +2 -0
  82. package/lib/module/sdk/types/index.d.js.map +1 -0
  83. package/lib/module/sdk/utils.js +15 -0
  84. package/lib/module/sdk/utils.js.map +1 -0
  85. package/lib/module/utils/requestPermission.js +67 -0
  86. package/lib/module/utils/requestPermission.js.map +1 -0
  87. package/lib/module/wayfinding/components/MapView.js +207 -0
  88. package/lib/module/wayfinding/components/MapView.js.map +1 -0
  89. package/lib/module/wayfinding/hooks/index.js +392 -0
  90. package/lib/module/wayfinding/hooks/index.js.map +1 -0
  91. package/lib/module/wayfinding/index.js +12 -0
  92. package/lib/module/wayfinding/index.js.map +1 -0
  93. package/lib/module/wayfinding/store/index.js +202 -0
  94. package/lib/module/wayfinding/store/index.js.map +1 -0
  95. package/lib/module/wayfinding/store/utils.js +34 -0
  96. package/lib/module/wayfinding/store/utils.js.map +1 -0
  97. package/lib/module/wayfinding/styles/colors.js +11 -0
  98. package/lib/module/wayfinding/styles/colors.js.map +1 -0
  99. package/lib/module/wayfinding/types/index.d.js +2 -0
  100. package/lib/module/wayfinding/types/index.d.js.map +1 -0
  101. package/lib/module/wayfinding/utils/index.js +4 -0
  102. package/lib/module/wayfinding/utils/index.js.map +1 -0
  103. package/lib/module/wayfinding/utils/mapper.js +100 -0
  104. package/lib/module/wayfinding/utils/mapper.js.map +1 -0
  105. package/lib/typescript/src/index.d.ts +4 -0
  106. package/lib/typescript/src/index.d.ts.map +1 -0
  107. package/lib/typescript/src/sdk/index.d.ts +269 -0
  108. package/lib/typescript/src/sdk/index.d.ts.map +1 -0
  109. package/lib/typescript/src/sdk/nativeInterface.d.ts +2 -0
  110. package/lib/typescript/src/sdk/nativeInterface.d.ts.map +1 -0
  111. package/lib/typescript/src/sdk/utils.d.ts +7 -0
  112. package/lib/typescript/src/sdk/utils.d.ts.map +1 -0
  113. package/lib/typescript/src/utils/requestPermission.d.ts +3 -0
  114. package/lib/typescript/src/utils/requestPermission.d.ts.map +1 -0
  115. package/lib/typescript/src/wayfinding/components/MapView.d.ts +36 -0
  116. package/lib/typescript/src/wayfinding/components/MapView.d.ts.map +1 -0
  117. package/lib/typescript/src/wayfinding/hooks/index.d.ts +53 -0
  118. package/lib/typescript/src/wayfinding/hooks/index.d.ts.map +1 -0
  119. package/lib/typescript/src/wayfinding/index.d.ts +5 -0
  120. package/lib/typescript/src/wayfinding/index.d.ts.map +1 -0
  121. package/lib/typescript/src/wayfinding/store/index.d.ts +103 -0
  122. package/lib/typescript/src/wayfinding/store/index.d.ts.map +1 -0
  123. package/lib/typescript/src/wayfinding/store/utils.d.ts +9 -0
  124. package/lib/typescript/src/wayfinding/store/utils.d.ts.map +1 -0
  125. package/lib/typescript/src/wayfinding/styles/colors.d.ts +8 -0
  126. package/lib/typescript/src/wayfinding/styles/colors.d.ts.map +1 -0
  127. package/lib/typescript/src/wayfinding/utils/index.d.ts +3 -0
  128. package/lib/typescript/src/wayfinding/utils/index.d.ts.map +1 -0
  129. package/lib/typescript/src/wayfinding/utils/mapper.d.ts +17 -0
  130. package/lib/typescript/src/wayfinding/utils/mapper.d.ts.map +1 -0
  131. package/package.json +130 -0
  132. package/security.txt +4 -0
  133. package/src/index.ts +6 -0
  134. package/src/sdk/index.ts +656 -0
  135. package/src/sdk/nativeInterface.ts +18 -0
  136. package/src/sdk/types/index.d.ts +718 -0
  137. package/src/sdk/utils.ts +16 -0
  138. package/src/utils/requestPermission.ts +94 -0
  139. package/src/wayfinding/components/MapView.tsx +312 -0
  140. package/src/wayfinding/hooks/index.ts +539 -0
  141. package/src/wayfinding/index.tsx +11 -0
  142. package/src/wayfinding/store/index.tsx +254 -0
  143. package/src/wayfinding/store/utils.ts +40 -0
  144. package/src/wayfinding/styles/colors.tsx +6 -0
  145. package/src/wayfinding/types/index.d.ts +56 -0
  146. package/src/wayfinding/utils/index.ts +5 -0
  147. package/src/wayfinding/utils/mapper.ts +129 -0
@@ -0,0 +1,656 @@
1
+ /* eslint-disable @typescript-eslint/no-explicit-any */
2
+ /* eslint-disable @typescript-eslint/ban-types */
3
+ import invariant from "invariant";
4
+ import { NativeEventEmitter, NativeModules, Platform } from "react-native";
5
+
6
+ import packageJson from "../../package.json";
7
+ import type {
8
+ Building,
9
+ DirectionPoint,
10
+ DirectionsOptions,
11
+ Floor,
12
+ LocationRequestOptions,
13
+ } from "./types/index.d.ts";
14
+ import { logError } from "./utils";
15
+
16
+ const LINKING_ERROR =
17
+ `The package 'situm-react-native-plugin' doesn't seem to be linked. Make sure: \n\n` +
18
+ Platform.select({ ios: "- You have run 'pod install'\n", default: "" }) +
19
+ "- You rebuilt the app after installing the package\n" +
20
+ "- You are not using Expo managed workflow\n";
21
+
22
+ const RNCSitumPlugin = NativeModules.RNCSitumPlugin
23
+ ? NativeModules.RNCSitumPlugin
24
+ : new Proxy(
25
+ {},
26
+ {
27
+ get() {
28
+ throw new Error(LINKING_ERROR);
29
+ },
30
+ }
31
+ );
32
+
33
+ const SitumPluginEventEmitter = new NativeEventEmitter(RNCSitumPlugin);
34
+
35
+ let positioningSubscriptions = [];
36
+ let navigationSubscriptions = [];
37
+ let realtimeSubscriptions = [];
38
+
39
+ export default {
40
+ /**
41
+ * Initializes SDK.
42
+ *
43
+ * You have to call this function prior any call to other method.
44
+ * This method can be safely called many times as it will only initialise the SDK
45
+ * if it is not already initialised.
46
+ */
47
+ initSitumSDK: function (): void {
48
+ RNCSitumPlugin.initSitumSDK();
49
+ },
50
+
51
+ /**
52
+ * Provides your API key to the Situm SDK.
53
+ *
54
+ * This key is generated for your application in the Dashboard.
55
+ * Old credentials will be removed.
56
+ *
57
+ * @param email user's email.
58
+ * @param apiKey user's apikey.
59
+ * @param onSuccess callback to use when the function returns successfully
60
+ */
61
+ setApiKey: function (
62
+ email: string,
63
+ apiKey: string,
64
+ onSuccess?: Function
65
+ ): void {
66
+ RNCSitumPlugin.setApiKey(email, apiKey, onSuccess);
67
+ },
68
+
69
+ /**
70
+ * Provides user's email and password. This credentials will be used to obtain a
71
+ * valid user token to authenticate the server request, when necessary. Token
72
+ * obtaining is not necessary done when this method is executed. Old credentials
73
+ * will be removed.
74
+ *
75
+ * @param email user's email.
76
+ * @param password user's password.
77
+ * @param onSuccess callback to use when the function returns successfully
78
+ */
79
+ setUserPass: function (
80
+ email: string,
81
+ password: string,
82
+ onSuccess?: Function
83
+ ): void {
84
+ RNCSitumPlugin.setUserPass(email, password, onSuccess);
85
+ },
86
+
87
+ setDashboardURL: function (url: string, success: Function): void {
88
+ RNCSitumPlugin.setDashboardURL(url, success);
89
+ },
90
+
91
+ /**
92
+ * Set to true if you want the SDK to download the configuration from the Situm API
93
+ * and use it by default. Right now it only affects the LocationRequest.
94
+ * Default value is true from SDK version 2.83.5
95
+ *
96
+ * @param useRemoteConfig boolean
97
+ * @param success function called on sucess
98
+ */
99
+ setUseRemoteConfig(useRemoteConfig: string, onSuccess?: Function): void {
100
+ RNCSitumPlugin.setUseRemoteConfig(useRemoteConfig, onSuccess);
101
+ },
102
+
103
+ /**
104
+ * Sets the maximum age of a cached response. If the cache response's age exceeds
105
+ * maxAge, it will not be used and a network request will be made.
106
+ *
107
+ * @param cacheAge a non-negative integer
108
+ * @param success function called on success
109
+ */
110
+ setCacheMaxAge: function (cacheAge: number, success?: Function): void {
111
+ RNCSitumPlugin.setCacheMaxAge(cacheAge, success);
112
+ },
113
+
114
+ /**
115
+ * Invalidate all the resources in the cache
116
+ */
117
+ invalidateCache: function (): void {
118
+ RNCSitumPlugin.invalidateCache();
119
+ },
120
+
121
+ /**
122
+ * Gets the list of versions for the current plugin and environment
123
+ *
124
+ * @param callback callback to use on success
125
+ */
126
+ sdkVersions: function (
127
+ callback: (event: {
128
+ ios?: string;
129
+ android?: string;
130
+ react_native: string;
131
+ }) => void
132
+ ): void {
133
+ const versions: { react_native: string; ios?: string; android?: string } = {
134
+ react_native: packageJson.version,
135
+ };
136
+
137
+ if (Platform.OS === "ios") {
138
+ versions.ios = packageJson.sdkVersions.ios;
139
+ } else {
140
+ versions.android = packageJson.sdkVersions.android;
141
+ }
142
+
143
+ callback(versions);
144
+ },
145
+
146
+ /**
147
+ * Returns the device identifier that has generated the location
148
+ *
149
+ * @param callback function called on sucess, returns the id of the current device
150
+ */
151
+ getDeviceId: function (callback: Function): void {
152
+ RNCSitumPlugin.getDeviceId(callback);
153
+ },
154
+
155
+ /**
156
+ * Request authorization for the provided authentication
157
+ * and stores it internally for subsequent requests
158
+ */
159
+ requestAuthorization: function (): void {
160
+ RNCSitumPlugin.requestAuthorization();
161
+ },
162
+
163
+ /**
164
+ * Download all the buildings for the current user
165
+ *
166
+ * @param success function called on sucess, returns a list of Building objects
167
+ * @param error function called on failure, returns an error string
168
+ */
169
+ fetchBuildings: function (success: Function, error?: Function): void {
170
+ invariant(
171
+ typeof success === "function",
172
+ "Must provide a valid success callback."
173
+ );
174
+
175
+ RNCSitumPlugin.fetchBuildings(success, error || logError);
176
+ },
177
+
178
+ /**
179
+ * Download all the building data for the selected building. This info includes
180
+ * floors, indoor and outdoor POIs, events and paths. Also it download floor
181
+ * maps and POI category icons to local storage.
182
+ *
183
+ * @param building
184
+ * @param success function called on sucess, returns a list of Building objects
185
+ * @param error function called on failure, returns an error string
186
+ */
187
+ fetchBuildingInfo: function (
188
+ building: Building,
189
+ success: Function,
190
+ error?: Function
191
+ ): void {
192
+ invariant(
193
+ typeof success === "function",
194
+ "Must provide a valid success callback."
195
+ );
196
+
197
+ RNCSitumPlugin.fetchBuildingInfo(building, success, error || logError);
198
+ },
199
+
200
+ fetchTilesFromBuilding: function (
201
+ building: Building,
202
+ success: Function,
203
+ error?: Function
204
+ ) {
205
+ invariant(
206
+ typeof success === "function",
207
+ "Must provide a valid success callback."
208
+ );
209
+ RNCSitumPlugin.fetchTilesFromBuilding(building, success, error || logError);
210
+ },
211
+
212
+ /**
213
+ * Download all the floors of a building
214
+ *
215
+ * @param building
216
+ * @param success function called on sucess, returns a list of Floor objects
217
+ * @param error function called on failure, returns an error string
218
+ */
219
+ fetchFloorsFromBuilding: function (
220
+ building: Building,
221
+ success: Function,
222
+ error?: Function
223
+ ): void {
224
+ invariant(
225
+ typeof success === "function",
226
+ "Must provide a valid success callback."
227
+ );
228
+
229
+ RNCSitumPlugin.fetchFloorsFromBuilding(
230
+ building,
231
+ success,
232
+ error || logError
233
+ );
234
+ },
235
+
236
+ /**
237
+ * Download the map image of a floor
238
+ *
239
+ * @param floor the floor object. Not null.
240
+ * @param success function called on sucess, returns a list of Map url objects
241
+ * @param error function called on failure, returns an error string
242
+ */
243
+ fetchMapFromFloor: function (
244
+ floor: Floor,
245
+ success: Function,
246
+ error?: Function
247
+ ): void {
248
+ invariant(
249
+ typeof success === "function",
250
+ "Must provide a valid success callback."
251
+ );
252
+
253
+ RNCSitumPlugin.fetchMapFromFloor(floor, success, error || logError);
254
+ },
255
+
256
+ /**
257
+ * Get the geofences of a building
258
+ *
259
+ * @param building
260
+ * @param success function called on sucess, returns a list of Building objects
261
+ * @param error function called on failure, returns an error string
262
+ */
263
+ fetchGeofencesFromBuilding: function (
264
+ building: Building,
265
+ success: Function,
266
+ error?: Function
267
+ ): void {
268
+ invariant(
269
+ typeof success === "function",
270
+ "Must provide a valid success callback."
271
+ );
272
+
273
+ RNCSitumPlugin.fetchGeofencesFromBuilding(
274
+ building,
275
+ success,
276
+ error || logError
277
+ );
278
+ },
279
+
280
+ /**
281
+ * Get all POI categories, download and cache their icons asynchronously.
282
+ *
283
+ * @param success function called on sucess, returns a list of POI categories
284
+ * @param error function called on failure, returns an error string
285
+ */
286
+ fetchPoiCategories: function (success: Function, error?: Function) {
287
+ invariant(
288
+ typeof success === "function",
289
+ "Must provide a valid success callback."
290
+ );
291
+
292
+ RNCSitumPlugin.fetchPoiCategories(success, error || logError);
293
+ },
294
+
295
+ /**
296
+ * Get the normal category icon for a category
297
+ *
298
+ * @param category the category. Not null.
299
+ * @param success function called on sucess, returns the icon in normal state.
300
+ * @param error function called on failure, returns an error string
301
+ */
302
+ fetchPoiCategoryIconNormal: function (
303
+ category: any,
304
+ success: Function,
305
+ error?: Function
306
+ ): void {
307
+ invariant(
308
+ typeof success === "function",
309
+ "Must provide a valid success callback."
310
+ );
311
+
312
+ RNCSitumPlugin.fetchPoiCategoryIconNormal(
313
+ category,
314
+ success,
315
+ error || logError
316
+ );
317
+ },
318
+
319
+ /**
320
+ * Get the selected category icon for a category
321
+ *
322
+ * @param category the category. Not null.
323
+ * @param success function called on sucess, returns the icon in selected state.
324
+ * @param error function called on failure, returns an error string
325
+ */
326
+ fetchPoiCategoryIconSelected: function (
327
+ category: any,
328
+ success: Function,
329
+ error?: Function
330
+ ): void {
331
+ invariant(
332
+ typeof success === "function",
333
+ "Must provide a valid success callback."
334
+ );
335
+
336
+ RNCSitumPlugin.fetchPoiCategoryIconSelected(
337
+ category,
338
+ success,
339
+ error || logError
340
+ );
341
+ },
342
+
343
+ /**
344
+ * Download the indoor POIs of a building
345
+ *
346
+ * @param building
347
+ * @param success function called on sucess, returns a list of POI objects
348
+ * @param error function called on failure, returns an error string
349
+ */
350
+ fetchIndoorPOIsFromBuilding: function (
351
+ building: any,
352
+ success: Function,
353
+ error?: Function
354
+ ): void {
355
+ invariant(
356
+ typeof success === "function",
357
+ "Must provide a valid success callback."
358
+ );
359
+
360
+ RNCSitumPlugin.fetchIndoorPOIsFromBuilding(
361
+ building,
362
+ success,
363
+ error || logError
364
+ );
365
+ },
366
+
367
+ /**
368
+ * Download the outdoor POIs of a building
369
+ *
370
+ * @param building
371
+ * @param success function called on sucess, returns a list of POI objects
372
+ * @param error function called on failure, returns an error string
373
+ */
374
+ fetchOutdoorPOIsFromBuilding: function (
375
+ building: any,
376
+ success: Function,
377
+ error?: Function
378
+ ): void {
379
+ invariant(
380
+ typeof success === "function",
381
+ "Must provide a valid success callback."
382
+ );
383
+
384
+ RNCSitumPlugin.fetchOutdoorPOIsFromBuilding(
385
+ building,
386
+ success,
387
+ error || logError
388
+ );
389
+ },
390
+
391
+ /**
392
+ * Download the events of a building
393
+ *
394
+ * @param building
395
+ * @param success Callback to asynchronously receive the events of a building. Not null.
396
+ * @param error function called on failure, returns an error string
397
+ */
398
+ fetchEventsFromBuilding: function (
399
+ building: any,
400
+ success: Function,
401
+ error?: Function
402
+ ): void {
403
+ invariant(
404
+ typeof success === "function",
405
+ "Must provide a valid success callback."
406
+ );
407
+
408
+ RNCSitumPlugin.fetchEventsFromBuilding(
409
+ building,
410
+ success,
411
+ error || logError
412
+ );
413
+ },
414
+
415
+ /**
416
+ * Starts positioning with the configuration specified by the LocationRequest;
417
+ * computed geolocations, status codes and errors will be received through the LocationListener callbacks.
418
+ * You may call this method more than once, with the following effect:
419
+ *
420
+ * - If you provide a new LocationRequest instance, positioning will be re-started
421
+ * with the new positioning options specified by this new instance.
422
+ * - If you provide a new LocationListener, the former LocationListener will be
423
+ * replaced, therefore geolocations will be communicated to the new one.
424
+ * - If neither LocationRequest nor LocationListener change, nothing will happen.
425
+ * You may stop positioning at any time by calling the LocationManager.removeUpdates() method.
426
+ *
427
+ * @param location callback to use when location is udpated
428
+ * @param status callback to use when the positioning status changes
429
+ * @param error callback to use when error is raised
430
+ * @param locationOptions hashmap with options
431
+ *
432
+ * @returns the id of the subscription
433
+ */
434
+ startPositioning: function (
435
+ location: (event: any) => void,
436
+ status: Function,
437
+ error?: Function,
438
+ options?: LocationRequestOptions
439
+ ): void {
440
+ this.requestAuthorization();
441
+ return this.startPositioningUpdates(
442
+ location,
443
+ status,
444
+ error || logError,
445
+ options || {}
446
+ );
447
+ },
448
+
449
+ startPositioningUpdates: function (
450
+ location: (event: any) => void,
451
+ status: (event: any) => void,
452
+ error?: (event: any) => void,
453
+ options?: LocationRequestOptions
454
+ ): void {
455
+ // Remove old positioning subscriptions:
456
+ positioningSubscriptions.forEach((subscription) => subscription?.remove());
457
+ positioningSubscriptions = [];
458
+
459
+ positioningSubscriptions.push(
460
+ SitumPluginEventEmitter.addListener("locationChanged", location),
461
+ SitumPluginEventEmitter.addListener("statusChanged", status),
462
+ error
463
+ ? SitumPluginEventEmitter.addListener(
464
+ "locationError",
465
+ error || logError
466
+ )
467
+ : null
468
+ );
469
+ // Call native:
470
+ RNCSitumPlugin.startPositioning(options || {});
471
+ },
472
+
473
+ /**
474
+ * Stops positioning, removing all location updates
475
+ *
476
+ * @param callback the callback to use when the function successfully ends
477
+ * @returns
478
+ */
479
+ stopPositioning: function (callback?: Function): void {
480
+ RNCSitumPlugin.stopPositioning(callback || logError);
481
+ },
482
+
483
+ /**
484
+ * Calculates a route between two points. The result is provided
485
+ * asynchronously using the callback.
486
+ *
487
+ * @param directionParams
488
+ * @param success function called on sucess, returns a Route object
489
+ * @param error function called on failure, returns an error string
490
+ */
491
+ requestDirections: function (
492
+ directionParams: [
493
+ Building,
494
+ DirectionPoint,
495
+ DirectionPoint,
496
+ DirectionsOptions
497
+ ],
498
+ success: Function,
499
+ error?: Function
500
+ ) {
501
+ invariant(
502
+ typeof success === "function",
503
+ "Must provide a valid success callback."
504
+ );
505
+
506
+ RNCSitumPlugin.requestDirections(
507
+ directionParams,
508
+ success,
509
+ error || logError
510
+ );
511
+ },
512
+
513
+ /**
514
+ * Set the navigation params, and the listener that receives the updated
515
+ * navigation progress.
516
+ *
517
+ * Can only exist one navigation with one listener at a time. If this method was
518
+ * previously invoked, but removeUpdates() wasn't, removeUpdates() is called internally.
519
+ *
520
+ * @param navigationUpdates
521
+ * @param error function called on failure, returns an error string
522
+ * @param options
523
+ */
524
+ requestNavigationUpdates: function (
525
+ navigationUpdates: (event: any) => void,
526
+ error?: (event: any) => void,
527
+ options?: LocationRequestOptions
528
+ ) {
529
+ RNCSitumPlugin.requestNavigationUpdates(options || {});
530
+ navigationSubscriptions.push(
531
+ SitumPluginEventEmitter.addListener(
532
+ "navigationUpdated",
533
+ navigationUpdates
534
+ )
535
+ );
536
+ navigationSubscriptions.push(
537
+ error
538
+ ? SitumPluginEventEmitter.addListener(
539
+ "navigationError",
540
+ error || logError
541
+ )
542
+ : null
543
+ );
544
+ },
545
+
546
+ /**
547
+ * Informs NavigationManager object the change of the user's location
548
+ *
549
+ * @param location new Location of the user. If null, nothing is done
550
+ * @param success callback to use when the navigation updates
551
+ * @param error callback to use when an error on navigation udpates raises
552
+ */
553
+ updateNavigationWithLocation: function (
554
+ location,
555
+ success: Function,
556
+ error?: Function
557
+ ) {
558
+ if (navigationSubscriptions.length === 0) {
559
+ error("No active navigation!!");
560
+ return;
561
+ }
562
+
563
+ RNCSitumPlugin.updateNavigationWithLocation(
564
+ location,
565
+ success,
566
+ error || logError
567
+ );
568
+ },
569
+
570
+ /**
571
+ * Removes all location updates. This removes the internal state of the manager,
572
+ * including the listener provided in requestNavigationUpdates(NavigationRequest,
573
+ * NavigationListener), so it won't receive more progress updates.
574
+ *
575
+ * @param callback
576
+ */
577
+ removeNavigationUpdates: function (callback?: Function) {
578
+ for (let i = 0; i < navigationSubscriptions.length; i++) {
579
+ navigationSubscriptions[i].remove();
580
+ }
581
+
582
+ navigationSubscriptions = [];
583
+ RNCSitumPlugin.removeNavigationUpdates(callback || logError);
584
+ },
585
+
586
+ requestRealTimeUpdates: function (
587
+ navigationUpdates: (event: any) => void,
588
+ error?: (event: any) => void,
589
+ options?: any
590
+ ) {
591
+ RNCSitumPlugin.requestRealTimeUpdates(options || {});
592
+ realtimeSubscriptions.push([
593
+ SitumPluginEventEmitter.addListener("realtimeUpdated", navigationUpdates),
594
+ error
595
+ ? SitumPluginEventEmitter.addListener(
596
+ "realtimeError",
597
+ error || logError
598
+ )
599
+ : null,
600
+ ]);
601
+ },
602
+
603
+ /**
604
+ * Requests a real time devices positions
605
+ *
606
+ * @param realtimeUpdates callback to use when new device positions are updated
607
+ * @param error callback to use when an error on navigation udpates raises
608
+ * @param options Represents the configuration for getting realtime devices positions in
609
+ */
610
+ removeRealTimeUpdates: function (_callback?: Function) {
611
+ realtimeSubscriptions = [];
612
+ RNCSitumPlugin.removeRealTimeUpdates();
613
+ },
614
+
615
+ checkIfPointInsideGeofence: function (request: any, callback?: Function) {
616
+ invariant(
617
+ typeof callback === "function",
618
+ "Must provide a valid success callback."
619
+ );
620
+
621
+ RNCSitumPlugin.checkIfPointInsideGeofence(request, callback);
622
+ },
623
+
624
+ /**
625
+ * Callback that notifies when the user enters a geofence.
626
+ *
627
+ * In order to use correctly these callbacks you must know the following:
628
+ * - Positioning geofences (with trainer_metadata custom field) won't be notified.
629
+ * - These callbacks only work with indoor locations. Any outdoor location will
630
+ * produce a call to onExitedGeofences with the last positioned geofences as argument.
631
+ *
632
+ * @param callback the function called when the user enters a geofence
633
+ */
634
+ onEnterGeofences: function (callback: (event: any) => void) {
635
+ RNCSitumPlugin.onEnterGeofences();
636
+ // Adopts SDK behavior (setter):
637
+ SitumPluginEventEmitter.removeAllListeners("onEnterGeofences");
638
+ SitumPluginEventEmitter.addListener("onEnterGeofences", callback);
639
+ },
640
+
641
+ /**
642
+ * Callback that notifies when the user exits a geofence.
643
+ *
644
+ * In order to use correctly these callbacks you must know the following:
645
+ * - Positioning geofences (with trainer_metadata custom field) won't be notified.
646
+ * - These callbacks only work with indoor locations. Any outdoor location will
647
+ * produce a call to onExitedGeofences with the last positioned geofences as argument.
648
+ *
649
+ * @param callback the function called when the user exits a geofence
650
+ */
651
+ onExitGeofences: function (callback: (event: any) => void) {
652
+ RNCSitumPlugin.onExitGeofences();
653
+ SitumPluginEventEmitter.removeAllListeners("onExitGeofences");
654
+ SitumPluginEventEmitter.addListener("onExitGeofences", callback);
655
+ },
656
+ };
@@ -0,0 +1,18 @@
1
+ import { NativeEventEmitter, NativeModules } from "react-native";
2
+
3
+ const { RNCSitumPlugin } = NativeModules;
4
+
5
+ if (!RNCSitumPlugin) {
6
+ throw new Error("react-native-situm-plugin: NativeModule is null");
7
+ }
8
+
9
+ let nativeEventEmitter = null;
10
+ module.exports = {
11
+ RNCSitumPlugin,
12
+ get SitumPluginEventEmitter() {
13
+ if (!nativeEventEmitter) {
14
+ nativeEventEmitter = new NativeEventEmitter(RNCSitumPlugin);
15
+ }
16
+ return nativeEventEmitter;
17
+ },
18
+ };