@situm/react-native 3.0.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (147) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +656 -0
  3. package/ReactNativeSitumPlugin.podspec +22 -0
  4. package/SECURITY-POLICY.md +9 -0
  5. package/android/.gradle/5.6.4/fileChanges/last-build.bin +0 -0
  6. package/android/.gradle/5.6.4/fileHashes/fileHashes.lock +0 -0
  7. package/android/.gradle/5.6.4/gc.properties +0 -0
  8. package/android/.idea/.name +1 -0
  9. package/android/.idea/codeStyles/Project.xml +116 -0
  10. package/android/.idea/encodings.xml +6 -0
  11. package/android/.idea/misc.xml +31 -0
  12. package/android/.idea/sonarlint/issuestore/index.pb +15 -0
  13. package/android/.project +34 -0
  14. package/android/build.gradle +45 -0
  15. package/android/gradle/wrapper/gradle-wrapper.jar +0 -0
  16. package/android/gradle/wrapper/gradle-wrapper.properties +6 -0
  17. package/android/gradlew +172 -0
  18. package/android/gradlew.bat +84 -0
  19. package/android/src/main/AndroidManifest.xml +6 -0
  20. package/android/src/main/java/com/situm/plugin/PluginHelper.java +989 -0
  21. package/android/src/main/java/com/situm/plugin/SitumMapper.java +1206 -0
  22. package/android/src/main/java/com/situm/plugin/SitumPackage.java +29 -0
  23. package/android/src/main/java/com/situm/plugin/SitumPlugin.java +84 -0
  24. package/android/src/main/java/com/situm/plugin/SitumPluginImpl.java +344 -0
  25. package/android/src/main/java/com/situm/plugin/utils/ReactNativeJson.java +122 -0
  26. package/android/src/main/res/mipmap-hdpi/ic_launcher.png +0 -0
  27. package/android/src/main/res/mipmap-hdpi/ic_launcher_round.png +0 -0
  28. package/android/src/main/res/mipmap-mdpi/ic_launcher.png +0 -0
  29. package/android/src/main/res/mipmap-mdpi/ic_launcher_round.png +0 -0
  30. package/android/src/main/res/mipmap-xhdpi/ic_launcher.png +0 -0
  31. package/android/src/main/res/mipmap-xhdpi/ic_launcher_round.png +0 -0
  32. package/android/src/main/res/mipmap-xxhdpi/ic_launcher.png +0 -0
  33. package/android/src/main/res/mipmap-xxhdpi/ic_launcher_round.png +0 -0
  34. package/android/src/main/res/mipmap-xxxhdpi/ic_launcher.png +0 -0
  35. package/android/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png +0 -0
  36. package/android/src/main/res/values/strings.xml +3 -0
  37. package/android/src/main/res/values/styles.xml +9 -0
  38. package/ios/Constants.h +14 -0
  39. package/ios/Constants.m +14 -0
  40. package/ios/RNSitumReactNativePlugin.xcodeproj/project.pbxproj +272 -0
  41. package/ios/SitumLocationWrapper.h +112 -0
  42. package/ios/SitumLocationWrapper.m +1132 -0
  43. package/ios/SitumPlugin.h +15 -0
  44. package/ios/SitumPlugin.m +911 -0
  45. package/lib/commonjs/index.js +25 -0
  46. package/lib/commonjs/index.js.map +1 -0
  47. package/lib/commonjs/sdk/index.js +399 -0
  48. package/lib/commonjs/sdk/index.js.map +1 -0
  49. package/lib/commonjs/sdk/nativeInterface.js +20 -0
  50. package/lib/commonjs/sdk/nativeInterface.js.map +1 -0
  51. package/lib/commonjs/sdk/types/index.d.js +6 -0
  52. package/lib/commonjs/sdk/types/index.d.js.map +1 -0
  53. package/lib/commonjs/sdk/utils.js +22 -0
  54. package/lib/commonjs/sdk/utils.js.map +1 -0
  55. package/lib/commonjs/utils/requestPermission.js +73 -0
  56. package/lib/commonjs/utils/requestPermission.js.map +1 -0
  57. package/lib/commonjs/wayfinding/components/MapView.js +220 -0
  58. package/lib/commonjs/wayfinding/components/MapView.js.map +1 -0
  59. package/lib/commonjs/wayfinding/hooks/index.js +401 -0
  60. package/lib/commonjs/wayfinding/hooks/index.js.map +1 -0
  61. package/lib/commonjs/wayfinding/index.js +45 -0
  62. package/lib/commonjs/wayfinding/index.js.map +1 -0
  63. package/lib/commonjs/wayfinding/store/index.js +237 -0
  64. package/lib/commonjs/wayfinding/store/index.js.map +1 -0
  65. package/lib/commonjs/wayfinding/store/utils.js +44 -0
  66. package/lib/commonjs/wayfinding/store/utils.js.map +1 -0
  67. package/lib/commonjs/wayfinding/styles/colors.js +18 -0
  68. package/lib/commonjs/wayfinding/styles/colors.js.map +1 -0
  69. package/lib/commonjs/wayfinding/types/index.d.js +6 -0
  70. package/lib/commonjs/wayfinding/types/index.d.js.map +1 -0
  71. package/lib/commonjs/wayfinding/utils/index.js +11 -0
  72. package/lib/commonjs/wayfinding/utils/index.js.map +1 -0
  73. package/lib/commonjs/wayfinding/utils/mapper.js +106 -0
  74. package/lib/commonjs/wayfinding/utils/mapper.js.map +1 -0
  75. package/lib/module/index.js +6 -0
  76. package/lib/module/index.js.map +1 -0
  77. package/lib/module/sdk/index.js +390 -0
  78. package/lib/module/sdk/index.js.map +1 -0
  79. package/lib/module/sdk/nativeInterface.js +18 -0
  80. package/lib/module/sdk/nativeInterface.js.map +1 -0
  81. package/lib/module/sdk/types/index.d.js +2 -0
  82. package/lib/module/sdk/types/index.d.js.map +1 -0
  83. package/lib/module/sdk/utils.js +15 -0
  84. package/lib/module/sdk/utils.js.map +1 -0
  85. package/lib/module/utils/requestPermission.js +67 -0
  86. package/lib/module/utils/requestPermission.js.map +1 -0
  87. package/lib/module/wayfinding/components/MapView.js +207 -0
  88. package/lib/module/wayfinding/components/MapView.js.map +1 -0
  89. package/lib/module/wayfinding/hooks/index.js +392 -0
  90. package/lib/module/wayfinding/hooks/index.js.map +1 -0
  91. package/lib/module/wayfinding/index.js +12 -0
  92. package/lib/module/wayfinding/index.js.map +1 -0
  93. package/lib/module/wayfinding/store/index.js +202 -0
  94. package/lib/module/wayfinding/store/index.js.map +1 -0
  95. package/lib/module/wayfinding/store/utils.js +34 -0
  96. package/lib/module/wayfinding/store/utils.js.map +1 -0
  97. package/lib/module/wayfinding/styles/colors.js +11 -0
  98. package/lib/module/wayfinding/styles/colors.js.map +1 -0
  99. package/lib/module/wayfinding/types/index.d.js +2 -0
  100. package/lib/module/wayfinding/types/index.d.js.map +1 -0
  101. package/lib/module/wayfinding/utils/index.js +4 -0
  102. package/lib/module/wayfinding/utils/index.js.map +1 -0
  103. package/lib/module/wayfinding/utils/mapper.js +100 -0
  104. package/lib/module/wayfinding/utils/mapper.js.map +1 -0
  105. package/lib/typescript/src/index.d.ts +4 -0
  106. package/lib/typescript/src/index.d.ts.map +1 -0
  107. package/lib/typescript/src/sdk/index.d.ts +269 -0
  108. package/lib/typescript/src/sdk/index.d.ts.map +1 -0
  109. package/lib/typescript/src/sdk/nativeInterface.d.ts +2 -0
  110. package/lib/typescript/src/sdk/nativeInterface.d.ts.map +1 -0
  111. package/lib/typescript/src/sdk/utils.d.ts +7 -0
  112. package/lib/typescript/src/sdk/utils.d.ts.map +1 -0
  113. package/lib/typescript/src/utils/requestPermission.d.ts +3 -0
  114. package/lib/typescript/src/utils/requestPermission.d.ts.map +1 -0
  115. package/lib/typescript/src/wayfinding/components/MapView.d.ts +36 -0
  116. package/lib/typescript/src/wayfinding/components/MapView.d.ts.map +1 -0
  117. package/lib/typescript/src/wayfinding/hooks/index.d.ts +53 -0
  118. package/lib/typescript/src/wayfinding/hooks/index.d.ts.map +1 -0
  119. package/lib/typescript/src/wayfinding/index.d.ts +5 -0
  120. package/lib/typescript/src/wayfinding/index.d.ts.map +1 -0
  121. package/lib/typescript/src/wayfinding/store/index.d.ts +103 -0
  122. package/lib/typescript/src/wayfinding/store/index.d.ts.map +1 -0
  123. package/lib/typescript/src/wayfinding/store/utils.d.ts +9 -0
  124. package/lib/typescript/src/wayfinding/store/utils.d.ts.map +1 -0
  125. package/lib/typescript/src/wayfinding/styles/colors.d.ts +8 -0
  126. package/lib/typescript/src/wayfinding/styles/colors.d.ts.map +1 -0
  127. package/lib/typescript/src/wayfinding/utils/index.d.ts +3 -0
  128. package/lib/typescript/src/wayfinding/utils/index.d.ts.map +1 -0
  129. package/lib/typescript/src/wayfinding/utils/mapper.d.ts +17 -0
  130. package/lib/typescript/src/wayfinding/utils/mapper.d.ts.map +1 -0
  131. package/package.json +130 -0
  132. package/security.txt +4 -0
  133. package/src/index.ts +6 -0
  134. package/src/sdk/index.ts +656 -0
  135. package/src/sdk/nativeInterface.ts +18 -0
  136. package/src/sdk/types/index.d.ts +718 -0
  137. package/src/sdk/utils.ts +16 -0
  138. package/src/utils/requestPermission.ts +94 -0
  139. package/src/wayfinding/components/MapView.tsx +312 -0
  140. package/src/wayfinding/hooks/index.ts +539 -0
  141. package/src/wayfinding/index.tsx +11 -0
  142. package/src/wayfinding/store/index.tsx +254 -0
  143. package/src/wayfinding/store/utils.ts +40 -0
  144. package/src/wayfinding/styles/colors.tsx +6 -0
  145. package/src/wayfinding/types/index.d.ts +56 -0
  146. package/src/wayfinding/utils/index.ts +5 -0
  147. package/src/wayfinding/utils/mapper.ts +129 -0
