@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,480 +1,250 @@
1
1
  /* eslint-disable @typescript-eslint/no-explicit-any */
2
- import { useContext, useEffect, useRef, useState } from "react";
2
+ import { useContext, useState } from "react";
3
3
 
4
4
  import SitumPlugin from "../../sdk";
5
5
  import {
6
6
  type Building,
7
- type DirectionPoint,
8
- type LocationRequestOptions,
7
+ type Error,
8
+ type Location,
9
9
  type LocationStatus,
10
- type Poi,
11
- type Position,
12
- type SDKError,
13
- type SDKNavigation,
10
+ type NavigationProgress,
14
11
  } from "../../sdk/types";
15
12
  import {
16
13
  LocationStatusName,
17
14
  NavigationStatus,
18
15
  NavigationUpdateType,
19
16
  } from "../../sdk/types/constants";
20
- import { requestPermission } from "../../utils/requestPermission";
21
17
  import {
22
18
  resetLocation,
23
- selectBuildings,
24
- selectCurrentBuilding,
25
- selectDestinationPoiID,
26
19
  selectDirections,
27
20
  selectError,
28
- selectIsSDKInitialized as selectIsSdkInitialized,
29
21
  selectLocation,
30
22
  selectLocationStatus,
31
23
  selectNavigation,
32
- selectPois,
33
- selectUser,
34
- setAuth,
35
- setBuildings,
36
- setCurrentBuilding,
37
- setDestinationPoiID,
38
24
  setDirections,
39
25
  setError,
40
26
  setLocation,
41
27
  setLocationStatus,
42
28
  setNavigation,
43
- setPois,
44
- setSdkInitialized,
45
- type State,
46
29
  UseSitumContext,
47
30
  } from "../store/index";
48
31
  import { useDispatch, useSelector } from "../store/utils";
32
+ import {
33
+ createDirectionsMessage,
34
+ createDirectionsRequest,
35
+ createNavigationRequest,
36
+ } from "../utils/mapper";
49
37
 
