@situm/react-native 3.0.7 → 3.1.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/android/src/main/java/com/situm/plugin/PluginHelper.java +3 -2
- package/android/src/main/java/com/situm/plugin/SitumMapper.java +38 -59
- package/android/src/main/java/com/situm/plugin/SitumPlugin.java +1 -0
- package/android/src/main/java/com/situm/plugin/SitumPluginImpl.java +1 -1
- package/ios/SitumPlugin.m +8 -2
- package/lib/commonjs/sdk/index.js +509 -251
- package/lib/commonjs/sdk/index.js.map +1 -1
- package/lib/commonjs/sdk/nativeInterface.js.map +1 -1
- package/lib/commonjs/sdk/types/constants.js +31 -4
- package/lib/commonjs/sdk/types/constants.js.map +1 -1
- package/lib/commonjs/sdk/utils.js +103 -0
- package/lib/commonjs/sdk/utils.js.map +1 -0
- package/lib/commonjs/utils/requestPermission.js +9 -16
- package/lib/commonjs/utils/requestPermission.js.map +1 -1
- package/lib/commonjs/wayfinding/components/MapView.js +78 -134
- package/lib/commonjs/wayfinding/components/MapView.js.map +1 -1
- package/lib/commonjs/wayfinding/hooks/index.js +118 -278
- package/lib/commonjs/wayfinding/hooks/index.js.map +1 -1
- package/lib/commonjs/wayfinding/store/index.js +17 -6
- package/lib/commonjs/wayfinding/store/index.js.map +1 -1
- package/lib/commonjs/wayfinding/types/index.js +1 -3
- package/lib/commonjs/wayfinding/types/index.js.map +1 -1
- package/lib/commonjs/wayfinding/utils/mapper.js +128 -71
- package/lib/commonjs/wayfinding/utils/mapper.js.map +1 -1
- package/lib/module/sdk/index.js +509 -249
- package/lib/module/sdk/index.js.map +1 -1
- package/lib/module/sdk/nativeInterface.js.map +1 -1
- package/lib/module/sdk/types/constants.js +27 -3
- package/lib/module/sdk/types/constants.js.map +1 -1
- package/lib/module/sdk/utils.js +94 -0
- package/lib/module/sdk/utils.js.map +1 -0
- package/lib/module/utils/requestPermission.js +9 -16
- package/lib/module/utils/requestPermission.js.map +1 -1
- package/lib/module/wayfinding/components/MapView.js +77 -133
- package/lib/module/wayfinding/components/MapView.js.map +1 -1
- package/lib/module/wayfinding/hooks/index.js +119 -278
- package/lib/module/wayfinding/hooks/index.js.map +1 -1
- package/lib/module/wayfinding/store/index.js +15 -6
- package/lib/module/wayfinding/store/index.js.map +1 -1
- package/lib/module/wayfinding/types/index.js +1 -1
- package/lib/module/wayfinding/types/index.js.map +1 -1
- package/lib/module/wayfinding/utils/mapper.js +123 -72
- package/lib/module/wayfinding/utils/mapper.js.map +1 -1
- package/lib/typescript/src/sdk/index.d.ts +183 -145
- package/lib/typescript/src/sdk/index.d.ts.map +1 -1
- package/lib/typescript/src/sdk/nativeInterface.d.ts +59 -0
- package/lib/typescript/src/sdk/nativeInterface.d.ts.map +1 -1
- package/lib/typescript/src/sdk/types/constants.d.ts +24 -3
- package/lib/typescript/src/sdk/types/constants.d.ts.map +1 -1
- package/lib/typescript/src/sdk/types/index.d.ts +91 -146
- package/lib/typescript/src/sdk/types/index.d.ts.map +1 -1
- package/lib/typescript/src/sdk/utils.d.ts +53 -0
- package/lib/typescript/src/sdk/utils.d.ts.map +1 -0
- package/lib/typescript/src/utils/requestPermission.d.ts +1 -1
- package/lib/typescript/src/utils/requestPermission.d.ts.map +1 -1
- package/lib/typescript/src/wayfinding/components/MapView.d.ts +16 -28
- package/lib/typescript/src/wayfinding/components/MapView.d.ts.map +1 -1
- package/lib/typescript/src/wayfinding/hooks/index.d.ts +3 -34
- package/lib/typescript/src/wayfinding/hooks/index.d.ts.map +1 -1
- package/lib/typescript/src/wayfinding/store/index.d.ts +8 -6
- package/lib/typescript/src/wayfinding/store/index.d.ts.map +1 -1
- package/lib/typescript/src/wayfinding/types/index.d.ts +36 -17
- package/lib/typescript/src/wayfinding/types/index.d.ts.map +1 -1
- package/lib/typescript/src/wayfinding/utils/mapper.d.ts +16 -11
- package/lib/typescript/src/wayfinding/utils/mapper.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/sdk/index.ts +467 -476
- package/src/sdk/nativeInterface.ts +149 -1
- package/src/sdk/types/constants.ts +27 -3
- package/src/sdk/types/index.ts +98 -158
- package/src/sdk/utils.ts +129 -0
- package/src/utils/requestPermission.ts +18 -23
- package/src/wayfinding/components/MapView.tsx +145 -215
- package/src/wayfinding/hooks/index.ts +155 -385
- package/src/wayfinding/store/index.tsx +19 -9
- package/src/wayfinding/types/index.ts +49 -15
- package/src/wayfinding/utils/mapper.ts +145 -104
|
@@ -1,480 +1,250 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
-
import { useContext,
|
|
2
|
+
import { useContext, useState } from "react";
|
|
3
3
|
|
|
4
4
|
import SitumPlugin from "../../sdk";
|
|
5
5
|
import {
|
|
6
6
|
type Building,
|
|
7
|
-
type
|
|
8
|
-
type
|
|
7
|
+
type Error,
|
|
8
|
+
type Location,
|
|
9
9
|
type LocationStatus,
|
|
10
|
-
type
|
|
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
|
|
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
|
-
|
|
72
|
-
const user = useSelector(selectUser);
|
|
45
|
+
|
|
73
46
|
const location = useSelector(selectLocation);
|
|
74
47
|
const locationStatus = useSelector(selectLocationStatus);
|
|
75
|
-
|
|
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
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
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
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
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
|
-
|
|
167
|
-
|
|
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
|
-
|
|
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(
|
|
74
|
+
dispatch(setLocationStatus(status.statusName as LocationStatusName));
|
|
202
75
|
}
|
|
203
|
-
);
|
|
204
|
-
};
|
|
76
|
+
});
|
|
205
77
|
|
|
206
|
-
|
|
207
|
-
|
|
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
|
-
|
|
210
|
-
console.debug("Situm > hook >
|
|
211
|
-
|
|
212
|
-
}
|
|
84
|
+
SitumPlugin.onLocationStopped(() => {
|
|
85
|
+
console.debug("Situm > hook > Stopped positioning");
|
|
86
|
+
dispatch(resetLocation());
|
|
87
|
+
});
|
|
213
88
|
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
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
|
-
|
|
246
|
-
|
|
105
|
+
SitumPlugin.onNavigationOutOfRoute(() => {
|
|
106
|
+
dispatch(
|
|
107
|
+
setNavigation({
|
|
108
|
+
type: NavigationUpdateType.OUT_OF_ROUTE,
|
|
109
|
+
status: NavigationStatus.UPDATE,
|
|
110
|
+
})
|
|
111
|
+
);
|
|
247
112
|
|
|
248
|
-
|
|
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
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
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
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
);
|
|
308
|
-
const
|
|
309
|
-
(
|
|
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 (!
|
|
144
|
+
if (!to || !from || lockDirections) {
|
|
313
145
|
console.debug(
|
|
314
|
-
`Situm > hook > Could not compute route
|
|
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(
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
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
|
-
|
|
347
|
-
|
|
165
|
+
if (updateRoute) {
|
|
166
|
+
dispatch(setDirections(newRoute));
|
|
167
|
+
}
|
|
168
|
+
return newRoute;
|
|
348
169
|
})
|
|
349
|
-
.catch((e
|
|
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(() =>
|
|
174
|
+
.finally(() => {
|
|
175
|
+
setLockDirections(false);
|
|
176
|
+
});
|
|
353
177
|
};
|
|
354
178
|
|
|
355
179
|
// Navigation
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
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
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
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 = ()
|
|
221
|
+
const stopNavigation = () => {
|
|
422
222
|
console.debug("Situm > hook > Stopping navigation");
|
|
423
|
-
|
|
223
|
+
// TODO: we should delegate this to the sdk plugin
|
|
224
|
+
if (!navigation || navigation?.status === NavigationStatus.STOP) {
|
|
424
225
|
return;
|
|
425
226
|
}
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
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
|
-
|
|
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
|
-
|
|
464
|
-
buildings,
|
|
465
|
-
pois,
|
|
241
|
+
|
|
466
242
|
directions,
|
|
467
243
|
navigation,
|
|
468
244
|
error,
|
|
469
|
-
destinationPoiID,
|
|
470
245
|
|
|
471
246
|
// Functions
|
|
472
|
-
|
|
473
|
-
initializeBuildings,
|
|
474
|
-
initializeBuilding,
|
|
475
|
-
initializeBuildingById,
|
|
476
|
-
startPositioning,
|
|
477
|
-
stopPositioning,
|
|
247
|
+
init,
|
|
478
248
|
calculateRoute,
|
|
479
249
|
startNavigation,
|
|
480
250
|
stopNavigation,
|