diff --git a/CHANGELOG_UNRELEASED.md b/CHANGELOG_UNRELEASED.md index 61d5ce84..16a7aae9 100644 --- a/CHANGELOG_UNRELEASED.md +++ b/CHANGELOG_UNRELEASED.md @@ -8,4 +8,14 @@ - `SitumProvider.apiKey` is now optional. If no credentials are available when the MapView loads, it waits until authentication is provided. - Updated the example application React Native from 0.79.1 to 0.83.10 to fix an issue that prevented the app from compiling on iOS. -- Updated Android example application targetSdkVersion from 35 to 37. \ No newline at end of file +- Updated Android example application targetSdkVersion from 35 to 37. + +### Removed + +- Removed routing and navigation bridge between MapView and native SDK as the MapView now always uses its own routing and navigation library. + +### Fixed + +- AccessibilityMode documentation now mentions DirectionsOptions instead of DirectionsRequest. +- Fixed removeNavigationUpdates never resolving when navigation was not running. +- Fixed navigationRunning remaining active after reaching the destination. \ No newline at end of file diff --git a/plugin/src/sdk/index.ts b/plugin/src/sdk/index.ts index ba64b429..bd0a29c8 100644 --- a/plugin/src/sdk/index.ts +++ b/plugin/src/sdk/index.ts @@ -100,8 +100,8 @@ let exitGeofencesCallback = (_: any) => {}; // Internal callbacks: // These callback functions will be added as listeners to SitumPluginEventEmitter as soon as possible and will be -// listening events for all the plugin lifecycle. They will forward calls to both client callbacks and the MapView -// internal callback. +// listening events for all the plugin lifecycle. Location and geofence events will forward calls to both client +// callbacks and the MapView internal callback. Navigation events are forwarded only to the client callbacks. const _internalLocationCallback = (loc: Location) => { DelegatedStateManager.getInstance().updateLocation(loc); @@ -143,56 +143,6 @@ const _internalLocationErrorCallback = (error: Error) => { locationErrorCallback?.(adaptedError); }; -const _internalNavigationStartedCallback = (route: Route) => { - internalMethodCallMapDelegate( - new InternalCall(InternalCallType.NAVIGATION_START, route), - ); - navigationStartedCallback?.(route); -}; - -const _internalNavigationProgressCallback = (progress: NavigationProgress) => { - internalMethodCallMapDelegate( - new InternalCall(InternalCallType.NAVIGATION_PROGRESS, progress), - ); - navigationProgressCallback?.(progress); -}; - -const _internalNavigationDestinationReachedCallback = (route: Route) => { - internalMethodCallMapDelegate( - new InternalCall(InternalCallType.NAVIGATION_DESTINATION_REACHED, route), - ); - navigationDestinationReachedCallback?.(route); -}; - -const _internalNavigationOutOfRouteCallback = () => { - internalMethodCallMapDelegate( - new InternalCall(InternalCallType.NAVIGATION_OUT_OF_ROUTE, undefined), - ); - navigationOutOfRouteCallback?.(); -}; - -const _internalNavigationFinishedCallback = () => { - // Deprecated! - internalMethodCallMapDelegate( - new InternalCall(InternalCallType.NAVIGATION_CANCELLATION, undefined), - ); - navigationFinishedCallback?.(); -}; - -const _internalNavigationCancellationCallback = () => { - internalMethodCallMapDelegate( - new InternalCall(InternalCallType.NAVIGATION_CANCELLATION, undefined), - ); - navigationCancellationCallback?.(); -}; - -const _internalNavigationErrorCallback = (error: any) => { - internalMethodCallMapDelegate( - new InternalCall(InternalCallType.NAVIGATION_ERROR, error), - ); - navigationErrorCallback?.(error); -}; - const _internalEnterGeofencesCallback = (data: any) => { internalMethodCallMapDelegate( new InternalCall(InternalCallType.GEOFENCES_ENTER, data), @@ -213,16 +163,30 @@ const _registerCallbacks = () => { statusChanged: _internalLocationStatusCallback, locationStopped: _internalLocationStoppedCallback, locationError: _internalLocationErrorCallback, - [SdkNavigationUpdateType.START]: _internalNavigationStartedCallback, - [SdkNavigationUpdateType.PROGRESS]: _internalNavigationProgressCallback, - [SdkNavigationUpdateType.DESTINATION_REACHED]: - _internalNavigationDestinationReachedCallback, - [SdkNavigationUpdateType.OUTSIDE_ROUTE]: - _internalNavigationOutOfRouteCallback, - [SdkNavigationUpdateType.FINISHED]: _internalNavigationFinishedCallback, - [SdkNavigationUpdateType.CANCELLATION]: - _internalNavigationCancellationCallback, - [SdkNavigationUpdateType.ERROR]: _internalNavigationErrorCallback, + [SdkNavigationUpdateType.START]: (route: Route) => { + navigationStartedCallback(route); + }, + [SdkNavigationUpdateType.PROGRESS]: (progress: NavigationProgress) => { + navigationProgressCallback(progress); + }, + [SdkNavigationUpdateType.DESTINATION_REACHED]: (route: Route) => { + navigationDestinationReachedCallback(route); + navigationRunning = false; + }, + [SdkNavigationUpdateType.OUTSIDE_ROUTE]: () => { + navigationOutOfRouteCallback(); + }, + [SdkNavigationUpdateType.FINISHED]: () => { + navigationFinishedCallback(); + navigationRunning = false; + }, + [SdkNavigationUpdateType.CANCELLATION]: () => { + navigationCancellationCallback(); + navigationRunning = false; + }, + [SdkNavigationUpdateType.ERROR]: (error: any) => { + navigationErrorCallback(error); + }, onEnterGeofences: _internalEnterGeofencesCallback, onExitGeofences: _internalExitGeofencesCallback, }; @@ -685,8 +649,11 @@ export default class SitumPlugin { * */ static removeNavigationUpdates = () => { - return promiseWrapper(({ onCallback }) => { - if (!SitumPlugin.navigationIsRunning()) return; + return promiseWrapper(({ resolve, onCallback }) => { + if (!SitumPlugin.navigationIsRunning()) { + resolve(); + return; + } navigationRunning = false; RNCSitumPlugin.removeNavigationUpdates((response) => { diff --git a/plugin/src/sdk/types/constants.ts b/plugin/src/sdk/types/constants.ts index d4a8486c..cff125eb 100644 --- a/plugin/src/sdk/types/constants.ts +++ b/plugin/src/sdk/types/constants.ts @@ -1,3 +1,8 @@ +/** + * @deprecated This enum was used by the legacy navigation bridge between the native SDK and the MapView. + * That bridge has been removed. + * It is kept for backward compatibility and is no longer used or emitted by the plugin. + */ export enum NavigationStatus { START = "start", STOP = "stop", @@ -5,6 +10,11 @@ export enum NavigationStatus { UPDATE = "update", } +/** + * @deprecated This enum was used by the legacy navigation bridge between the native SDK and the MapView. + * That bridge has been removed. + * It is kept for backward compatibility and is no longer used or emitted by the plugin. + */ export enum NavigationUpdateType { PROGRESS = "PROGRESS", OUT_OF_ROUTE = "OUT_OF_ROUTE", @@ -33,7 +43,7 @@ export enum LocationStatusName { } /** - * Available accessibility modes used in the {@link DirectionsRequest}. + * Available accessibility modes used in the {@link DirectionsOptions}. * * @property CHOOSE_SHORTEST The route should choose the best route, without taking into account if it is accessible or not. * This option is the default so you don't have to do anything in order to use it @@ -51,12 +61,6 @@ export enum InternalCallType { LOCATION_STATUS = "LOCATION_STATUS", LOCATION_ERROR = "LOCATION_ERROR", LOCATION_STOPPED = "LOCATION_STOPPED", // TODO: Exists only in RN, delete! - NAVIGATION_START = "NAVIGATION_START", - NAVIGATION_DESTINATION_REACHED = "NAVIGATION_DESTINATION_REACHED", - NAVIGATION_PROGRESS = "NAVIGATION_PROGRESS", - NAVIGATION_OUT_OF_ROUTE = "NAVIGATION_OUT_OF_ROUTE", - NAVIGATION_CANCELLATION = "NAVIGATION_CANCELLATION", - NAVIGATION_ERROR = "NAVIGATION_ERROR", GEOFENCES_ENTER = "GEOFENCES_ENTER", GEOFENCES_EXIT = "GEOFENCES_EXIT", } diff --git a/plugin/src/wayfinding/components/MapView.tsx b/plugin/src/wayfinding/components/MapView.tsx index addb9d27..510520c4 100644 --- a/plugin/src/wayfinding/components/MapView.tsx +++ b/plugin/src/wayfinding/components/MapView.tsx @@ -26,7 +26,6 @@ import SitumPlugin from "../../sdk"; import useSitum from "../hooks"; import { selectApiDomain, - selectUser, setError, setLocationStatus, } from "../store"; @@ -40,7 +39,6 @@ import { type NavigateToCarPayload, type NavigateToPointPayload, type NavigateToPoiPayload, - type OnDirectionsRequestInterceptor, type OnExternalLinkClickedResult, type OnFavoritePoisUpdatedResult, type OnFloorChangedResult, @@ -53,7 +51,7 @@ import { import { ErrorName } from "../types/constants"; import { sendMessageToViewer } from "../utils"; import ViewerMapper from "../utils/mapper"; -import { areSameAuth, authStore, SitumAuth } from "../../sdk/authStore"; +import { authStore, SitumAuth } from "../../sdk/authStore"; const SITUM_BASE_DOMAIN = "https://maps.situm.com"; const NETWORK_ERROR_CODE = { @@ -183,8 +181,6 @@ const MapView = React.forwardRef( ref, ) => { const webViewRef = useRef(null); - const [_onDirectionsRequestInterceptor, setInterceptor] = - useState(); const internalMessageCallbackRef = useRef(); @@ -203,11 +199,6 @@ const MapView = React.forwardRef( init, location, locationStatus, - directions, - navigation, - calculateRoute, - startNavigation, - stopNavigation, error, } = useSitum(); @@ -282,12 +273,6 @@ const MapView = React.forwardRef( if (!webViewRef.current) { return; } - if (SitumPlugin.navigationIsRunning()) { - console.error( - "Situm > hook > Navigation on course, poi category selection is unavailable", - ); - return; - } sendMessageToViewer( webViewRef.current, ViewerMapper.selectPoiCategory(categoryId), @@ -299,12 +284,6 @@ const MapView = React.forwardRef( if (!webViewRef.current) { return; } - if (SitumPlugin.navigationIsRunning()) { - console.error( - "Situm > hook > Navigation on course, floor selection is unavailable", - ); - return; - } sendMessageToViewer( webViewRef.current, ViewerMapper.selectFloor(floorId, options), @@ -412,7 +391,7 @@ const MapView = React.forwardRef( webViewRef.current && sendMessageToViewer( webViewRef.current, - ViewerMapper.selectPoi(null), + ViewerMapper.deselectPoi(), ); }, navigateToPoi(payload): void { @@ -424,12 +403,8 @@ const MapView = React.forwardRef( navigateToPoint(payload: NavigateToPointPayload): void { _navigateToPoint(payload); }, - setOnDirectionsRequestInterceptor(directionRequestInterceptor): void { - setInterceptor(() => directionRequestInterceptor); - }, cancelNavigation(): void { if (!webViewRef.current) return; - stopNavigation(); sendMessageToViewer( webViewRef.current, ViewerMapper.cancelNavigation(), @@ -450,7 +425,6 @@ const MapView = React.forwardRef( }, }; }, [ - stopNavigation, _navigateToPoi, _followUser, _navigateToCar, @@ -516,23 +490,6 @@ const MapView = React.forwardRef( setError(null); }, [error, mapLoaded]); - // Updated SDK navigation - useEffect(() => { - if (!webViewRef.current || !navigation || !mapLoaded) return; - - sendMessageToViewer( - webViewRef.current, - ViewerMapper.navigation(navigation), - ); - }, [navigation, mapLoaded]); - - // Updated SDK route - useEffect(() => { - if (!webViewRef.current || !directions || !mapLoaded) return; - - sendMessageToViewer(webViewRef.current, ViewerMapper.route(directions)); - }, [directions, mapLoaded]); - // Update language useEffect(() => { if (!webViewRef.current || !configuration.language || !mapLoaded) return; @@ -580,15 +537,6 @@ const MapView = React.forwardRef( case "app.ready_for_auth": sendEffectiveAuth(); break; - case "directions.requested": - calculateRoute(payload, _onDirectionsRequestInterceptor); - break; - case "navigation.requested": - startNavigation(payload, _onDirectionsRequestInterceptor); - break; - case "navigation.stopped": - stopNavigation(); - break; case "cartography.poi_selected": onPoiSelected(payload); break; @@ -620,6 +568,10 @@ const MapView = React.forwardRef( case "viewer.navigation.started": case "viewer.navigation.updated": case "viewer.navigation.stopped": + // Forward Viewer navigation events to the existing SDK callbacks. + // This avoids introducing a separate set of callbacks just for the Viewer. + // Warning: running SDK and MapView navigations at the same time may mix + // events because both navigations use the same public SDK callbacks. SitumPlugin.updateNavigationState(payload); break; case "share_location.uploading_locations_started": diff --git a/plugin/src/wayfinding/hooks/index.ts b/plugin/src/wayfinding/hooks/index.ts index d4d619a9..24408f4e 100644 --- a/plugin/src/wayfinding/hooks/index.ts +++ b/plugin/src/wayfinding/hooks/index.ts @@ -1,49 +1,28 @@ /* eslint-disable no-case-declarations */ /* eslint-disable @typescript-eslint/no-explicit-any */ -import { useContext, useState } from "react"; +import { useContext } from "react"; import SitumPlugin from "../../sdk"; import { - type Building, type Error, - ErrorCode, - ErrorType, InternalCall, type Location, - type NavigationProgress, } from "../../sdk/types"; import { InternalCallType, LocationStatusName, - NavigationStatus, - NavigationUpdateType, } from "../../sdk/types/constants"; import { resetLocation, - selectDirections, selectError, selectLocation, selectLocationStatus, - selectNavigation, - setDirections, setError, setLocation, setLocationStatus, - setNavigation, UseSitumContext, } from "../store/index"; import { useDispatch, useSelector } from "../store/utils"; -import type { OnDirectionsRequestInterceptor } from "../types"; -import { - createDirectionsMessage, - createDirectionsRequest, - createNavigationRequest, -} from "../utils/mapper"; - -const defaultNavigationRequest = { - distanceToGoalThreshold: 4, - outsideRouteThreshold: 5, -}; export const useSitumInternal = () => { const dispatch = useDispatch(); @@ -51,12 +30,8 @@ export const useSitumInternal = () => { const location = useSelector(selectLocation); const locationStatus = useSelector(selectLocationStatus); - const directions = useSelector(selectDirections); - const navigation = useSelector(selectNavigation); const error = useSelector(selectError); - const [lockDirections, setLockDirections] = useState(false); - const init = () => { console.debug("Situm > hook > Initializing -> Registering callbacks"); registerCallbacks(); @@ -88,53 +63,6 @@ export const useSitumInternal = () => { const receivedError = internalCall.get(); dispatch(setError(receivedError)); break; - case InternalCallType.NAVIGATION_START: - dispatch( - setNavigation({ - type: NavigationUpdateType.PROGRESS, - status: NavigationStatus.START, - }), - ); - break; - case InternalCallType.NAVIGATION_DESTINATION_REACHED: - dispatch( - setNavigation({ - type: NavigationUpdateType.DESTINATION_REACHED, - status: NavigationStatus.UPDATE, - }), - ); - break; - case InternalCallType.NAVIGATION_PROGRESS: - const progress = internalCall.get(); - dispatch( - setNavigation({ - currentIndication: progress?.currentIndication, - routeStep: progress?.routeStep, - distanceToGoal: progress?.distanceToGoal, - points: progress?.points, - type: NavigationUpdateType.PROGRESS, - segments: progress?.segments, - status: NavigationStatus.UPDATE, - }), - ); - break; - case InternalCallType.NAVIGATION_OUT_OF_ROUTE: - dispatch( - setNavigation({ - type: NavigationUpdateType.OUT_OF_ROUTE, - status: NavigationStatus.UPDATE, - }), - ); - break; - case InternalCallType.NAVIGATION_CANCELLATION: - dispatch( - setNavigation({ - type: NavigationUpdateType.CANCELLED, - status: NavigationStatus.STOP, - }), - ); - break; - case InternalCallType.NAVIGATION_ERROR: case InternalCallType.GEOFENCES_ENTER: case InternalCallType.GEOFENCES_EXIT: // Do nothing. @@ -144,165 +72,15 @@ export const useSitumInternal = () => { ); } - const calculateRoute = async ( - payload: any, - interceptor?: OnDirectionsRequestInterceptor, - updateRoute = true, - ) => { - console.debug("Situm > hook > calculating route"); - - const directionsRequest = createDirectionsRequest( - payload.directionsRequest, - ); - interceptor && interceptor(directionsRequest); - const { - to, - from, - minimizeFloorChanges, - accessibilityMode, - bearingFrom, - includedTags, - excludedTags, - } = directionsRequest; - const { originIdentifier, destinationIdentifier, buildingIdentifier } = - createDirectionsMessage(payload); - - const _buildings = await SitumPlugin.fetchBuildings(); - const _building = _buildings.find( - (b: Building) => b.buildingIdentifier === buildingIdentifier, - ); - - if (!_building) { - console.debug(`Situm > hook > Could not compute route: missing building`); - return; - } - - if (!to || !from || lockDirections) { - console.debug( - `Situm > hook > Could not compute route (to: ${to}, from: ${from}, lockDirections: ${lockDirections})`, - ); - return; - } - - // iOS workaround -> does not allow for several direction petitions - setLockDirections(true); - return await SitumPlugin.requestDirections(_building, from, to, { - minimizeFloorChanges, - accessibilityMode, - bearingFrom, - includedTags, - excludedTags, - }) - .then((_directions) => { - const newRoute = { - ..._directions, - originIdentifier, - destinationIdentifier, - type: accessibilityMode, - }; - if (updateRoute) { - dispatch(setDirections(newRoute)); - } - return newRoute; - }) - .catch((e) => { - console.error(`Situm > hook > Could not compute route: ${e}`); - dispatch(setDirections({ error: JSON.stringify(e) })); - }) - .finally(() => { - setLockDirections(false); - }); - }; - - // Navigation - const startNavigation = ( - payload: any, - interceptor?: OnDirectionsRequestInterceptor, - ) => { - console.debug("Situm > hook > request to start navigation"); - // TODO: we should delegate this to the sdk plugin - if (!navigation || navigation?.status !== NavigationStatus.STOP) { - stopNavigation(); - } - - calculateRoute(payload, interceptor, false) - .then((r) => { - if (!r) { - console.debug(`Situm > hook > No route was computed`); - return; - } - dispatch( - setNavigation({ - status: NavigationStatus.START, - type: NavigationUpdateType.PROGRESS, - ...r, - }), - ); - try { - const navigationRequest = createNavigationRequest( - payload.navigationRequest, - ); - SitumPlugin.requestNavigationUpdates({ - ...defaultNavigationRequest, - ...navigationRequest, - }); - } catch (e) { - console.error(`Situm > hook > Could not update navigation ${e}`); - //TODO: Remove this and emit these errors in SitumPlugin.onNavigationError - dispatch( - setError({ - message: "Could not update navigation", - code: ErrorCode.UNKNOWN, - type: ErrorType.NON_CRITICAL, - } as Error), - ); - stopNavigation(); - } - }) - .catch((e) => { - console.error( - `Situm > hook > Could not compute route for navigation ${JSON.stringify( - e, - )}`, - ); - }); - }; - - const stopNavigation = () => { - // TODO: we should delegate this to the sdk plugin - if (!navigation || navigation?.status === NavigationStatus.STOP) { - return; - } - console.debug("Situm > hook > Stopping navigation"); - - SitumPlugin.removeNavigationUpdates() - .then(() => { - console.debug("Situm > hook > Successfully removed navigation updates"); - dispatch(setNavigation({ status: NavigationStatus.STOP })); - }) - .catch((e) => { - console.warn( - `Situm > hook > Could not remove navigation updates ${JSON.stringify( - e, - )}`, - ); - }); - }; - return { // States location, locationStatus, - directions, - navigation, error, // Functions init, - calculateRoute, - startNavigation, - stopNavigation, }; }; diff --git a/plugin/src/wayfinding/store/index.tsx b/plugin/src/wayfinding/store/index.tsx index cf077019..27db7956 100644 --- a/plugin/src/wayfinding/store/index.tsx +++ b/plugin/src/wayfinding/store/index.tsx @@ -38,7 +38,15 @@ export interface State { buildings: Building[] | null; currentBuilding: Building | undefined; pois: Poi[]; + /** + * @deprecated Routes are now calculated and managed by the MapView. + * This property is kept for backward compatibility and will always be undefined. + */ directions?: Directions; + /** + * @deprecated Navigation is now calculated and managed by the MapView. + * This property is kept for backward compatibility and will always be undefined. + */ navigation?: NavigationProgress; destinationPoiID?: number; error?: Error; @@ -93,12 +101,6 @@ const store = createStore({ setPois: (state: State, payload: State["pois"]) => { return { ...state, pois: payload }; }, - setDirections: (state: State, payload: State["directions"]) => { - return { ...state, directions: payload }; - }, - setNavigation: (state: State, payload: State["navigation"]) => { - return { ...state, navigation: payload }; - }, setDestinationPoiID: (state: State, payload: State["destinationPoiID"]) => { return { ...state, destinationPoiID: payload }; }, @@ -162,10 +164,18 @@ export const selectPois = (state: State) => { return state.pois; }; +/** + * @deprecated Routes are now calculated and managed by the MapView. + * This selector is kept for backward compatibility and will always return undefined. + */ export const selectDirections = (state: State) => { return state.directions; }; +/** + * @deprecated Navigation is now calculated and managed by the MapView. + * This selector is kept for backward compatibility and will always return undefined. + */ export const selectNavigation = (state: State) => { return state.navigation; }; @@ -190,8 +200,6 @@ export const { setBuildings, setCurrentBuilding, setPois, - setDirections, - setNavigation, setDestinationPoiID, setError, setBuildingIdentifier, diff --git a/plugin/src/wayfinding/types/index.ts b/plugin/src/wayfinding/types/index.ts index f875c330..1a669fa9 100644 --- a/plugin/src/wayfinding/types/index.ts +++ b/plugin/src/wayfinding/types/index.ts @@ -79,6 +79,11 @@ export interface MapViewRef { * Cancels the current navigation, if any. */ cancelNavigation: () => void; + + /** + * @deprecated Routes are now calculated and managed by the MapView, so direction requests are no longer intercepted by the plugin. + * This method is kept for backward compatibility and has no effect. + */ setOnDirectionsRequestInterceptor: (params: { onDirectionsRequestInterceptor: OnDirectionsRequestInterceptor; }) => void; @@ -176,8 +181,8 @@ export interface MapViewDirectionsOptions { } /** - * This interface allows you to modify all the parameters in the DirectionRequest used by the MapViewer to calculate the route. - * To use this you will need to load the MapView and once it ends loading use the MapViewRef that you obtain an call setOnDirectionsRequestInterceptor(interceptor) + * @deprecated Routes are now calculated and managed by the MapView, so direction requests are no longer intercepted by the plugin. + * This interface is kept for backward compatibility and is no longer used internally. */ export interface OnDirectionsRequestInterceptor { (directionRequest: DirectionsRequest): void; @@ -205,6 +210,10 @@ export interface OnFavoritePoisUpdatedResult { currentPoisIdentifiers: number[]; } +/** + * @deprecated Navigation is now calculated and managed by the MapView. + * This interface is kept for backward compatibility and is no longer used internally. + */ export interface Destination { category: string; identifier?: string; @@ -212,11 +221,19 @@ export interface Destination { point: Point; } +/** + * @deprecated Navigation is now calculated and managed by the MapView. + * This interface is kept for backward compatibility and is no longer used internally. + */ export interface Navigation { status: string; destination?: Destination; } +/** + * @deprecated Navigation results are no longer produced by the native SDK bridge. + * This interface is kept for backward compatibility and is no longer used internally. + */ export interface OnNavigationResult { navigation?: Navigation; error?: Error; @@ -243,6 +260,10 @@ export type ShareLiveLocationSessionPayload = { identifier: string; }; +/** + * @deprecated Direction requests are no longer forwarded from the MapView to the native SDK. + * This type is kept for backward compatibility and is no longer used internally. + */ export type DirectionsMessage = { buildingIdentifier: string; originIdentifier: string; diff --git a/plugin/src/wayfinding/utils/mapper.ts b/plugin/src/wayfinding/utils/mapper.ts index 9a15a468..d2a85832 100644 --- a/plugin/src/wayfinding/utils/mapper.ts +++ b/plugin/src/wayfinding/utils/mapper.ts @@ -1,85 +1,20 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ import { SitumAuth } from "../../sdk/authStore"; -import { AccessibilityMode, LocationStatusName } from "../../sdk"; +import { LocationStatusName } from "../../sdk"; import type { - Directions, - DirectionsRequest, Location, - NavigationProgress, - NavigationRequest, - Point, } from "../../sdk/types"; import type { CartographySelectionOptions, - DirectionsMessage, MapViewDirectionsOptions, NavigateToCarPayload, NavigateToPointPayload, NavigateToPoiPayload, - Navigation, - OnNavigationResult, SearchFilter, ViewerConfigItem, ShareLiveLocationSessionPayload, } from "../types"; -export const createPoint = (payload: any): Point => { - return { - buildingIdentifier: payload.buildingIdentifier, - floorIdentifier: payload.floorIdentifier, - cartesianCoordinate: payload.cartesianCoordinate, - coordinate: payload.coordinate, - }; -}; - -export const createDirectionsMessage = (payload: any): DirectionsMessage => { - return { - buildingIdentifier: payload.buildingIdentifier, - originIdentifier: (payload.originIdentifier || -1).toString(), - originCategory: payload.originCategory, - destinationIdentifier: (payload.destinationIdentifier || -1).toString(), - destinationCategory: payload.destinationCategory, - identifier: (payload.identifier || "").toString(), - }; -}; - -export const createDirectionsRequest = (payload: any): DirectionsRequest => { - return { - buildingIdentifier: payload.from.buildingIdentifier, - to: createPoint(payload.to), - from: createPoint(payload.from), - bearingFrom: payload.bearingFrom?.radians || 0, - accessibilityMode: - payload.accessibilityMode || AccessibilityMode.CHOOSE_SHORTEST, - minimizeFloorChanges: payload.minimizeFloorChanges || false, - includedTags: payload.includedTags || [], - excludedTags: payload.excludedTags || [], - }; -}; - -export const createNavigationRequest = (payload: any): NavigationRequest => { - const navigationRequest = { - distanceToGoalThreshold: payload.distanceToGoalThreshold, - outsideRouteThreshold: payload.outsideRouteThreshold, - distanceToIgnoreFirstIndication: payload.distanceToIgnoreFirstIndication, - distanceToFloorChangeThreshold: payload.distanceToFloorChangeThreshold, - distanceToChangeIndicationThreshold: - payload.distanceToChangeIndicationThreshold, - indicationsInterval: payload.indicationsInterval, - timeToFirstIndication: payload.timeToFirstIndication, - roundIndicationsStep: payload.roundIndicationsStep, - timeToIgnoreUnexpectedFloorChanges: - payload.timeToIgnoreUnexpectedFloorChanges, - ignoreLowQualityLocations: payload.ignoreLowQualityLocations, - }; - - return Object.fromEntries( - Object.entries(navigationRequest || {}).filter( - ([_, value]) => value !== undefined, - ), - ); -}; - const mapperWrapper = (type: string, payload?: unknown) => { return JSON.stringify({ type, payload: payload ?? {} }); }; @@ -106,6 +41,9 @@ const ViewerMapper = { selectPoi: (poiId: number | null) => { return mapperWrapper(`cartography.select_poi`, { identifier: poiId }); }, + deselectPoi: () => { + return mapperWrapper("cartography.deselect_poi"); + }, selectCar: () => { return mapperWrapper(`cartography.select_car`); }, @@ -153,27 +91,7 @@ const ViewerMapper = { locationError: (errorCode: string) => { return mapperWrapper("location.update_status", { status: errorCode }); }, - // Directions - route: (directions: Directions) => { - return mapperWrapper("directions.update", directions); - }, - routeToResult: (route: any): OnNavigationResult => { - return { - navigation: { - status: route.status, - destination: { - category: route?.destinationId ? "POI" : "COORDINATE", - identifier: route?.destinationId, - //name:, //TODO - point: route.to ? createPoint(route.to) : createPoint(route.TO), - }, - }, - }; - }, // Navigation - navigation: (navigation: Navigation) => { - return mapperWrapper(`navigation.${navigation.status}`, navigation); - }, navigateToPoi: (navigate: NavigateToPoiPayload) => { return mapperWrapper(`navigation.start`, { navigationTo: navigate?.identifier, @@ -203,13 +121,6 @@ const ViewerMapper = { cancelNavigation: () => { return mapperWrapper(`navigation.cancel`, {}); }, - navigationToResult: (navigation: NavigationProgress): OnNavigationResult => { - return { - navigation: { - status: navigation?.type, - }, - }; - }, search: (searchFilter: SearchFilter) => { return mapperWrapper(`ui.set_search_filter`, { text: searchFilter.text,