@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,220 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = exports.ErrorName = void 0;
7
+ var _react = _interopRequireWildcard(require("react"));
8
+ var _reactNative = require("react-native");
9
+ var _reactNativeWebview = _interopRequireDefault(require("react-native-webview"));
10
+ var _hooks = _interopRequireDefault(require("../hooks"));
11
+ var _store = require("../store");
12
+ var _utils = require("../store/utils");
13
+ var _utils2 = require("../utils");
14
+ var _mapper = _interopRequireDefault(require("../utils/mapper"));
15
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
16
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
17
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
18
+ /* eslint-disable @typescript-eslint/no-explicit-any */
19
+ /* eslint-disable @typescript-eslint/no-empty-function */
20
+
21
+ //This icon should either be inside plugin or not be used rat all
22
+
23
+ const SITUM_BASE_DOMAIN = "https://map-viewer.situm.com";
24
+
25
+ // Define class that handles errors
26
+ let ErrorName = /*#__PURE__*/function (ErrorName) {
27
+ ErrorName["ERR_INTERNET_DISCONNECTED"] = "ERR_INTERNET_DISCONNECTED";
28
+ ErrorName["ERR_INTERNAL_SERVER_ERROR"] = "ERR_INTERNAL_SERVER_ERROR";
29
+ return ErrorName;
30
+ }({});
31
+ exports.ErrorName = ErrorName;
32
+ const NETWORK_ERROR_CODE = {
33
+ android: -2,
34
+ ios: -1009,
35
+ // These platforms are unhandled
36
+ windows: 0,
37
+ macos: 0,
38
+ web: 0
39
+ };
40
+ const viewerStyles = _reactNative.StyleSheet.create({
41
+ webview: {
42
+ minHeight: "100%",
43
+ minWidth: "100%"
44
+ }
45
+ });
46
+ const MapView = _ref => {
47
+ let {
48
+ domain,
49
+ // user,
50
+ // apikey,
51
+ configuration,
52
+ onLoad = () => {},
53
+ onLoadError = () => {},
54
+ onFloorChanged = () => {},
55
+ onPoiSelected = () => {},
56
+ onPoiDeselected = () => {},
57
+ onNavigationRequested = () => {},
58
+ onNavigationStarted = () => {},
59
+ onNavigationError = () => {},
60
+ onNavigationFinished = () => {},
61
+ style
62
+ //iOSMapViewIndex,
63
+ } = _ref;
64
+ const dispatch = (0, _utils.useDispatch)();
65
+ const webViewRef = (0, _react.useRef)();
66
+ // Local states
67
+ const [mapLoaded, setMapLoaded] = (0, _react.useState)(false);
68
+ const {
69
+ user: fullUser,
70
+ location,
71
+ directions,
72
+ navigation,
73
+ currentBuilding,
74
+ initializeBuildingById,
75
+ calculateRoute,
76
+ startNavigation,
77
+ stopNavigation,
78
+ error
79
+ } = (0, _hooks.default)();
80
+ const sendFollowUser = () => {
81
+ var _location$position;
82
+ if (webViewRef.current && mapLoaded && (location === null || location === void 0 ? void 0 : (_location$position = location.position) === null || _location$position === void 0 ? void 0 : _location$position.buildingIdentifier) === (configuration === null || configuration === void 0 ? void 0 : configuration.buildingIdentifier)) {
83
+ (0, _utils2.sendMessageToViewer)(webViewRef.current, _mapper.default.followUser(true));
84
+ }
85
+ };
86
+ (0, _react.useEffect)(() => {
87
+ configuration.buildingIdentifier && initializeBuildingById(configuration.buildingIdentifier);
88
+ // eslint-disable-next-line react-hooks/exhaustive-deps
89
+ }, [configuration.buildingIdentifier]);
90
+ (0, _react.useEffect)(() => {
91
+ if (error) {
92
+ console.error("Error code:", error.code ? error.code : " no code provided");
93
+ console.error("Error detected:", error.message);
94
+ }
95
+ }, [error]);
96
+
97
+ // Updated SDK location
98
+ (0, _react.useEffect)(() => {
99
+ if (!webViewRef.current || !location) return;
100
+ //console.debug('location', location);
101
+
102
+ (0, _utils2.sendMessageToViewer)(webViewRef.current, _mapper.default.location(location));
103
+ }, [location]);
104
+
105
+ // Updated SDK navigation
106
+ (0, _react.useEffect)(() => {
107
+ if (!webViewRef.current || !navigation) return;
108
+ (0, _utils2.sendMessageToViewer)(webViewRef.current, _mapper.default.navigation(navigation));
109
+ if (navigation.status === _store.NavigationStatus.START) {
110
+ onNavigationStarted({
111
+ navigation: _mapper.default.routeToResult(navigation)
112
+ });
113
+ }
114
+ if ((navigation === null || navigation === void 0 ? void 0 : navigation.type) === _store.NavigationUpdateType.destinationReached) {
115
+ onNavigationFinished({
116
+ navigation: _mapper.default.navigationToResult(navigation)
117
+ });
118
+ }
119
+ // eslint-disable-next-line react-hooks/exhaustive-deps
120
+ }, [navigation]);
121
+
122
+ // Updated SDK route
123
+ (0, _react.useEffect)(() => {
124
+ if (!webViewRef.current || !directions) return;
125
+ (0, _utils2.sendMessageToViewer)(webViewRef.current, _mapper.default.route(directions));
126
+ }, [directions]);
127
+ (0, _react.useEffect)(() => {
128
+ if (webViewRef.current && mapLoaded) {
129
+ (0, _utils2.sendMessageToViewer)(webViewRef.current, _mapper.default.initialConfiguration(style, configuration.enablePoiClustering, configuration.showPoiNames, configuration.minZoom, configuration.maxZoom, configuration.initialZoom, configuration.useDashboardTheme));
130
+ }
131
+ }, [webViewRef, mapLoaded, style, configuration.enablePoiClustering, configuration.showPoiNames, configuration.minZoom, configuration.maxZoom, configuration.initialZoom, configuration.useDashboardTheme]);
132
+ const handleRequestFromViewer = event => {
133
+ const eventParsed = JSON.parse(event.nativeEvent.data);
134
+ switch (eventParsed.type) {
135
+ case "app.map_is_ready":
136
+ onLoad({
137
+ status: "SUCCESS",
138
+ message: "Map is ready!"
139
+ });
140
+ sendFollowUser();
141
+ break;
142
+ case "directions.requested":
143
+ calculateRoute({
144
+ originId: JSON.parse(event.nativeEvent.data).payload.originIdentifier,
145
+ destinationId: JSON.parse(event.nativeEvent.data).payload.destinationIdentifier,
146
+ directionsOptions: JSON.parse(event.nativeEvent.data).payload.directionsOptions
147
+ });
148
+ break;
149
+ case "navigation.requested":
150
+ startNavigation({
151
+ originId: JSON.parse(event.nativeEvent.data).payload.originIdentifier,
152
+ destinationId: JSON.parse(event.nativeEvent.data).payload.destinationIdentifier,
153
+ directionsOptions: JSON.parse(event.nativeEvent.data).payload.directionsOptions,
154
+ callback: (status, _navigation) => status === "success" && navigation ? onNavigationRequested({
155
+ navigation: _mapper.default.routeToResult(_navigation)
156
+ }) : status === "error" && onNavigationError({})
157
+ });
158
+ break;
159
+ case "navigation.stopped":
160
+ stopNavigation();
161
+ break;
162
+ case "cartography.poi_selected":
163
+ onPoiSelected(eventParsed === null || eventParsed === void 0 ? void 0 : eventParsed.payload);
164
+ break;
165
+ case "cartography.poi_deselected":
166
+ onPoiDeselected(eventParsed === null || eventParsed === void 0 ? void 0 : eventParsed.payload);
167
+ break;
168
+ case "cartography.floor_changed":
169
+ onFloorChanged(eventParsed === null || eventParsed === void 0 ? void 0 : eventParsed.payload);
170
+ break;
171
+ case "cartography.building_selected":
172
+ if (!eventParsed.payload.identifier || currentBuilding && eventParsed.payload.identifier.toString() === currentBuilding.buildingIdentifier) {
173
+ return;
174
+ }
175
+ initializeBuildingById(eventParsed.payload.identifier.toString());
176
+ break;
177
+ default:
178
+ break;
179
+ }
180
+ };
181
+ return /*#__PURE__*/_react.default.createElement(_reactNativeWebview.default, {
182
+ ref: webViewRef,
183
+ source: {
184
+ uri: `${domain || SITUM_BASE_DOMAIN}/?email=${fullUser === null || fullUser === void 0 ? void 0 : fullUser.email}&apikey=${fullUser === null || fullUser === void 0 ? void 0 : fullUser.apiKey}&wl=true&global=true&mode=embed${configuration.buildingIdentifier ? `&buildingid=${configuration.buildingIdentifier}` : ""}&show=rts`
185
+ },
186
+ style: viewerStyles.webview,
187
+ javaScriptEnabled: true,
188
+ domStorageEnabled: true,
189
+ startInLoadingState: true,
190
+ onMessage: handleRequestFromViewer
191
+ // This is called on a lot of interactions with the map because of url change probably
192
+ ,
193
+ onLoadEnd: () => {
194
+ if (!webViewRef.current) return;
195
+ dispatch((0, _store.setWebViewRef)(webViewRef));
196
+ setMapLoaded(true);
197
+ },
198
+ onError: evt => {
199
+ const {
200
+ nativeEvent
201
+ } = evt;
202
+ // TODO: on render error should probably still try to render an html
203
+ if (nativeEvent.code === NETWORK_ERROR_CODE[_reactNative.Platform.OS]) {
204
+ onLoadError({
205
+ name: ErrorName.ERR_INTERNET_DISCONNECTED,
206
+ description: nativeEvent.description
207
+ });
208
+ } else {
209
+ // TODO: handle more errors
210
+ onLoadError({
211
+ name: ErrorName.ERR_INTERNAL_SERVER_ERROR,
212
+ description: nativeEvent.description
213
+ });
214
+ }
215
+ }
216
+ });
217
+ };
218
+ var _default = MapView;
219
+ exports.default = _default;
220
+ //# sourceMappingURL=MapView.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_react","_interopRequireWildcard","require","_reactNative","_reactNativeWebview","_interopRequireDefault","_hooks","_store","_utils","_utils2","_mapper","obj","__esModule","default","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set","SITUM_BASE_DOMAIN","ErrorName","exports","NETWORK_ERROR_CODE","android","ios","windows","macos","web","viewerStyles","StyleSheet","create","webview","minHeight","minWidth","MapView","_ref","domain","configuration","onLoad","onLoadError","onFloorChanged","onPoiSelected","onPoiDeselected","onNavigationRequested","onNavigationStarted","onNavigationError","onNavigationFinished","style","dispatch","useDispatch","webViewRef","useRef","mapLoaded","setMapLoaded","useState","user","fullUser","location","directions","navigation","currentBuilding","initializeBuildingById","calculateRoute","startNavigation","stopNavigation","error","useSitum","sendFollowUser","_location$position","current","position","buildingIdentifier","sendMessageToViewer","Mapper","followUser","useEffect","console","code","message","status","NavigationStatus","START","routeToResult","type","NavigationUpdateType","destinationReached","navigationToResult","route","initialConfiguration","enablePoiClustering","showPoiNames","minZoom","maxZoom","initialZoom","useDashboardTheme","handleRequestFromViewer","event","eventParsed","JSON","parse","nativeEvent","data","originId","payload","originIdentifier","destinationId","destinationIdentifier","directionsOptions","callback","_navigation","identifier","toString","createElement","ref","source","uri","email","apiKey","javaScriptEnabled","domStorageEnabled","startInLoadingState","onMessage","onLoadEnd","setWebViewRef","onError","evt","Platform","OS","name","ERR_INTERNET_DISCONNECTED","description","ERR_INTERNAL_SERVER_ERROR","_default"],"sourceRoot":"../../../../src","sources":["wayfinding/components/MapView.tsx"],"mappings":";;;;;;AAEA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AACA,IAAAE,mBAAA,GAAAC,sBAAA,CAAAH,OAAA;AAOA,IAAAI,M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AA,GAAAqI,QAAA"}
@@ -0,0 +1,401 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _react = require("react");
8
+ var _sdk = _interopRequireDefault(require("../../sdk"));
9
+ var _requestPermission = _interopRequireDefault(require("../../utils/requestPermission"));
10
+ var _index = require("../store/index");
11
+ var _utils = require("../store/utils");
12
+ var _utils2 = require("../utils");
13
+ var _mapper = _interopRequireDefault(require("../utils/mapper"));
14
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
+ /* eslint-disable @typescript-eslint/no-explicit-any */
16
+
17
+ const defaultNavigationOptions = {
18
+ distanceToGoalThreshold: 4,
19
+ outsideRouteThreshold: 5
20
+ };
21
+ // Hook to define references that point to functions
22
+ // used on listeners. These references are updated whenever
23
+ // one of the dependencies on the array change
24
+ const useCallbackRef = (fn, deps) => {
25
+ const fnRef = (0, _react.useRef)(fn);
26
+ (0, _react.useEffect)(() => {
27
+ fnRef.current = fn;
28
+ // eslint-disable-next-line react-hooks/exhaustive-deps
29
+ }, deps);
30
+ return fnRef;
31
+ };
32
+ const useSitum = () => {
33
+ const dispatch = (0, _utils.useDispatch)();
34
+ const webViewRef = (0, _utils.useSelector)(_index.selectWebViewRef);
35
+ const isSdkInitialized = (0, _utils.useSelector)(_index.selectIsSDKInitialized);
36
+ const user = (0, _utils.useSelector)(_index.selectUser);
37
+ const location = (0, _utils.useSelector)(_index.selectLocation);
38
+ const locationStatus = (0, _utils.useSelector)(_index.selectLocationStatus);
39
+ const buildings = (0, _utils.useSelector)(_index.selectBuildings);
40
+ const currentBuilding = (0, _utils.useSelector)(_index.selectCurrentBuilding);
41
+ const pois = (0, _utils.useSelector)(_index.selectPois);
42
+ const directions = (0, _utils.useSelector)(_index.selectDirections);
43
+ const navigation = (0, _utils.useSelector)(_index.selectNavigation);
44
+ const error = (0, _utils.useSelector)(_index.selectError);
45
+ const destinationPoiID = (0, _utils.useSelector)(_index.selectDestinationPoiID);
46
+ const [lockDirections, setLockDirections] = (0, _react.useState)(false);
47
+ const initSitumSdk = async _ref => {
48
+ let {
49
+ email,
50
+ apiKey,
51
+ startPositions = true,
52
+ fetchCartography = true,
53
+ useRemoteConfig = true
54
+ } = _ref;
55
+ return (
56
+ // TODO fix this async/await
57
+ // eslint-disable-next-line no-async-promise-executor
58
+ new Promise(async (resolve, reject) => {
59
+ if (!isSdkInitialized) {
60
+ _sdk.default.initSitumSDK();
61
+ (0, _index.setSdkInitialized)(true);
62
+ }
63
+ if (email && apiKey) {
64
+ dispatch((0, _index.setAuth)({
65
+ email,
66
+ apiKey
67
+ }));
68
+ } else {
69
+ email = user.email;
70
+ apiKey = user.apiKey;
71
+ }
72
+ _sdk.default.setApiKey(email, apiKey, response => {
73
+ if (response && Boolean(response.success) === true) {
74
+ console.debug("Situm > hook > Successful authentication.");
75
+ } else {
76
+ reject("Situm > hook > Failure while authenticating.");
77
+ }
78
+ });
79
+ useRemoteConfig && _sdk.default.setUseRemoteConfig(`${useRemoteConfig}`, () => {
80
+ console.debug("Situm > hook > Using remote config");
81
+ });
82
+ startPositions && (await (0, _requestPermission.default)().then(() => {
83
+ startPositioning();
84
+ }).catch(e => {
85
+ console.error(e);
86
+ reject(e);
87
+ }));
88
+ fetchCartography && (await initializeBuildings().catch(e => {
89
+ console.error(e);
90
+ reject(e);
91
+ }));
92
+ resolve();
93
+ })
94
+ );
95
+ };
96
+
97
+ // Cartography
98
+ const initializeBuildings = async () => new Promise((resolve, reject) => {
99
+ console.debug("Retrieving buildings from Situm API");
100
+ _sdk.default.fetchBuildings(buildingArray => {
101
+ dispatch((0, _index.setBuildings)(buildingArray));
102
+ console.debug("Situm > hook > Successfully retrieved buildings.");
103
+ resolve(buildingArray);
104
+ }, _error => {
105
+ console.error(`Situm > hook > Could not retrieve buildings: ${_error}`);
106
+ reject(`Could not retrieve buildings: ${_error}`);
107
+ dispatch((0, _index.setError)({
108
+ message: _error,
109
+ code: 3011
110
+ }));
111
+ });
112
+ });
113
+ const initializeBuildingById = async buildingId => {
114
+ if (buildings.length === 0) return;
115
+ const newBuilding = buildings.find(b => b.buildingIdentifier === buildingId);
116
+ if (newBuilding) {
117
+ dispatch((0, _index.setCurrentBuilding)(newBuilding));
118
+ initializeBuildingPois(newBuilding);
119
+ } else {
120
+ console.warn(`Situm > hook > No building found for id ${buildingId}`);
121
+ }
122
+ };
123
+ const initializeBuilding = async b => {
124
+ dispatch((0, _index.setCurrentBuilding)(b));
125
+ initializeBuildingPois(b);
126
+ };
127
+ const initializeBuildingPois = b => {
128
+ _sdk.default.fetchBuildingInfo(b, buildingInfo => {
129
+ console.debug("Situm > hook > Successfully retrieved pois of the selected building. ");
130
+
131
+ // Please, do not change the next line. iOS sends data as indoorPois and Android sends it as indoorPOIs
132
+ const buildingPois = (buildingInfo === null || buildingInfo === void 0 ? void 0 : buildingInfo.indoorPOIs) || (buildingInfo === null || buildingInfo === void 0 ? void 0 : buildingInfo.indoorPois) || [];
133
+ dispatch((0, _index.setPois)(buildingPois));
134
+ }, err => {
135
+ console.error(`Situm > hook > Could not initialize building pois: ${error}`);
136
+ dispatch((0, _index.setError)({
137
+ message: err,
138
+ code: 3021
139
+ }));
140
+ });
141
+ };
142
+ const startPositioning = () => {
143
+ console.debug("Situm > hook > Starting positioning...");
144
+ if (location.status !== _index.PositioningStatus.STOPPED) {
145
+ console.debug("Situm > hook > Positioning has already started");
146
+ return;
147
+ }
148
+
149
+ // Declare the locationOptions (empty = default parameters)
150
+ const locationOptions = {
151
+ useDeadReckoning: false
152
+ };
153
+ // Start positioning
154
+ _sdk.default.startPositioning(newLocation => {
155
+ dispatch((0, _index.setLocation)({
156
+ ...newLocation
157
+ }));
158
+ }, status => {
159
+ if (status.statusName in _index.PositioningStatus) {
160
+ console.debug(`Situm > hook > Positioning state updated ${status.statusName}`);
161
+ dispatch((0, _index.setLocationStatus)(status.statusName));
162
+ }
163
+ }, err => {
164
+ console.error(`Situm > hook > Error while positioning: ${err}}`);
165
+ //@ts-ignore
166
+ dispatch((0, _index.setError)({
167
+ message: err,
168
+ code: 3001
169
+ }));
170
+ }, locationOptions);
171
+ console.debug(`Successfully started positioning`);
172
+ };
173
+ const stopPositioning = async () => {
174
+ console.debug(`Stopping positioning ...`);
175
+ _sdk.default.stopPositioning(success => {
176
+ if (success) {
177
+ dispatch((0, _index.resetLocation)());
178
+ console.debug("Situm > hook > Successfully stopped positioning");
179
+ } else {
180
+ console.error("Situm > hook > Could not stop positioning");
181
+ }
182
+ });
183
+ };
184
+
185
+ // Routes
186
+ const requestDirections = async (building, from, to, directionsOptions) => {
187
+ console.debug("Requesting directions");
188
+ const fromPoint = {
189
+ floorIdentifier: from.floorIdentifier,
190
+ buildingIdentifier: from.buildingIdentifier,
191
+ coordinate: from.coordinate
192
+ };
193
+ const toPoint = {
194
+ floorIdentifier: to.floorIdentifier,
195
+ buildingIdentifier: to.buildingIdentifier,
196
+ coordinate: to.coordinate
197
+ };
198
+ return new Promise((resolve, reject) => {
199
+ _sdk.default.requestDirections([building, fromPoint, toPoint, directionsOptions], newDirections => {
200
+ console.debug("Situm > hook > Successfully computed route");
201
+ resolve(newDirections);
202
+ }, err => {
203
+ console.debug(`Situm > hook > Could not compute route: ${err}`);
204
+ dispatch((0, _index.setError)({
205
+ message: err,
206
+ code: 3041
207
+ }));
208
+ reject(err);
209
+ });
210
+ });
211
+ };
212
+ const calculateRoute = async _ref2 => {
213
+ let {
214
+ originId,
215
+ destinationId,
216
+ directionsOptions,
217
+ updateRoute = true
218
+ } = _ref2;
219
+ const poiOrigin = pois.find(p => p.identifier === (originId === null || originId === void 0 ? void 0 : originId.toString()));
220
+ const poiDestination = pois.find(p => p.identifier === (destinationId === null || destinationId === void 0 ? void 0 : destinationId.toString()));
221
+ if (!poiDestination || !poiOrigin && originId !== -1 || lockDirections) {
222
+ console.debug(`Situm > hook >Could not compute route for origin: ${originId} or destination: ${destinationId} (lockDirections: ${lockDirections})`);
223
+ return;
224
+ }
225
+ const from = originId === -1 && location ? location.position : {
226
+ buildingIdentifier: poiOrigin.buildingIdentifier,
227
+ floorIdentifier: poiOrigin.floorIdentifier,
228
+ cartesianCoordinate: poiOrigin.cartesianCoordinate,
229
+ coordinate: poiOrigin.coordinate
230
+ };
231
+ const to = {
232
+ buildingIdentifier: poiDestination.buildingIdentifier,
233
+ floorIdentifier: poiDestination.floorIdentifier,
234
+ cartesianCoordinate: poiDestination.cartesianCoordinate,
235
+ coordinate: poiDestination.coordinate
236
+ };
237
+
238
+ // iOS workaround -> does not allow for several direction petitions
239
+ setLockDirections(true);
240
+ return requestDirections(currentBuilding, from, to, directionsOptions).then(newDirections => {
241
+ const extendedRoute = {
242
+ ...newDirections,
243
+ originId,
244
+ destinationId,
245
+ type: directionsOptions === null || directionsOptions === void 0 ? void 0 : directionsOptions.accessibilityMode
246
+ };
247
+ updateRoute && dispatch((0, _index.setDirections)(extendedRoute));
248
+ return directions;
249
+ }).catch(e => {
250
+ dispatch((0, _index.setDirections)({
251
+ error: JSON.stringify(e)
252
+ }));
253
+ }).finally(() => setLockDirections(false));
254
+ };
255
+
256
+ // Navigation
257
+ // TODO: this function is async and we use a callback, why not use a promise?
258
+ const startNavigation = async _ref3 => {
259
+ let {
260
+ callback,
261
+ destinationId,
262
+ directionsOptions,
263
+ navigationOptions,
264
+ originId
265
+ } = _ref3;
266
+ calculateRoute({
267
+ originId,
268
+ destinationId,
269
+ directionsOptions,
270
+ updateRoute: false
271
+ }).then(r => {
272
+ if (originId !== -1 || !location || !r) {
273
+ callback && callback("error");
274
+ return;
275
+ }
276
+ dispatch((0, _index.setNavigation)({
277
+ status: _index.NavigationStatus.START,
278
+ ...r
279
+ }));
280
+ callback && callback("success", r);
281
+ _sdk.default.requestNavigationUpdates(update => {
282
+ const newNavType = update.type && update.type in _index.NavigationUpdateType && _index.NavigationUpdateType[update.type] || _index.NavigationUpdateType.progress;
283
+ dispatch((0, _index.setNavigation)({
284
+ currentIndication: update === null || update === void 0 ? void 0 : update.currentIndication,
285
+ routeStep: update === null || update === void 0 ? void 0 : update.routeStep,
286
+ distanceToGoal: update === null || update === void 0 ? void 0 : update.distanceToGoal,
287
+ points: update === null || update === void 0 ? void 0 : update.points,
288
+ type: newNavType,
289
+ segments: update === null || update === void 0 ? void 0 : update.segments,
290
+ status: _index.NavigationStatus.UPDATE
291
+ }));
292
+ }, err => {
293
+ console.error(`Situm > hook >Could not update navigation: ${err}`);
294
+ callback && callback("error");
295
+ dispatch((0, _index.setError)({
296
+ message: err,
297
+ code: 3051
298
+ }));
299
+ stopNavigationRef.current();
300
+ }, {
301
+ ...defaultNavigationOptions,
302
+ ...navigationOptions
303
+ });
304
+ });
305
+ };
306
+ const navigateToPoi = async _ref4 => {
307
+ let {
308
+ poi,
309
+ poiId
310
+ } = _ref4;
311
+ if (!poi && !poiId) return;
312
+ const validPoi = pois === null || pois === void 0 ? void 0 : pois.find(p => {
313
+ var _poi$id;
314
+ return (p === null || p === void 0 ? void 0 : p.identifier) === (poiId === null || poiId === void 0 ? void 0 : poiId.toString()) ||
315
+ // @ts-ignore
316
+ (p === null || p === void 0 ? void 0 : p.identifier) === (poi === null || poi === void 0 ? void 0 : (_poi$id = poi.id) === null || _poi$id === void 0 ? void 0 : _poi$id.toString());
317
+ });
318
+ if (!validPoi) {
319
+ console.error("Situm > hook > Invalid value as poi or poiId");
320
+ return;
321
+ }
322
+ (0, _utils2.sendMessageToViewer)(webViewRef.current, _mapper.default.navigateToPoi({
323
+ // @ts-ignore
324
+ navigationTo: (poi === null || poi === void 0 ? void 0 : poi.id) || poiId
325
+ }));
326
+ };
327
+ const stopNavigation = () => {
328
+ console.debug("Stopping navigation");
329
+ if (!navigation || navigation.status === _index.NavigationStatus.STOP) {
330
+ return;
331
+ }
332
+ _sdk.default.removeNavigationUpdates(response => {
333
+ if (response && response.success) {
334
+ console.debug("Situm > hook > Successfully removed navigation updates");
335
+ } else {
336
+ console.error("Situm > hook > Could not remove navigation updates");
337
+ }
338
+ });
339
+ dispatch((0, _index.setNavigation)({
340
+ status: _index.NavigationStatus.STOP
341
+ }));
342
+ dispatch((0, _index.setDestinationPoiID)(undefined));
343
+ };
344
+ const cancelNavigation = () => {
345
+ stopNavigation();
346
+ (0, _utils2.sendMessageToViewer)(webViewRef.current, _mapper.default.cancelNavigation());
347
+ };
348
+ const selectPoi = poiId => {
349
+ const poi = pois === null || pois === void 0 ? void 0 : pois.find(p => (p === null || p === void 0 ? void 0 : p.identifier) === (poiId === null || poiId === void 0 ? void 0 : poiId.toString()));
350
+ if (!poi) {
351
+ console.error("Situm > hook > Invalid value as poiId");
352
+ return;
353
+ }
354
+ if (navigation.status !== _index.NavigationStatus.STOP) {
355
+ console.error("Situm > hook > Navigation on course, poi selection is unavailable");
356
+ return;
357
+ }
358
+ (0, _utils2.sendMessageToViewer)(webViewRef.current, _mapper.default.selectPoi(poiId));
359
+ };
360
+ const stopNavigationRef = useCallbackRef(stopNavigation, [navigation]);
361
+ (0, _react.useEffect)(() => {
362
+ if (!navigation || navigation.status === _index.NavigationStatus.STOP || !location) {
363
+ return;
364
+ }
365
+ _sdk.default.updateNavigationWithLocation(location, info => {
366
+ console.debug(info);
367
+ }, e => {
368
+ console.error(`Situm > hook > Error on navigation update ${e}`);
369
+ });
370
+ // eslint-disable-next-line react-hooks/exhaustive-deps
371
+ }, [location]);
372
+ return {
373
+ // States
374
+ user,
375
+ location,
376
+ locationStatus,
377
+ currentBuilding,
378
+ buildings,
379
+ pois,
380
+ directions,
381
+ navigation,
382
+ error,
383
+ destinationPoiID,
384
+ // Functions
385
+ initSitumSdk,
386
+ initializeBuildings,
387
+ initializeBuilding,
388
+ initializeBuildingById,
389
+ startPositioning,
390
+ stopPositioning,
391
+ calculateRoute,
392
+ startNavigation,
393
+ stopNavigation,
394
+ cancelNavigation,
395
+ selectPoi,
396
+ navigateToPoi
397
+ };
398
+ };
399
+ var _default = useSitum;
400
+ exports.default = _default;
401
+ //# sourceMappingURL=index.js.map