@situm/react-native 3.16.3 → 3.17.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.
@@ -9,6 +9,7 @@ export interface State {
9
9
  webViewRef: MutableRefObject<undefined> | undefined;
10
10
  sdkInitialized: boolean;
11
11
  user?: User;
12
+ apiDomain?: string;
12
13
  location?: Location;
13
14
  locationStatus?: LocationStatusName;
14
15
  buildings: Building[] | null;
@@ -28,6 +29,7 @@ export declare const SitumContext: React.Context<{
28
29
  export declare const selectWebViewRef: (state: State) => React.MutableRefObject<undefined> | undefined;
29
30
  export declare const selectIsSDKInitialized: (state: State) => boolean;
30
31
  export declare const selectUser: (state: State) => User | undefined;
32
+ export declare const selectApiDomain: (state: State) => string | undefined;
31
33
  export declare const selectLocation: (state: State) => Location | undefined;
32
34
  export declare const selectLocationStatus: (state: State) => LocationStatusName | undefined;
33
35
  export declare const selectBuildings: (state: State) => Building[] | null;
@@ -46,11 +48,29 @@ export declare const UseSitumContext: React.Context<{
46
48
  useSitum: any;
47
49
  } | undefined>;
48
50
  /**
49
- * Main context of the application, stores the plugins' state.
51
+ * Main context of the application, stores the plugin's state.
50
52
  */
51
53
  declare const SitumProvider: React.FC<React.PropsWithChildren<{
54
+ /**
55
+ * Your Situm email account.
56
+ */
52
57
  email?: string;
53
- apiKey?: string;
58
+ /**
59
+ * Your Situm API key. Find your API key at your [Situm dashboard's profile](https://dashboard.situm.com/accounts/profile)
60
+ *
61
+ * When specifying a valid situm API key in this parameter, you won't need to call later on the `SitumPlugin.init()` & `SitumPlugin.setApiKey()` methods,
62
+ * and also you won't need to specify `MapViewConfiguration.situmApiKey` when configuring your MapView.
63
+ */
64
+ apiKey: string;
65
+ /**
66
+ * Set the API domain that will be used by the native SDKs and MapView to obtain the situm's data.
67
+ *
68
+ * When specifying a valid domain in this parameter, you won't need to call later on the `SitumPlugin.setDashboardURL()` method,
69
+ * and also you won't need to specify `MapViewConfiguration.apiDomain` when configuring your MapView.
70
+ *
71
+ * Defaults to "api.situm.com"
72
+ */
73
+ apiDomain?: string;
54
74
  }>>;
55
75
  export default SitumProvider;
56
76
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/wayfinding/store/index.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,EAAiB,KAAK,gBAAgB,EAAc,MAAM,OAAO,CAAC;AAEhF,OAAO,EACL,KAAK,QAAQ,EACb,KAAK,UAAU,EACf,KAAK,KAAK,EACV,KAAK,QAAQ,EACb,KAAK,kBAAkB,EACvB,KAAK,GAAG,EACT,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAI/D,UAAU,IAAI;IACZ,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,KAAK;IACpB,UAAU,EAAE,gBAAgB,CAAC,SAAS,CAAC,GAAG,SAAS,CAAC;IACpD,cAAc,EAAE,OAAO,CAAC;IACxB,IAAI,CAAC,EAAE,IAAI,CAAC;IACZ,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,cAAc,CAAC,EAAE,kBAAkB,CAAC;IACpC,SAAS,EAAE,QAAQ,EAAE,GAAG,IAAI,CAAC;IAC7B,eAAe,EAAE,QAAQ,GAAG,SAAS,CAAC;IACtC,IAAI,EAAE,GAAG,EAAE,CAAC;IACZ,UAAU,CAAC,EAAE,UAAU,CAAC;IACxB,UAAU,CAAC,EAAE,kBAAkB,CAAC;IAChC,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,KAAK,CAAC,EAAE,KAAK,CAAC;IACd,kBAAkB,EAAE,MAAM,CAAC;CAC5B;AAED,eAAO,MAAM,YAAY,EAAE,KAc1B,CAAC;AAEF,eAAO,MAAM,YAAY;WACd,KAAK;cAAY,KAAK,CAAC,QAAQ,CAAC,C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AAC;IACf;;;;;OAKG;IACH,MAAM,EAAE,MAAM,CAAC;IACf;;;;;;;OAOG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC,CA2CH,CAAC;AAEF,eAAe,aAAa,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@situm/react-native",
3
- "version": "3.16.3",
3
+ "version": "3.17.0",
4
4
  "description": "Situm Wayfinding for React Native. Integrate plug&play navigation experience with indoor maps, routes and turn-by-turn directions in no time. With the power of Situm.",
5
5
  "repository": "https://github.com/situmtech/react-native",
6
6
  "author": "Situm Technologies <mobile@situm.com>",
@@ -156,7 +156,7 @@
156
156
  "lib/"
157
157
  ],
158
158
  "sdkVersions": {
159
- "android": "3.33.1@aar",
159
+ "android": "3.33.2@aar",
160
160
  "ios": "3.34.9"
161
161
  }
162
162
  }
