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