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