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