@@ -0,0 +1,539 @@
1
+ /* eslint-disable @typescript-eslint/no-explicit-any */
2
+ import { useEffect, useRef, useState } from "react";
3
+
4
+ import type {
5
+ Building,
6
+ DirectionPoint,
7
+ LocationRequestOptions,
8
+ Poi,
9
+ } from "../../index";
10
+ import SitumPlugin from "../../sdk";
11
+ import requestPermission from "../../utils/requestPermission";
12
+ import {
13
+ NavigateToPoiType,
14
+ NavigationStatus,
15
+ NavigationUpdateType,
16
+ Position,
17
+ PositioningStatus,
18
+ resetLocation,
19
+ SDKError,
20
+ SDKNavigation,
21
+ selectBuildings,
22
+ selectCurrentBuilding,
23
+ selectDestinationPoiID,
24
+ selectDirections,
25
+ selectError,
26
+ selectIsSDKInitialized as selectIsSdkInitialized,
27
+ selectLocation,
28
+ selectLocationStatus,
29
+ selectNavigation,
30
+ selectPois,
31
+ selectUser,
32
+ selectWebViewRef,
33
+ setAuth,
34
+ setBuildings,
35
+ setCurrentBuilding,
36
+ setDestinationPoiID,
37
+ setDirections,
38
+ setError,
39
+ setLocation,
40
+ setLocationStatus,
41
+ setNavigation,
42
+ setPois,
43
+ setSdkInitialized,
44
+ State,
45
+ } from "../store/index";
46
+ import { useDispatch, useSelector } from "../store/utils";
47
+ import { sendMessageToViewer } from "../utils";
48
+ import Mapper from "../utils/mapper";
49
+
50
+ const defaultNavigationOptions = {
51
+ distanceToGoalThreshold: 4,
52
+ outsideRouteThreshold: 5,
53
+ };
54
+
55
+ export interface LocationStatus {
56
+ statusName: string;
57
+ statusCode: number;
58
+ }
59
+
60
+ // Hook to define references that point to functions
61
+ // used on listeners. These references are updated whenever
62
+ // one of the dependencies on the array change
63
+ const useCallbackRef = <T>(fn: T, deps: any[]) => {
64
+ const fnRef = useRef(fn);
65
+
66
+ useEffect(() => {
67
+ fnRef.current = fn;
68
+ // eslint-disable-next-line react-hooks/exhaustive-deps
69
+ }, deps);
70
+
71
+ return fnRef;
72
+ };
73
+
74
+ const useSitum = () => {
75
+ const dispatch = useDispatch();
76
+ const webViewRef = useSelector(selectWebViewRef);
77
+ const isSdkInitialized = useSelector(selectIsSdkInitialized);
78
+ const user = useSelector(selectUser);
79
+ const location = useSelector(selectLocation);
80
+ const locationStatus = useSelector(selectLocationStatus);
81
+ const buildings = useSelector(selectBuildings);
82
+ const currentBuilding = useSelector(selectCurrentBuilding);
83
+ const pois = useSelector(selectPois);
84
+ const directions = useSelector(selectDirections);
85
+ const navigation = useSelector(selectNavigation);
86
+ const error = useSelector(selectError);
87
+ const destinationPoiID = useSelector(selectDestinationPoiID);
88
+
89
+ const [lockDirections, setLockDirections] = useState<boolean>(false);
90
+
91
+ const initSitumSdk = async ({
92
+ email,
93
+ apiKey,
94
+ startPositions = true,
95
+ fetchCartography = true,
96
+ useRemoteConfig = true,
97
+ }: {
98
+ email?: string;
99
+ apiKey?: string;
100
+ startPositions?: boolean;
101
+ fetchCartography?: boolean;
102
+ useRemoteConfig?: boolean;
103
+ }) =>
104
+ // TODO fix this async/await
105
+ // eslint-disable-next-line no-async-promise-executor
106
+ new Promise<void>(async (resolve, reject) => {
107
+ if (!isSdkInitialized) {
108
+ SitumPlugin.initSitumSDK();
109
+ setSdkInitialized(true);
110
+ }
111
+
112
+ if (email && apiKey) {
113
+ dispatch(setAuth({ email, apiKey }));
114
+ } else {
115
+ email = user.email;
116
+ apiKey = user.apiKey;
117
+ }
118
+
119
+ SitumPlugin.setApiKey(email, apiKey, (response: any) => {
120
+ if (response && Boolean(response.success) === true) {
121
+ console.debug("Situm > hook > Successful authentication.");
122
+ } else {
123
+ reject("Situm > hook > Failure while authenticating.");
124
+ }
125
+ });
126
+
127
+ useRemoteConfig &&
128
+ SitumPlugin.setUseRemoteConfig(`${useRemoteConfig}`, () => {
129
+ console.debug("Situm > hook > Using remote config");
130
+ });
131
+
132
+ startPositions &&
133
+ (await requestPermission()
134
+ .then(() => {
135
+ startPositioning();
136
+ })
137
+ .catch((e: string) => {
138
+ console.error(e);
139
+ reject(e);
140
+ }));
141
+
142
+ fetchCartography &&
143
+ (await initializeBuildings().catch((e: string) => {
144
+ console.error(e);
145
+ reject(e);
146
+ }));
147
+
148
+ resolve();
149
+ });
150
+
151
+ // Cartography
152
+ const initializeBuildings = async () =>
153
+ new Promise<Building[]>((resolve, reject) => {
154
+ console.debug("Retrieving buildings from Situm API");
155
+
156
+ SitumPlugin.fetchBuildings(
157
+ (buildingArray: Building[]) => {
158
+ dispatch(setBuildings(buildingArray));
159
+ console.debug("Situm > hook > Successfully retrieved buildings.");
160
+ resolve(buildingArray);
161
+ },
162
+ (_error: string) => {
163
+ console.error(
164
+ `Situm > hook > Could not retrieve buildings: ${_error}`
165
+ );
166
+ reject(`Could not retrieve buildings: ${_error}`);
167
+ dispatch(setError({ message: _error, code: 3011 } as SDKError));
168
+ }
169
+ );
170
+ });
171
+
172
+ const initializeBuildingById = async (buildingId: string) => {
173
+ if (buildings.length === 0) return;
174
+ const newBuilding = buildings.find(
175
+ (b: Building) => b.buildingIdentifier === buildingId
176
+ );
177
+ if (newBuilding) {
178
+ dispatch(setCurrentBuilding(newBuilding));
179
+ initializeBuildingPois(newBuilding);
180
+ } else {
181
+ console.warn(`Situm > hook > No building found for id ${buildingId}`);
182
+ }
183
+ };
184
+
185
+ const initializeBuilding = async (b: Building) => {
186
+ dispatch(setCurrentBuilding(b));
187
+ initializeBuildingPois(b);
188
+ };
189
+
190
+ const initializeBuildingPois = (b: Building) => {
191
+ SitumPlugin.fetchBuildingInfo(
192
+ b,
193
+ (buildingInfo: any) => {
194
+ console.debug(
195
+ "Situm > hook > Successfully retrieved pois of the selected building. "
196
+ );
197
+
198
+ // Please, do not change the next line. iOS sends data as indoorPois and Android sends it as indoorPOIs
199
+ const buildingPois =
200
+ buildingInfo?.indoorPOIs || buildingInfo?.indoorPois || [];
201
+ dispatch(setPois(buildingPois));
202
+ },
203
+ (err: string) => {
204
+ console.error(
205
+ `Situm > hook > Could not initialize building pois: ${error}`
206
+ );
207
+ dispatch(setError({ message: err, code: 3021 } as SDKError));
208
+ }
209
+ );
210
+ };
211
+
212
+ const startPositioning = () => {
213
+ console.debug("Situm > hook > Starting positioning...");
214
+
215
+ if (location.status !== PositioningStatus.STOPPED) {
216
+ console.debug("Situm > hook > Positioning has already started");
217
+ return;
218
+ }
219
+
220
+ // Declare the locationOptions (empty = default parameters)
221
+ const locationOptions = {
222
+ useDeadReckoning: false,
223
+ } as LocationRequestOptions;
224
+ // Start positioning
225
+ SitumPlugin.startPositioning(
226
+ (newLocation: State["location"]) => {
227
+ dispatch(
228
+ setLocation({
229
+ ...newLocation,
230
+ })
231
+ );
232
+ },
233
+ (status: LocationStatus) => {
234
+ if (status.statusName in PositioningStatus) {
235
+ console.debug(
236
+ `Situm > hook > Positioning state updated ${status.statusName}`
237
+ );
238
+ dispatch(setLocationStatus(status.statusName as PositioningStatus));
239
+ }
240
+ },
241
+ (err: string) => {
242
+ console.error(`Situm > hook > Error while positioning: ${err}}`);
243
+ //@ts-ignore
244
+ dispatch(setError({ message: err, code: 3001 } as SDKError));
245
+ },
246
+ locationOptions
247
+ );
248
+ console.debug(`Successfully started positioning`);
249
+ };
250
+
251
+ const stopPositioning = async () => {
252
+ console.debug(`Stopping positioning ...`);
253
+ SitumPlugin.stopPositioning((success: boolean) => {
254
+ if (success) {
255
+ dispatch(resetLocation());
256
+ console.debug("Situm > hook > Successfully stopped positioning");
257
+ } else {
258
+ console.error("Situm > hook > Could not stop positioning");
259
+ }
260
+ });
261
+ };
262
+
263
+ // Routes
264
+ const requestDirections = async (
265
+ building: Building,
266
+ from: Position,
267
+ to: Position,
268
+ directionsOptions?: any
269
+ ): Promise<State["directions"]> => {
270
+ console.debug("Requesting directions");
271
+ const fromPoint = {
272
+ floorIdentifier: from.floorIdentifier,
273
+ buildingIdentifier: from.buildingIdentifier,
274
+ coordinate: from.coordinate,
275
+ } as DirectionPoint;
276
+ const toPoint = {
277
+ floorIdentifier: to.floorIdentifier,
278
+ buildingIdentifier: to.buildingIdentifier,
279
+ coordinate: to.coordinate,
280
+ } as DirectionPoint;
281
+
282
+ return new Promise((resolve, reject) => {
283
+ SitumPlugin.requestDirections(
284
+ [building, fromPoint, toPoint, directionsOptions],
285
+ (newDirections: State["directions"]) => {
286
+ console.debug("Situm > hook > Successfully computed route");
287
+ resolve(newDirections);
288
+ },
289
+ (err: string) => {
290
+ console.debug(`Situm > hook > Could not compute route: ${err}`);
291
+ dispatch(setError({ message: err, code: 3041 } as SDKError));
292
+ reject(err);
293
+ }
294
+ );
295
+ });
296
+ };
297
+
298
+ const calculateRoute = async ({
299
+ originId,
300
+ destinationId,
301
+ directionsOptions,
302
+ updateRoute = true,
303
+ }: {
304
+ originId: number;
305
+ destinationId: number;
306
+ directionsOptions?: any;
307
+ updateRoute?: boolean;
308
+ }) => {
309
+ const poiOrigin = pois.find(
310
+ (p: Poi) => p.identifier === originId?.toString()
311
+ );
312
+ const poiDestination = pois.find(
313
+ (p: Poi) => p.identifier === destinationId?.toString()
314
+ );
315
+
316
+ if (!poiDestination || (!poiOrigin && originId !== -1) || lockDirections) {
317
+ console.debug(
318
+ `Situm > hook >Could not compute route for origin: ${originId} or destination: ${destinationId} (lockDirections: ${lockDirections})`
319
+ );
320
+ return;
321
+ }
322
+
323
+ const from =
324
+ originId === -1 && location
325
+ ? location.position
326
+ : {
327
+ buildingIdentifier: poiOrigin.buildingIdentifier,
328
+ floorIdentifier: poiOrigin.floorIdentifier,
329
+ cartesianCoordinate: poiOrigin.cartesianCoordinate,
330
+ coordinate: poiOrigin.coordinate,
331
+ };
332
+
333
+ const to = {
334
+ buildingIdentifier: poiDestination.buildingIdentifier,
335
+ floorIdentifier: poiDestination.floorIdentifier,
336
+ cartesianCoordinate: poiDestination.cartesianCoordinate,
337
+ coordinate: poiDestination.coordinate,
338
+ };
339
+
340
+ // iOS workaround -> does not allow for several direction petitions
341
+ setLockDirections(true);
342
+ return requestDirections(currentBuilding, from, to, directionsOptions)
343
+ .then((newDirections: State["directions"]) => {
344
+ const extendedRoute = {
345
+ ...newDirections,
346
+ originId,
347
+ destinationId,
348
+ type: directionsOptions?.accessibilityMode,
349
+ };
350
+ updateRoute && dispatch(setDirections(extendedRoute));
351
+ return directions;
352
+ })
353
+ .catch((e: string) => {
354
+ dispatch(setDirections({ error: JSON.stringify(e) }));
355
+ })
356
+ .finally(() => setLockDirections(false));
357
+ };
358
+
359
+ // Navigation
360
+ // TODO: this function is async and we use a callback, why not use a promise?
361
+ const startNavigation = async ({
362
+ callback,
363
+ destinationId,
364
+ directionsOptions,
365
+ navigationOptions,
366
+ originId,
367
+ }: {
368
+ callback?: (status: string, navigation?: SDKNavigation) => void;
369
+ destinationId: number;
370
+ directionsOptions?: any;
371
+ navigationOptions?: any;
372
+ originId: number;
373
+ updateRoute?: boolean;
374
+ }) => {
375
+ calculateRoute({
376
+ originId,
377
+ destinationId,
378
+ directionsOptions,
379
+ updateRoute: false,
380
+ }).then((r) => {
381
+ if (originId !== -1 || !location || !r) {
382
+ callback && callback("error");
383
+ return;
384
+ }
385
+ dispatch(
386
+ setNavigation({
387
+ status: NavigationStatus.START,
388
+ ...r,
389
+ })
390
+ );
391
+ callback && callback("success", r);
392
+ SitumPlugin.requestNavigationUpdates(
393
+ (update: SDKNavigation) => {
394
+ const newNavType =
395
+ (update.type &&
396
+ update.type in NavigationUpdateType &&
397
+ NavigationUpdateType[
398
+ update.type as unknown as keyof typeof NavigationUpdateType
399
+ ]) ||
400
+ NavigationUpdateType.progress;
401
+ dispatch(
402
+ setNavigation({
403
+ currentIndication: update?.currentIndication,
404
+ routeStep: update?.routeStep,
405
+ distanceToGoal: update?.distanceToGoal,
406
+ points: update?.points,
407
+ type: newNavType,
408
+ segments: update?.segments,
409
+ status: NavigationStatus.UPDATE,
410
+ })
411
+ );
412
+ },
413
+ (err: string) => {
414
+ console.error(`Situm > hook >Could not update navigation: ${err}`);
415
+ callback && callback("error");
416
+ dispatch(setError({ message: err, code: 3051 } as SDKError));
417
+ stopNavigationRef.current();
418
+ },
419
+ { ...defaultNavigationOptions, ...navigationOptions }
420
+ );
421
+ });
422
+ };
423
+
424
+ const navigateToPoi = async ({
425
+ poi,
426
+ poiId,
427
+ }: {
428
+ poi?: Poi;
429
+ poiId?: number;
430
+ }) => {
431
+ if (!poi && !poiId) return;
432
+ const validPoi = pois?.find(
433
+ (p) =>
434
+ p?.identifier === poiId?.toString() ||
435
+ // @ts-ignore
436
+ p?.identifier === poi?.id?.toString()
437
+ );
438
+ if (!validPoi) {
439
+ console.error("Situm > hook > Invalid value as poi or poiId");
440
+ return;
441
+ }
442
+
443
+ sendMessageToViewer(
444
+ webViewRef.current,
445
+ Mapper.navigateToPoi({
446
+ // @ts-ignore
447
+ navigationTo: poi?.id || poiId,
448
+ } as NavigateToPoiType)
449
+ );
450
+ };
451
+
452
+ const stopNavigation = (): void => {
453
+ console.debug("Stopping navigation");
454
+ if (!navigation || navigation.status === NavigationStatus.STOP) {
455
+ return;
456
+ }
457
+ SitumPlugin.removeNavigationUpdates((response: any) => {
458
+ if (response && response.success) {
459
+ console.debug("Situm > hook > Successfully removed navigation updates");
460
+ } else {
461
+ console.error("Situm > hook > Could not remove navigation updates");
462
+ }
463
+ });
464
+ dispatch(setNavigation({ status: NavigationStatus.STOP }));
465
+ dispatch(setDestinationPoiID(undefined));
466
+ };
467
+
468
+ const cancelNavigation = (): void => {
469
+ stopNavigation();
470
+ sendMessageToViewer(webViewRef.current, Mapper.cancelNavigation());
471
+ };
472
+
473
+ const selectPoi = (poiId: number): void => {
474
+ const poi = pois?.find((p) => p?.identifier === poiId?.toString());
475
+ if (!poi) {
476
+ console.error("Situm > hook > Invalid value as poiId");
477
+ return;
478
+ }
479
+ if (navigation.status !== NavigationStatus.STOP) {
480
+ console.error(
481
+ "Situm > hook > Navigation on course, poi selection is unavailable"
482
+ );
483
+ return;
484
+ }
485
+ sendMessageToViewer(webViewRef.current, Mapper.selectPoi(poiId));
486
+ };
487
+
488
+ const stopNavigationRef = useCallbackRef(stopNavigation, [navigation]);
489
+
490
+ useEffect(() => {
491
+ if (
492
+ !navigation ||
493
+ navigation.status === NavigationStatus.STOP ||
494
+ !location
495
+ ) {
496
+ return;
497
+ }
498
+ SitumPlugin.updateNavigationWithLocation(
499
+ location,
500
+ (info: any) => {
501
+ console.debug(info);
502
+ },
503
+ (e: string) => {
504
+ console.error(`Situm > hook > Error on navigation update ${e}`);
505
+ }
506
+ );
507
+ // eslint-disable-next-line react-hooks/exhaustive-deps
508
+ }, [location]);
509
+
510
+ return {
511
+ // States
512
+ user,
513
+ location,
514
+ locationStatus,
515
+ currentBuilding,
516
+ buildings,
517
+ pois,
518
+ directions,
519
+ navigation,
520
+ error,
521
+ destinationPoiID,
522
+
523
+ // Functions
524
+ initSitumSdk,
525
+ initializeBuildings,
526
+ initializeBuilding,
527
+ initializeBuildingById,
528
+ startPositioning,
529
+ stopPositioning,
530
+ calculateRoute,
531
+ startNavigation,
532
+ stopNavigation,
533
+ cancelNavigation,
534
+ selectPoi,
535
+ navigateToPoi,
536
+ };
537
+ };
538
+
539
+ export default useSitum;
@@ -0,0 +1,11 @@
1
+ // Definitions
2
+ export * from "./types/index.d";
3
+
4
+ // Hook
5
+ export { default as useSitum } from "./hooks";
6
+
7
+ // State Provider
8
+ export { default as SitumProvider } from "./store";
9
+
10
+ // Component
11
+ export { default as MapView } from "./components/MapView";