package/src/sdk/index.ts CHANGED
@@ -315,6 +315,13 @@ export default class SitumPlugin {
315
315
  */
316
316
 
317
317
  static setDashboardURL = (url: string) => {
318
+ if (!url.startsWith("https://")) {
319
+ url = "https://" + url;
320
+ }
321
+ if (url.endsWith("/")) {
322
+ url = url.substring(0, url.length - 1);
323
+ }
324
+
318
325
  return exceptionWrapper<void>(({ onCallback }) => {
319
326
  RNCSitumPlugin.setDashboardURL(url, (response: { success: boolean }) => {
320
327
  onCallback(response, "Failed to set dashboard URL.");
@@ -4,6 +4,7 @@ import React, {
4
4
  useCallback,
5
5
  useEffect,
6
6
  useImperativeHandle,
7
+ useMemo,
7
8
  useRef,
8
9
  useState,
9
10
  } from "react";
@@ -22,7 +23,13 @@ import type {
22
23
 
23
24
  import SitumPlugin from "../../sdk";
24
25
  import useSitum from "../hooks";
25
- import { setError, setLocationStatus } from "../store";
26
+ import {
27
+ selectApiDomain,
28
+ selectUser,
29
+ setError,
30
+ setLocationStatus,
31
+ } from "../store";
32
+ import { useSelector } from "../store/utils";
26
33
  import {
27
34
  type CartographySelectionOptions,
28
35
  type MapViewDirectionsOptions,
@@ -65,10 +72,14 @@ export type MapViewConfiguration = {
65
72
  */
66
73
  viewerDomain?: string;
67
74
  /**
68
- * ** Required **
69
- * Your Situm API key. Find your API key at your [situm profile](https://dashboard.situm.com/accounts/profile)
75
+ * Your Situm API key. Find your API key at your [Situm dashboard's profile](https://dashboard.situm.com/accounts/profile)
76
+ *
77
+ * Since X.YY.ZZ version this parameter is not required. Instead, you should specify your apiKey
78
+ * at the root of your app with `SitumProvider.apiKey` for the correct usage of the plugin.
79
+ * If {@param situmApiKey} is specified, `SitumProvider.apiKey` will be ignored.
70
80
  */
71
- situmApiKey: string;
81
+ // TODO: set the version on the doc right before releasing this version.
82
+ situmApiKey?: string;
72
83
  /**
73
84
  * @deprecated Use `profile` instead.
74
85
  * A String identifier that allows you to remotely configure all map settings.
@@ -169,6 +180,9 @@ const MapView = React.forwardRef<MapViewRef, MapViewProps>(
169
180
  const [buildingIdentifier, setBuildingIdentifier] = useState<string>(
170
181
  configuration.buildingIdentifier,
171
182
  );
183
+
184
+ const user = useSelector(selectUser);
185
+ const apiDomain = useSelector(selectApiDomain);
172
186
  const {
173
187
  init,
174
188
  location,
@@ -586,8 +600,31 @@ const MapView = React.forwardRef<MapViewRef, MapViewProps>(
586
600
  return true;
587
601
  };
588
602
 
589
- const _effectiveProfile = () => {
590
- let effectiveProfile = configuration.profile;
603
+ const _effectiveApiKey = useMemo(() => {
604
+ const internalApiKey = user?.apiKey;
605
+ const configApiKey = configuration.situmApiKey;
606
+
607
+ if (!configApiKey && !internalApiKey) {
608
+ console.error(
609
+ "No apiKey was specified. Make sure to be authenticated either by specifying the SitumProvider.apiKey or by specifying the MapViewConfiguration.situmApiKey.",
610
+ );
611
+ }
612
+
613
+ return configApiKey ?? internalApiKey;
614
+ }, [user?.apiKey, configuration.situmApiKey]);
615
+
616
+ const _effectiveProfile = useMemo(() => {
617
+ let effectiveProfile: any = "";
618
+
619
+ if (
620
+ configuration.profile?.length === 0 &&
621
+ configuration.remoteIdentifier?.length === 0
622
+ ) {
623
+ effectiveProfile = "";
624
+ }
625
+
626
+ effectiveProfile = configuration.profile;
627
+
591
628
  if (
592
629
  configuration.remoteIdentifier &&
593
630
  configuration.remoteIdentifier.length > 0
@@ -599,8 +636,31 @@ const MapView = React.forwardRef<MapViewRef, MapViewProps>(
599
636
  effectiveProfile = configuration.remoteIdentifier;
600
637
  }
601
638
  }
639
+
602
640
  return effectiveProfile;
603
- };
641
+ }, [configuration.profile, configuration.remoteIdentifier]);
642
+
643
+ const _effectiveApiDomain = useMemo(() => {
644
+ let finalApiDomain = configuration.apiDomain ?? apiDomain;
645
+
646
+ if (!finalApiDomain) return "";
647
+
648
+ finalApiDomain = finalApiDomain.replace("https://", "");
649
+ finalApiDomain = finalApiDomain.replace("/", "");
650
+
651
+ return `&domain=${finalApiDomain}`;
652
+ }, [apiDomain, configuration.apiDomain]);
653
+
654
+ const _effectiveBuildingId = useMemo(() => {
655
+ let finalBuildingIdentifier = "";
656
+ const buildingId = configuration.buildingIdentifier;
657
+
658
+ if (buildingId && buildingId.length > 0) {
659
+ finalBuildingIdentifier = `&buildingid=${buildingId}`;
660
+ }
661
+
662
+ return finalBuildingIdentifier;
663
+ }, [configuration.buildingIdentifier]);
604
664
 
605
665
  const _disableInternalWebViewTTSEngine = () => {
606
666
  sendMessageToViewer(
@@ -615,15 +675,9 @@ const MapView = React.forwardRef<MapViewRef, MapViewProps>(
615
675
  <WebView
616
676
  ref={webViewRef}
617
677
  source={{
618
- uri: `${configuration.viewerDomain || SITUM_BASE_DOMAIN}/${
619
- _effectiveProfile() ? `id/${_effectiveProfile()}` : ""
620
- }?&apikey=${
621
- configuration.situmApiKey
622
- }&wl=true&global=true&mode=embed${
623
- configuration.buildingIdentifier
624
- ? `&buildingid=${configuration.buildingIdentifier}`
625
- : ""
626
- }&show=rts`,
678
+ uri: `${configuration.viewerDomain || SITUM_BASE_DOMAIN}/${_effectiveProfile}?apikey=${
679
+ _effectiveApiKey
680
+ }${_effectiveApiDomain}${_effectiveBuildingId}&mode=embed`,
627
681
  }}
628
682
  style={StyleSheet.flatten([viewerStyles.webview, style])}
629
683
  limitsNavigationsToAppBoundDomains={true}
@@ -1,3 +1,4 @@
1
+ /* eslint-disable no-case-declarations */
1
2
  /* eslint-disable @typescript-eslint/no-explicit-any */
2
3
  import { useContext, useState } from "react";
3
4
 
@@ -66,15 +67,15 @@ export const useSitumInternal = () => {
66
67
  (internalCall: InternalCall) => {
67
68
  switch (internalCall.type) {
68
69
  case InternalCallType.LOCATION:
69
- let location = internalCall.get<Location>();
70
+ const receivedLocation = internalCall.get<Location>();
70
71
  dispatch(
71
72
  setLocation({
72
- ...location,
73
+ ...receivedLocation,
73
74
  }),
74
75
  );
75
76
  break;
76
77
  case InternalCallType.LOCATION_STATUS:
77
- let statusName = internalCall.get<string>();
78
+ const statusName = internalCall.get<string>();
78
79
  if (statusName in LocationStatusName) {
79
80
  dispatch(setLocationStatus(statusName));
80
81
  }
@@ -84,8 +85,8 @@ export const useSitumInternal = () => {
84
85
  dispatch(resetLocation());
85
86
  break;
86
87
  case InternalCallType.LOCATION_ERROR:
87
- let error = internalCall.get<Error>();
88
- dispatch(setError(error));
88
+ const receivedError = internalCall.get<Error>();
89
+ dispatch(setError(receivedError));
89
90
  break;
90
91
  case InternalCallType.NAVIGATION_START:
91
92
  dispatch(
@@ -104,7 +105,7 @@ export const useSitumInternal = () => {
104
105
  );
105
106
  break;
106
107
  case InternalCallType.NAVIGATION_PROGRESS:
107
- let progress = internalCall.get<NavigationProgress>();
108
+ const progress = internalCall.get<NavigationProgress>();
108
109
  dispatch(
109
110
  setNavigation({
110
111
  currentIndication: progress?.currentIndication,
@@ -1,6 +1,13 @@
1
1
  /* eslint-disable @typescript-eslint/no-explicit-any */
2
- import React, { createContext, type MutableRefObject, useReducer } from "react";
2
+ import React, {
3
+ createContext,
4
+ type MutableRefObject,
5
+ useEffect,
6
+ useReducer,
7
+ useState,
8
+ } from "react";
3
9
 
10
+ import SitumPlugin from "../../sdk";
4
11
  import {
5
12
  type Building,
6
13
  type Directions,
@@ -22,6 +29,7 @@ export interface State {
22
29
  webViewRef: MutableRefObject<undefined> | undefined;
23
30
  sdkInitialized: boolean;
24
31
  user?: User;
32
+ apiDomain?: string;
25
33
  location?: Location;
26
34
  locationStatus?: LocationStatusName;
27
35
  buildings: Building[] | null;
@@ -38,6 +46,7 @@ export const initialState: State = {
38
46
  webViewRef: undefined,
39
47
  sdkInitialized: false,
40
48
  user: undefined,
49
+ apiDomain: undefined,
41
50
  location: undefined,
42
51
  locationStatus: undefined,
43
52
  buildings: null,
@@ -101,7 +110,7 @@ const store = createStore<State>({
101
110
  },
102
111
  setBuildingIdentifier: (
103
112
  state: State,
104
- payload: State["buildingIdentifier"]
113
+ payload: State["buildingIdentifier"],
105
114
  ) => {
106
115
  return { ...state, buildingIdentifier: payload };
107
116
  },
@@ -120,6 +129,10 @@ export const selectUser = (state: State) => {
120
129
  return state.user;
121
130
  };
122
131
 
132
+ export const selectApiDomain = (state: State) => {
133
+ return state.apiDomain;
134
+ };
135
+
123
136
  export const selectLocation = (state: State) => {
124
137
  return state.location;
125
138
  };
@@ -181,7 +194,7 @@ export const {
181
194
  * Context specifically to store the only instance of our hook.
182
195
  */
183
196
  export const UseSitumContext = createContext<{ useSitum: any } | undefined>(
184
- undefined
197
+ undefined,
185
198
  );
186
199
 
187
200
  const UseSitumProvider: React.FC<{ children: React.ReactNode }> = ({
@@ -199,19 +212,56 @@ const UseSitumProvider: React.FC<{ children: React.ReactNode }> = ({
199
212
  };
200
213
 
201
214
  /**
202
- * Main context of the application, stores the plugins' state.
215
+ * Main context of the application, stores the plugin's state.
203
216
  */
204
217
  const SitumProvider: React.FC<
205
218
  React.PropsWithChildren<{
219
+ /**
220
+ * Your Situm email account.
221
+ */
206
222
  email?: string;
207
- apiKey?: string;
223
+ /**
224
+ * Your Situm API key. Find your API key at your [Situm dashboard's profile](https://dashboard.situm.com/accounts/profile)
225
+ *
226
+ * When specifying a valid situm API key in this parameter, you won't need to call later on the `SitumPlugin.init()` & `SitumPlugin.setApiKey()` methods,
227
+ * and also you won't need to specify `MapViewConfiguration.situmApiKey` when configuring your MapView.
228
+ */
229
+ apiKey: string;
230
+ /**
231
+ * Set the API domain that will be used by the native SDKs and MapView to obtain the situm's data.
232
+ *
233
+ * When specifying a valid domain in this parameter, you won't need to call later on the `SitumPlugin.setDashboardURL()` method,
234
+ * and also you won't need to specify `MapViewConfiguration.apiDomain` when configuring your MapView.
235
+ *
236
+ * Defaults to "api.situm.com"
237
+ */
238
+ apiDomain?: string;
208
239
  }>
209
- > = ({ email, apiKey, children }) => {
240
+ > = ({ email, apiKey, apiDomain, children }) => {
210
241
  const [state, dispatch] = useReducer(store.reducer, {
211
242
  ...store.initialState,
212
243
  user: { email, apiKey },
244
+ apiDomain: apiDomain,
213
245
  });
214
246
 
247
+ const [isInitialized, setIsInitialized] = useState(false);
248
+
249
+ useEffect(() => {
250
+ try {
251
+ SitumPlugin.init();
252
+ apiDomain && SitumPlugin.setDashboardURL(apiDomain);
253
+ if (!apiKey) {
254
+ throw new Error(
255
+ "Please specify SitumProvider.apiKey to be able to successfully use SitumPlugin and MapView.",
256
+ );
257
+ }
258
+ SitumPlugin.setApiKey(apiKey);
259
+ } catch (e) {
260
+ console.error(`SitumProvider > Could not initialize ${e}`);
261
+ }
262
+ setIsInitialized(true);
263
+ }, [apiKey, apiDomain]);
264
+
215
265
  return (
216
266
  <SitumContext.Provider
217
267
  value={{
@@ -219,7 +269,14 @@ const SitumProvider: React.FC<
219
269
  dispatch,
220
270
  }}
221
271
  >
222
- <UseSitumProvider>{children}</UseSitumProvider>
272
+ {/**
273
+ * Make sure to execute first SitumProvider's initialization & authentication useEffect(),
274
+ * before letting children components rendering MapView or calling SitumPlugin methods.
275
+ *
276
+ * If we directly let the `children` render, the children's useEffect() will execute before SitumProvider's useEffect().
277
+ * This causes a crash when the children wants to access SitumPlugin before it is initialized.
278
+ */}
279
+ <UseSitumProvider>{isInitialized ? children : <></>}</UseSitumProvider>
223
280
  </SitumContext.Provider>
224
281
  );
225
282
  };