50
- const defaultNavigationOptions = {
38
+ const defaultNavigationRequest = {
51
39
  distanceToGoalThreshold: 4,
52
40
  outsideRouteThreshold: 5,
53
41
  };
54
42
 
55
- // Hook to define references that point to functions
56
- // used on listeners. These references are updated whenever
57
- // one of the dependencies on the array change
58
- export const useCallbackRef = <T>(fn: T, deps: any[]) => {
59
- const fnRef = useRef(fn);
60
-
61
- useEffect(() => {
62
- fnRef.current = fn;
63
- // eslint-disable-next-line react-hooks/exhaustive-deps
64
- }, deps);
65
-
66
- return fnRef;
67
- };
68
-
69
43
  export const useSitumInternal = () => {
70
44
  const dispatch = useDispatch();
71
- const isSdkInitialized = useSelector(selectIsSdkInitialized);
72
- const user = useSelector(selectUser);
45
+
73
46
  const location = useSelector(selectLocation);
74
47
  const locationStatus = useSelector(selectLocationStatus);
75
- const buildings = useSelector(selectBuildings);
76
- const currentBuilding = useSelector(selectCurrentBuilding);
77
- const pois = useSelector(selectPois);
48
+
78
49
  const directions = useSelector(selectDirections);
79
50
  const navigation = useSelector(selectNavigation);
80
51
  const error = useSelector(selectError);
81
- const destinationPoiID = useSelector(selectDestinationPoiID);
82
52
 
83
53
  const [lockDirections, setLockDirections] = useState<boolean>(false);
84
54
 
85
- const initSitumSdk = async ({
86
- email,
87
- apiKey,
88
- startPositions = true,
89
- fetchCartography = true,
90
- useRemoteConfig = true,
91
- }: {
92
- email?: string;
93
- apiKey?: string;
94
- startPositions?: boolean;
95
- fetchCartography?: boolean;
96
- useRemoteConfig?: boolean;
97
- }) =>
98
- // TODO fix this async/await
99
- // eslint-disable-next-line no-async-promise-executor
100
- new Promise<void>(async (resolve, reject) => {
101
- if (!isSdkInitialized) {
102
- SitumPlugin.initSitumSDK();
103
- setSdkInitialized(true);
104
- }
105
-
106
- if (email && apiKey) {
107
- dispatch(setAuth({ email, apiKey }));
108
- } else {
109
- email = user.email;
110
- apiKey = user.apiKey;
111
- }
112
-
113
- SitumPlugin.setApiKey(email, apiKey, (response: any) => {
114
- if (response && Boolean(response.success) === true) {
115
- console.debug("Situm > hook > Successful authentication.");
116
- } else {
117
- reject("Situm > hook > Failure while authenticating.");
118
- }
119
- });
120
-
121
- useRemoteConfig &&
122
- SitumPlugin.setUseRemoteConfig(`${useRemoteConfig}`, () => {
123
- console.debug("Situm > hook > Using remote config");
124
- });
125
-
126
- startPositions &&
127
- (await requestPermission()
128
- .then(() => {
129
- startPositioning();
130
- })
131
- .catch((e: string) => {
132
- console.error(e);
133
- reject(e);
134
- }));
135
-
136
- fetchCartography &&
137
- (await initializeBuildings().catch((e: string) => {
138
- console.error(e);
139
- reject(e);
140
- }));
141
-
142
- resolve();
143
- });
55
+ const init = () => {
56
+ console.debug("Situm > hook > Initializing -> Registering callbacks");
57
+ registerCallbacks();
58
+ };
144
59
 
145
- // Cartography
146
- const initializeBuildings = async () =>
147
- new Promise<Building[]>((resolve, reject) => {
148
- console.debug("Situm > hook > Retrieving buildings from Situm API");
149
-
150
- SitumPlugin.fetchBuildings(
151
- (buildingArray: Building[]) => {
152
- dispatch(setBuildings(buildingArray));
153
- console.debug("Situm > hook > Successfully retrieved buildings.");
154
- resolve(buildingArray);
155
- },
156
- (_error: string) => {
157
- console.error(
158
- `Situm > hook > Could not retrieve buildings: ${_error}`
159
- );
160
- reject(`Situm > hook> Could not retrieve buildings: ${_error}`);
161
- dispatch(setError({ message: _error, code: 3011 } as SDKError));
162
- }
60
+ function registerCallbacks() {
61
+ SitumPlugin.onLocationUpdate((loc: Location) => {
62
+ dispatch(
63
+ setLocation({
64
+ ...loc,
65
+ })
163
66
  );
164
67
  });
165
68
 
166
- const initializeBuildingById = async (buildingId: string) => {
167
- if (!buildings || buildings.length === 0) return;
168
- const newBuilding = buildings.find(
169
- (b: Building) => b.buildingIdentifier === buildingId
170
- );
171
- if (newBuilding) {
172
- dispatch(setCurrentBuilding(newBuilding));
173
- initializeBuildingPois(newBuilding);
174
- } else {
175
- console.warn(`Situm > hook > No building found for id ${buildingId}`);
176
- }
177
- };
178
-
179
- const initializeBuilding = async (b: Building) => {
180
- dispatch(setCurrentBuilding(b));
181
- initializeBuildingPois(b);
182
- };
183
-
184
- const initializeBuildingPois = (b: Building) => {
185
- SitumPlugin.fetchBuildingInfo(
186
- b,
187
- (buildingInfo: any) => {
69
+ SitumPlugin.onLocationStatus((status: LocationStatus) => {
70
+ if (status.statusName in LocationStatusName) {
188
71
  console.debug(
189
- "Situm > hook > Successfully retrieved pois of the selected building. "
190
- );
191
-
192
- // Please, do not change the next line. iOS sends data as indoorPois and Android sends it as indoorPOIs
193
- const buildingPois =
194
- buildingInfo?.indoorPOIs || buildingInfo?.indoorPois || [];
195
- dispatch(setPois(buildingPois));
196
- },
197
- (err: string) => {
198
- console.error(
199
- `Situm > hook > Could not initialize building pois: ${error}`
72
+ `Situm > hook > Positioning state updated ${status.statusName}`
200
73
  );
201
- dispatch(setError({ message: err, code: 3021 } as SDKError));
74
+ dispatch(setLocationStatus(status.statusName as LocationStatusName));
202
75
  }
203
- );
204
- };
76
+ });
205
77
 
206
- const startPositioning = () => {
207
- console.debug("Situm > hook > Starting positioning...");
78
+ SitumPlugin.onLocationError((err: Error) => {
79
+ console.error(`Situm > hook > Error while positioning: ${err}}`);
80
+ //@ts-ignore
81
+ dispatch(setError({ message: err, code: 3001 } as SDKError));
82
+ });
208
83
 
209
- if (location.status !== LocationStatusName.STOPPED) {
210
- console.debug("Situm > hook > Positioning has already started");
211
- return;
212
- }
84
+ SitumPlugin.onLocationStopped(() => {
85
+ console.debug("Situm > hook > Stopped positioning");
86
+ dispatch(resetLocation());
87
+ });
213
88
 
214
- // Declare the locationOptions (empty = default parameters)
215
- const locationOptions = {
216
- useDeadReckoning: false,
217
- } as LocationRequestOptions;
218
- // Start positioning
219
- SitumPlugin.startPositioning(
220
- (newLocation: State["location"]) => {
221
- dispatch(
222
- setLocation({
223
- ...newLocation,
224
- })
225
- );
226
- },
227
- (status: LocationStatus) => {
228
- if (status.statusName in LocationStatusName) {
229
- console.debug(
230
- `Situm > hook > Positioning state updated ${status.statusName}`
231
- );
232
- dispatch(setLocationStatus(status.statusName as LocationStatusName));
233
- }
234
- },
235
- (err: string) => {
236
- console.error(`Situm > hook > Error while positioning: ${err}}`);
237
- //@ts-ignore
238
- dispatch(setError({ message: err, code: 3001 } as SDKError));
239
- },
240
- locationOptions
241
- );
242
- console.debug(`Situm > hook > Successfully started positioning`);
243
- };
89
+ SitumPlugin.onNavigationProgress((progress: NavigationProgress) => {
90
+ console.debug("Situm > hook > NavigationProgress");
91
+
92
+ dispatch(
93
+ setNavigation({
94
+ currentIndication: progress?.currentIndication,
95
+ routeStep: progress?.routeStep,
96
+ distanceToGoal: progress?.distanceToGoal,
97
+ points: progress?.points,
98
+ type: NavigationUpdateType.PROGRESS,
99
+ segments: progress?.segments,
100
+ status: NavigationStatus.UPDATE,
101
+ })
102
+ );
103
+ });
244
104
 
245
- const stopPositioning = async () => {
246
- console.debug(`Situm > hook > Stopping positioning…`);
105
+ SitumPlugin.onNavigationOutOfRoute(() => {
106
+ dispatch(
107
+ setNavigation({
108
+ type: NavigationUpdateType.OUT_OF_ROUTE,
109
+ status: NavigationStatus.UPDATE,
110
+ })
111
+ );
247
112
 
248
- SitumPlugin.stopPositioning((success: boolean) => {
249
- if (success) {
250
- dispatch(resetLocation());
251
- console.debug("Situm > hook > Successfully stopped positioning");
252
- } else {
253
- console.error("Situm > hook > Could not stop positioning");
254
- }
113
+ console.debug("Situm > hook > NavigationOutOfRoute");
255
114
  });
256
- };
257
115
 
258
- // Routes
259
- const requestDirections = async (
260
- building: Building,
261
- from: Position,
262
- to: Position,
263
- directionsOptions?: any
264
- ): Promise<State["directions"]> => {
265
- console.debug("Situm > hook > Requesting directions");
266
-
267
- const fromPoint = {
268
- floorIdentifier: from.floorIdentifier,
269
- buildingIdentifier: from.buildingIdentifier,
270
- coordinate: from.coordinate,
271
- } as DirectionPoint;
272
- const toPoint = {
273
- floorIdentifier: to.floorIdentifier,
274
- buildingIdentifier: to.buildingIdentifier,
275
- coordinate: to.coordinate,
276
- } as DirectionPoint;
277
-
278
- return new Promise((resolve, reject) => {
279
- SitumPlugin.requestDirections(
280
- [building, fromPoint, toPoint, directionsOptions],
281
- (newDirections: State["directions"]) => {
282
- console.debug("Situm > hook > Successfully computed route");
283
- resolve(newDirections);
284
- },
285
- (err: string) => {
286
- console.debug(`Situm > hook > Could not compute route: ${err}`);
287
- dispatch(setError({ message: err, code: 3041 } as SDKError));
288
- reject(err);
289
- }
116
+ SitumPlugin.onNavigationFinished(() => {
117
+ dispatch(
118
+ setNavigation({
119
+ type: NavigationUpdateType.FINISHED,
120
+ status: NavigationStatus.UPDATE,
121
+ })
290
122
  );
123
+ console.debug("Situm > hook > NavigationFinished");
291
124
  });
292
- };
293
125
 
294
- const calculateRoute = async ({
295
- originId,
296
- destinationId,
297
- directionsOptions,
298
- updateRoute = true,
299
- }: {
300
- originId: number;
301
- destinationId: number;
302
- directionsOptions?: any;
303
- updateRoute?: boolean;
304
- }) => {
305
- const poiOrigin = pois.find(
306
- (p: Poi) => p.identifier === originId?.toString()
307
- );
308
- const poiDestination = pois.find(
309
- (p: Poi) => p.identifier === destinationId?.toString()
126
+ SitumPlugin.onNavigationError((progress: NavigationProgress) => {
127
+ console.debug("Situm > hook > NavigationProgress: ", progress);
128
+ });
129
+ }
130
+
131
+ const calculateRoute = async (payload: any, updateRoute = true) => {
132
+ console.debug("Situm > hook > calculating route");
133
+
134
+ const { to, from, minimizeFloorChanges, accessibilityMode, bearingFrom } =
135
+ createDirectionsRequest(payload.directionsRequest);
136
+ const { originIdentifier, destinationIdentifier, buildingIdentifier } =
137
+ createDirectionsMessage(payload);
138
+
139
+ const _buildings = await SitumPlugin.fetchBuildings();
140
+ const _building = _buildings.find(
141
+ (b: Building) => b.buildingIdentifier === buildingIdentifier
310
142
  );
311
143
 
312
- if (!poiDestination || (!poiOrigin && originId !== -1) || lockDirections) {
144
+ if (!to || !from || lockDirections) {
313
145
  console.debug(
314
- `Situm > hook > Could not compute route for origin: ${originId} or destination: ${destinationId} (lockDirections: ${lockDirections})`
146
+ `Situm > hook > Could not compute route (to: ${to}, from: ${from}, lockDirections: ${lockDirections})`
315
147
  );
316
148
  return;
317
149
  }
318
150
 
319
- const from =
320
- originId === -1 && location
321
- ? location.position
322
- : {
323
- buildingIdentifier: poiOrigin.buildingIdentifier,
324
- floorIdentifier: poiOrigin.floorIdentifier,
325
- cartesianCoordinate: poiOrigin.cartesianCoordinate,
326
- coordinate: poiOrigin.coordinate,
327
- };
328
-
329
- const to = {
330
- buildingIdentifier: poiDestination.buildingIdentifier,
331
- floorIdentifier: poiDestination.floorIdentifier,
332
- cartesianCoordinate: poiDestination.cartesianCoordinate,
333
- coordinate: poiDestination.coordinate,
334
- };
335
-
336
151
  // iOS workaround -> does not allow for several direction petitions
337
152
  setLockDirections(true);
338
- return requestDirections(currentBuilding, from, to, directionsOptions)
339
- .then((newDirections: State["directions"]) => {
340
- const extendedRoute = {
341
- ...newDirections,
342
- originId,
343
- destinationId,
344
- type: directionsOptions?.accessibilityMode,
153
+ return await SitumPlugin.requestDirections(_building, from, to, {
154
+ minimizeFloorChanges,
155
+ accessibilityMode,
156
+ bearingFrom,
157
+ })
158
+ .then((_directions) => {
159
+ const newRoute = {
160
+ ..._directions,
161
+ originIdentifier,
162
+ destinationIdentifier,
163
+ type: accessibilityMode,
345
164
  };
346
- updateRoute && dispatch(setDirections(extendedRoute));
347
- return extendedRoute;
165
+ if (updateRoute) {
166
+ dispatch(setDirections(newRoute));
167
+ }
168
+ return newRoute;
348
169
  })
349
- .catch((e: string) => {
170
+ .catch((e) => {
171
+ console.error(`Situm > hook > Could not compute route: ${e}`);
350
172
  dispatch(setDirections({ error: JSON.stringify(e) }));
351
173
  })
352
- .finally(() => setLockDirections(false));
174
+ .finally(() => {
175
+ setLockDirections(false);
176
+ });
353
177
  };
354
178
 
355
179
  // Navigation
356
- // TODO: this function is async and we use a callback, why not use a promise?
357
- const startNavigation = async ({
358
- callback,
359
- destinationId,
360
- directionsOptions,
361
- navigationOptions,
362
- originId,
363
- }: {
364
- callback?: (status: string, navigation?: SDKNavigation) => void;
365
- destinationId: number;
366
- directionsOptions?: any;
367
- navigationOptions?: any;
368
- originId: number;
369
- updateRoute?: boolean;
370
- }) => {
371
- navigation?.status !== NavigationStatus.STOP && stopNavigation();
372
- calculateRoute({
373
- originId,
374
- destinationId,
375
- directionsOptions,
376
- updateRoute: false,
377
- }).then((r) => {
378
- if (originId !== -1 || !location || !r) {
379
- callback && callback("error");
380
- return;
381
- }
382
- dispatch(
383
- setNavigation({
384
- status: NavigationStatus.START,
385
- ...r,
386
- })
387
- );
388
- callback && callback("success", r);
389
- SitumPlugin.requestNavigationUpdates(
390
- (update: SDKNavigation) => {
391
- const newNavType =
392
- (update.type &&
393
- update.type in NavigationUpdateType &&
394
- NavigationUpdateType[
395
- update.type as unknown as keyof typeof NavigationUpdateType
396
- ]) ||
397
- NavigationUpdateType.progress;
398
- dispatch(
399
- setNavigation({
400
- currentIndication: update?.currentIndication,
401
- routeStep: update?.routeStep,
402
- distanceToGoal: update?.distanceToGoal,
403
- points: update?.points,
404
- type: newNavType,
405
- segments: update?.segments,
406
- status: NavigationStatus.UPDATE,
407
- })
180
+ const startNavigation = (payload: any) => {
181
+ console.debug("Situm > hook > request to start navigation");
182
+ // TODO: we should delegate this to the sdk plugin
183
+ if (!navigation || navigation?.status !== NavigationStatus.STOP) {
184
+ stopNavigation();
185
+ }
186
+
187
+ calculateRoute(payload, false)
188
+ .then((r) => {
189
+ if (!r) {
190
+ console.debug(`Situm > hook > No route was computed`);
191
+ return;
192
+ }
193
+ dispatch(
194
+ setNavigation({
195
+ status: NavigationStatus.START,
196
+ type: NavigationUpdateType.PROGRESS,
197
+ ...r,
198
+ })
199
+ );
200
+ try {
201
+ const navigationRequest = createNavigationRequest(
202
+ payload.navigationRequest
408
203
  );
409
- },
410
- (err: string) => {
411
- console.error(`Situm > hook >Could not update navigation: ${err}`);
412
- callback && callback("error");
413
- dispatch(setError({ message: err, code: 3051 } as SDKError));
414
- stopNavigationRef.current();
415
- },
416
- { ...defaultNavigationOptions, ...navigationOptions }
417
- );
418
- });
204
+ SitumPlugin.requestNavigationUpdates({
205
+ ...defaultNavigationRequest,
206
+ ...navigationRequest,
207
+ });
208
+ } catch (e) {
209
+ console.error(`Situm > hook > Could not update navigation ${e}`);
210
+ dispatch(setError({ message: "error", code: 3051 } as Error));
211
+ stopNavigation();
212
+ }
213
+ })
214
+ .catch((e) => {
215
+ console.error(
216
+ `Situm > hook > Could not compute route for navigation ${e}`
217
+ );
218
+ });
419
219
  };
420
220
 
421
- const stopNavigation = (): void => {
221
+ const stopNavigation = () => {
422
222
  console.debug("Situm > hook > Stopping navigation");
423
- if (!navigation || navigation.status === NavigationStatus.STOP) {
223
+ // TODO: we should delegate this to the sdk plugin
224
+ if (!navigation || navigation?.status === NavigationStatus.STOP) {
424
225
  return;
425
226
  }
426
- SitumPlugin.removeNavigationUpdates((response: any) => {
427
- if (response && response.success) {
428
- console.debug("Situm > hook > Successfully removed navigation updates");
429
- } else {
430
- console.error("Situm > hook > Could not remove navigation updates");
431
- }
432
- });
433
- dispatch(setNavigation({ status: NavigationStatus.STOP }));
434
- dispatch(setDestinationPoiID(undefined));
435
- };
436
- const stopNavigationRef = useCallbackRef(stopNavigation, [navigation]);
437
-
438
- useEffect(() => {
439
- if (
440
- !navigation ||
441
- navigation.status === NavigationStatus.STOP ||
442
- !location
443
- ) {
444
- return;
227
+
228
+ try {
229
+ SitumPlugin.removeNavigationUpdates();
230
+ console.debug("Situm > hook > Successfully removed navigation updates");
231
+ dispatch(setNavigation({ status: NavigationStatus.STOP }));
232
+ } catch (e) {
233
+ console.error(`Situm > hook > Could not remove navigation updates ${e}`);
445
234
  }
446
- SitumPlugin.updateNavigationWithLocation(
447
- location,
448
- (info: any) => {
449
- console.debug(info);
450
- },
451
- (e: string) => {
452
- console.error(`Situm > hook > Error on navigation update ${e}`);
453
- }
454
- );
455
- // eslint-disable-next-line react-hooks/exhaustive-deps
456
- }, [location]);
235
+ };
457
236
 
458
237
  return {
459
238
  // States
460
- user,
461
239
  location,
462
240
  locationStatus,
463
- currentBuilding,
464
- buildings,
465
- pois,
241
+
466
242
  directions,
467
243
  navigation,
468
244
  error,
469
- destinationPoiID,
470
245
 
471
246
  // Functions
472
- initSitumSdk,
473
- initializeBuildings,
474
- initializeBuilding,
475
- initializeBuildingById,
476
- startPositioning,
477
- stopPositioning,
247
+ init,
478
248
  calculateRoute,
479
249
  startNavigation,
480
250
  stopNavigation,