react-native-visit-rn-sdk 6.0.4 → 7.0.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 (93) hide show
  1. package/README.md +286 -195
  2. package/android/build.gradle +4 -1
  3. package/android/gradle.properties +4 -4
  4. package/android/src/main/AndroidManifest.xml +11 -5
  5. package/android/src/main/AndroidManifestNew.xml +11 -5
  6. package/android/src/main/java/com/visitrnsdk/VisitFitnessModule.kt +642 -0
  7. package/android/src/main/java/com/visitrnsdk/VisitRnSdkPackage.kt +1 -1
  8. package/android/src/main/java/com/visitrnsdk/VisitSessionStorage.kt +50 -0
  9. package/ios/VisitRnSdkViewManager.h +23 -1
  10. package/ios/VisitRnSdkViewManager.m +1259 -8
  11. package/lib/commonjs/Services.js +35 -0
  12. package/lib/commonjs/Services.js.map +1 -0
  13. package/lib/commonjs/constants.js +11 -0
  14. package/lib/commonjs/constants.js.map +1 -0
  15. package/lib/commonjs/index.android.js +451 -206
  16. package/lib/commonjs/index.android.js.map +1 -1
  17. package/lib/commonjs/index.ios.js +266 -114
  18. package/lib/commonjs/index.ios.js.map +1 -1
  19. package/lib/module/Services.js +27 -0
  20. package/lib/module/Services.js.map +1 -0
  21. package/lib/module/constants.js +5 -0
  22. package/lib/module/constants.js.map +1 -0
  23. package/lib/module/index.android.js +451 -207
  24. package/lib/module/index.android.js.map +1 -1
  25. package/lib/module/index.ios.js +268 -116
  26. package/lib/module/index.ios.js.map +1 -1
  27. package/lib/typescript/Services.d.ts +3 -0
  28. package/lib/typescript/Services.d.ts.map +1 -0
  29. package/lib/typescript/constants.d.ts +6 -0
  30. package/lib/typescript/constants.d.ts.map +1 -0
  31. package/lib/typescript/index.android.d.ts +26 -3
  32. package/lib/typescript/index.android.d.ts.map +1 -1
  33. package/lib/typescript/index.ios.d.ts +20 -3
  34. package/lib/typescript/index.ios.d.ts.map +1 -1
  35. package/package.json +16 -26
  36. package/react-native-visit-rn-sdk.podspec +2 -1
  37. package/src/Services.js +37 -0
  38. package/src/constants.js +4 -0
  39. package/src/index.android.js +773 -0
  40. package/src/index.ios.js +429 -0
  41. package/android/src/main/java/com/visitrnsdk/VisitRnSdkLocationModule.kt +0 -37
  42. package/lib/commonjs/assets/video-call/connecting-lottie.gif +0 -0
  43. package/lib/commonjs/assets/video-call/end-call.png +0 -0
  44. package/lib/commonjs/assets/video-call/mic-off.png +0 -0
  45. package/lib/commonjs/assets/video-call/reconnecting.gif +0 -0
  46. package/lib/commonjs/assets/video-call/switch-camera.png +0 -0
  47. package/lib/commonjs/assets/video-call/toggle-down.png +0 -0
  48. package/lib/commonjs/assets/video-call/toggle-up.png +0 -0
  49. package/lib/commonjs/assets/video-call/video-off.png +0 -0
  50. package/lib/commonjs/components/VideoCallComponent.js +0 -1088
  51. package/lib/commonjs/components/VideoCallComponent.js.map +0 -1
  52. package/lib/commonjs/index.js +0 -6
  53. package/lib/commonjs/index.js.map +0 -1
  54. package/lib/commonjs/shims.d.js +0 -2
  55. package/lib/commonjs/shims.d.js.map +0 -1
  56. package/lib/commonjs/types.js +0 -2
  57. package/lib/commonjs/types.js.map +0 -1
  58. package/lib/module/assets/video-call/connecting-lottie.gif +0 -0
  59. package/lib/module/assets/video-call/end-call.png +0 -0
  60. package/lib/module/assets/video-call/mic-off.png +0 -0
  61. package/lib/module/assets/video-call/reconnecting.gif +0 -0
  62. package/lib/module/assets/video-call/switch-camera.png +0 -0
  63. package/lib/module/assets/video-call/toggle-down.png +0 -0
  64. package/lib/module/assets/video-call/toggle-up.png +0 -0
  65. package/lib/module/assets/video-call/video-off.png +0 -0
  66. package/lib/module/components/VideoCallComponent.js +0 -1081
  67. package/lib/module/components/VideoCallComponent.js.map +0 -1
  68. package/lib/module/index.js +0 -2
  69. package/lib/module/index.js.map +0 -1
  70. package/lib/module/shims.d.js +0 -2
  71. package/lib/module/shims.d.js.map +0 -1
  72. package/lib/module/types.js +0 -2
  73. package/lib/module/types.js.map +0 -1
  74. package/lib/typescript/components/VideoCallComponent.d.ts +0 -79
  75. package/lib/typescript/components/VideoCallComponent.d.ts.map +0 -1
  76. package/lib/typescript/index.d.ts +0 -17
  77. package/lib/typescript/index.d.ts.map +0 -1
  78. package/lib/typescript/types.d.ts +0 -24
  79. package/lib/typescript/types.d.ts.map +0 -1
  80. package/src/assets/video-call/connecting-lottie.gif +0 -0
  81. package/src/assets/video-call/end-call.png +0 -0
  82. package/src/assets/video-call/mic-off.png +0 -0
  83. package/src/assets/video-call/reconnecting.gif +0 -0
  84. package/src/assets/video-call/switch-camera.png +0 -0
  85. package/src/assets/video-call/toggle-down.png +0 -0
  86. package/src/assets/video-call/toggle-up.png +0 -0
  87. package/src/assets/video-call/video-off.png +0 -0
  88. package/src/components/VideoCallComponent.tsx +0 -1484
  89. package/src/index.android.tsx +0 -459
  90. package/src/index.ios.tsx +0 -238
  91. package/src/index.tsx +0 -25
  92. package/src/shims.d.ts +0 -49
  93. package/src/types.ts +0 -25
@@ -1,261 +1,465 @@
1
- import React, { forwardRef, useRef, useEffect, useState, useCallback, useImperativeHandle } from 'react';
2
- import { Alert, AppState, BackHandler, Linking, NativeModules, SafeAreaView } from 'react-native';
3
- import { check, openSettings, PERMISSIONS, request, RESULTS } from 'react-native-permissions';
1
+ import React, { useRef, useEffect, useState, useCallback } from 'react';
2
+ import { EventRegister } from 'react-native-event-listeners';
3
+ import { SafeAreaView, NativeModules, PermissionsAndroid, BackHandler, Linking, Alert, AppState, NativeEventEmitter } from 'react-native';
4
4
  import WebView from 'react-native-webview';
5
- import VideoCallComponent from './components/VideoCallComponent';
6
- // react-native-webview typings can collapse to `never` under React 17 @types.
7
- const SdkWebView = WebView;
8
- const LOCATION_SOURCE_SETTINGS = 'android.settings.LOCATION_SOURCE_SETTINGS';
9
- const GENERAL_SETTINGS = 'android.settings.SETTINGS';
5
+ import LocationEnabler from 'react-native-location-enabler';
6
+ import DeviceInfo from 'react-native-device-info';
7
+ import axios from 'axios';
8
+ import constants from './constants';
9
+ export const httpClient = axios.create({
10
+ timeout: 60000
11
+ });
12
+ const messageEmitter = new NativeEventEmitter(NativeModules.VisitFitnessModule);
10
13
  const {
11
- VisitRnSdkLocation
12
- } = NativeModules;
13
- const VisitRnSdkView = /*#__PURE__*/forwardRef(function VisitRnSdkView({
14
- ssoLink = '',
15
- isLoggingEnabled = false,
16
- onEvent
17
- }, ref) {
18
- const source = typeof ssoLink === 'string' ? ssoLink.trim() : '';
19
- const webviewRef = useRef(null);
20
- const videoCallRef = useRef(null);
21
- const locationFlowInProgressRef = useRef(false);
22
- const pendingSettingsRef = useRef(null);
23
- const appStateRef = useRef(AppState.currentState);
24
- const [canGoBack, setCanGoBack] = useState(false);
25
- const warn = useCallback((message, error) => {
14
+ PRIORITIES: {
15
+ HIGH_ACCURACY
16
+ },
17
+ useLocationSettings,
18
+ addListener
19
+ } = LocationEnabler;
20
+ const VisitRnSdkView = ({
21
+ cpsid,
22
+ baseUrl,
23
+ errorBaseUrl,
24
+ token,
25
+ moduleName,
26
+ environment,
27
+ magicLink,
28
+ isLoggingEnabled
29
+ }) => {
30
+ const [source, setSource] = useState('');
31
+ const [appState, setAppState] = useState(AppState.currentState);
32
+ const [showPermissionAlreadyDeniedDialog, setShowPermissionAlreadyDeniedDialog] = useState(false);
33
+ useEffect(() => {
34
+ var _magicLink$trim;
26
35
  if (isLoggingEnabled) {
27
- console.warn(message, error);
36
+ console.log('useEffect ran');
28
37
  }
29
- }, [isLoggingEnabled]);
30
- const finishLocationFlow = useCallback(granted => {
31
- var _webviewRef$current;
32
- locationFlowInProgressRef.current = false;
33
- pendingSettingsRef.current = null;
34
- (_webviewRef$current = webviewRef.current) === null || _webviewRef$current === void 0 || _webviewRef$current.injectJavaScript(`window.checkTheGpsPermission(${granted}); true;`);
38
+ NativeModules.VisitFitnessModule.initiateSDK(isLoggingEnabled);
39
+ if (((magicLink === null || magicLink === void 0 || (_magicLink$trim = magicLink.trim()) === null || _magicLink$trim === void 0 ? void 0 : _magicLink$trim.length) || 0) > 0) {
40
+ setSource(magicLink);
41
+ } else {
42
+ DeviceInfo.getAndroidId().then(deviceId => {
43
+ var buildNumber = DeviceInfo.getBuildNumber();
44
+ let systemVersion = DeviceInfo.getSystemVersion();
45
+ let version = DeviceInfo.getVersion();
46
+ if (isLoggingEnabled) {
47
+ console.log(' baseUrl : ' + baseUrl + 'token: ' + token + ' cpsid: ' + cpsid + ' environment: ' + environment + 'buildNumber:' + buildNumber + ' systemVersion:' + systemVersion + ' version : ' + version + ' deviceId', deviceId);
48
+ }
49
+ var finalEndPoint = `${baseUrl}/partners/v3/generate-magic-link-star-health`;
50
+ if (isLoggingEnabled) {
51
+ console.log('finalEndPoint: ' + finalEndPoint);
52
+ }
53
+ httpClient.post(finalEndPoint, {
54
+ cpsid: cpsid,
55
+ token: token,
56
+ srcClientId: 'Android',
57
+ deviceId: deviceId,
58
+ appVersion: version,
59
+ deviceVersion: systemVersion,
60
+ userEnv: environment
61
+ }).then(response => {
62
+ let data = response.data;
63
+ // let visitMagicLink = data.result; //@Deprecated. Superseded by magic code usage.
64
+ const errorMessage = data.errorMessage;
65
+ const magicCode = data.magicCode;
66
+ const responseReferenceId = data.responseReferenceId;
67
+ const otherValues = data.otherValues;
68
+ let finalBaseUrl = '';
69
+ if (environment.toUpperCase() === 'PROD') {
70
+ finalBaseUrl = constants.PROD_BASE_URL;
71
+ } else {
72
+ finalBaseUrl = constants.STAGE_BASE_URL;
73
+ }
74
+ let finalUrl = `${finalBaseUrl}=${magicCode}`;
75
+ if (data.message === 'success') {
76
+ var _moduleName$trim;
77
+ if (((moduleName === null || moduleName === void 0 || (_moduleName$trim = moduleName.trim()) === null || _moduleName$trim === void 0 ? void 0 : _moduleName$trim.length) || 0) > 0) {
78
+ finalUrl += `&tab=${moduleName}`;
79
+ }
80
+ if (typeof responseReferenceId === 'string' && responseReferenceId.trim().length > 0) {
81
+ finalUrl += `&responseReferenceId=${responseReferenceId}`;
82
+ }
83
+ if (typeof otherValues === 'string' && otherValues.trim().length > 0) {
84
+ finalUrl += `&otherValues=${otherValues}`;
85
+ }
86
+ if (isLoggingEnabled) {
87
+ console.log('magicLink: ' + finalUrl);
88
+ }
89
+ setSource(finalUrl);
90
+ } else {
91
+ var errorUrl = `${errorBaseUrl}/star-health?error=${errorMessage}`;
92
+ setSource(errorUrl);
93
+ if (errorMessage != null) {
94
+ if (errorMessage === 'Please login again') {
95
+ EventRegister.emitEvent('visit-event', {
96
+ message: 'unauthorized-wellness-access',
97
+ errorMessage: errorMessage
98
+ });
99
+ } else if (errorMessage.includes('External Server Error')) {
100
+ EventRegister.emitEvent('visit-event', {
101
+ message: 'external-server-error',
102
+ errorMessage: errorMessage
103
+ });
104
+ }
105
+ }
106
+ if (isLoggingEnabled) {
107
+ console.log('erorMessage: ' + data.errorMessage + ' errorUrl: ' + errorUrl);
108
+ }
109
+ }
110
+ }).catch(error => {
111
+ var errorUrl = `${errorBaseUrl}/star-health?error=${error}`;
112
+ setSource(errorUrl);
113
+ EventRegister.emitEvent('visit-event', {
114
+ message: 'generate-magic-link-failed',
115
+ errorMessage: `${error}`
116
+ });
117
+ if (isLoggingEnabled) {
118
+ console.log('error: ' + error);
119
+ }
120
+ });
121
+ }).catch(err => {
122
+ var errorUrl = `${errorBaseUrl}/star-health?error=${err}`;
123
+ setSource(errorUrl);
124
+ EventRegister.emitEvent('visit-event', {
125
+ message: 'getDeviceInfo-failed',
126
+ errorMessage: `${err}`
127
+ });
128
+ if (isLoggingEnabled) {
129
+ console.log('getDeviceInfo err', err);
130
+ }
131
+ });
132
+ }
133
+ }, [cpsid, token, baseUrl, errorBaseUrl, moduleName, environment, magicLink, isLoggingEnabled]);
134
+ useEffect(() => {
135
+ const subscription = messageEmitter.addListener('onMessage', message => {
136
+ console.log('Received message:', message);
137
+ if (typeof message === 'string' && message.includes('RemoteException')) {
138
+ Alert.alert('Error!', 'Something went wrong while connecting to Health Connect. Please try again.', []);
139
+ }
140
+ EventRegister.emitEvent('visit-event', {
141
+ message: 'health-connect-error-event',
142
+ errorMessage: message
143
+ });
144
+ });
145
+ return () => {
146
+ // Clean up the subscription when the component unmounts
147
+ subscription.remove();
148
+ };
35
149
  }, []);
36
- const showLocationPermissionSettingsAlert = useCallback(() => {
37
- Alert.alert('Location permission required', 'Allow location access in app settings to continue.', [{
150
+ useEffect(() => {
151
+ const subscription = AppState.addEventListener('change', handleAppStateChange);
152
+ console.log(`AppState.addEventListener added, current state: ${appState}`);
153
+ return () => {
154
+ subscription.remove();
155
+ };
156
+ }, [appState]); // Include appState in the dependency array to ensure it's up to date.
157
+
158
+ const handleAppStateChange = nextAppState => {
159
+ // console.log(
160
+ // "nextAppState: " + nextAppState + ", previousState: " + appState
161
+ // );
162
+
163
+ // Instead of relying on the old appState, use the nextAppState directly
164
+ if (appState.match(/inactive|background/) && nextAppState === 'active') {
165
+ if (isLoggingEnabled) {
166
+ console.log('App has come to the foreground!');
167
+ }
168
+ console.log('getHealthConnectStatus commented out, because it it not required for MCHI since we rely on callback from the web to get the health connect status.');
169
+ // getHealthConnectStatus();
170
+ }
171
+ setAppState(nextAppState); // Update the state with the new app state
172
+ };
173
+ const [enabled, requestResolution] = useLocationSettings({
174
+ priority: HIGH_ACCURACY,
175
+ // default BALANCED_POWER_ACCURACY
176
+ alwaysShow: true,
177
+ // default false
178
+ needBle: true // default false
179
+ }, false /* optional: default undefined */);
180
+ const webviewRef = useRef(null);
181
+ const showLocationPermissionAlert = () => {
182
+ Alert.alert('Permission Required', 'Allow location permission from app settings', [{
38
183
  text: 'Cancel',
39
- style: 'cancel',
40
- onPress: () => finishLocationFlow(false)
184
+ onPress: () => {
185
+ console.log('Cancel clicked');
186
+ }
41
187
  }, {
42
- text: 'Open Settings',
43
- onPress: async () => {
44
- pendingSettingsRef.current = 'location-permission';
45
- try {
46
- await openSettings();
47
- } catch (error) {
48
- warn('Unable to open application settings.', error);
49
- finishLocationFlow(false);
188
+ text: 'Go to Settings',
189
+ onPress: () => {
190
+ Linking.openSettings();
191
+ }
192
+ }]);
193
+ };
194
+ const requestLocationPermission = async () => {
195
+ try {
196
+ console.log('requestLocationPermission called');
197
+ const isLocationPermissionPresent = await PermissionsAndroid.check(PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION);
198
+ console.log('isLocationPermissionPresent: ' + isLocationPermissionPresent + ' showPermissionAlreadyDeniedDialog: ' + showPermissionAlreadyDeniedDialog);
199
+ if (!isLocationPermissionPresent && showPermissionAlreadyDeniedDialog) {
200
+ console.log('showLocationPermissionAlert() called');
201
+ showLocationPermissionAlert();
202
+ } else {
203
+ console.log('requesting location permission');
204
+ const granted = await PermissionsAndroid.request(PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION, {
205
+ title: 'Need Location Permission',
206
+ message: 'Need access to location permission',
207
+ buttonNeutral: 'Ask Me Later',
208
+ buttonNegative: 'Cancel',
209
+ buttonPositive: 'OK'
210
+ });
211
+ if (granted === PermissionsAndroid.RESULTS.GRANTED) {
212
+ if (isLoggingEnabled) {
213
+ console.log('Location permission granted');
214
+ }
215
+ setShowPermissionAlreadyDeniedDialog(false);
216
+ if (!enabled) {
217
+ requestResolution();
218
+ } else {
219
+ var _webviewRef$current;
220
+ var finalString = `window.checkTheGpsPermission(true)`;
221
+ console.log('requestLocationPermission: ' + finalString);
222
+ (_webviewRef$current = webviewRef.current) === null || _webviewRef$current === void 0 || _webviewRef$current.injectJavaScript(finalString);
223
+ }
224
+ } else {
225
+ var _webviewRef$current2;
226
+ setShowPermissionAlreadyDeniedDialog(true);
227
+ console.log('Location permission denied');
228
+ var finalString = `window.checkTheGpsPermission(false)`;
229
+ console.log('requestLocationPermission: ' + finalString);
230
+ (_webviewRef$current2 = webviewRef.current) === null || _webviewRef$current2 === void 0 || _webviewRef$current2.injectJavaScript(finalString);
50
231
  }
51
232
  }
52
- }], {
53
- cancelable: false
54
- });
55
- }, [finishLocationFlow, warn]);
56
- const openLocationServicesSettings = useCallback(async () => {
57
- pendingSettingsRef.current = 'location-services';
233
+ } catch (e) {
234
+ console.error(e);
235
+ }
236
+ };
237
+ const showHealthConnectPermissionDeniedDialog = () => {
238
+ Alert.alert('Permission Denied', 'Go to Health Connect App to allow app permission', [{
239
+ text: 'Cancel',
240
+ onPress: () => {
241
+ console.log('Cancel clicked');
242
+ }
243
+ }, {
244
+ text: 'Open Health Connect',
245
+ onPress: () => {
246
+ openHealthConnectApp();
247
+ }
248
+ }]);
249
+ };
250
+ const openHealthConnectApp = async () => {
251
+ NativeModules.VisitFitnessModule.openHealthConnectApp();
252
+ };
253
+ const askForHealthConnectPermission = async () => {
58
254
  try {
59
- await Linking.sendIntent(LOCATION_SOURCE_SETTINGS);
60
- } catch (locationSettingsError) {
61
- warn('Unable to open Location Services settings; opening general settings.', locationSettingsError);
62
- try {
63
- await Linking.sendIntent(GENERAL_SETTINGS);
64
- } catch (generalSettingsError) {
65
- warn('Unable to open Android settings.', generalSettingsError);
66
- finishLocationFlow(false);
255
+ const isPermissionGranted = await NativeModules.VisitFitnessModule.askForFitnessPermission();
256
+ if (isLoggingEnabled) {
257
+ console.log('isPermissionGranted: ' + isPermissionGranted);
258
+ }
259
+ if (isPermissionGranted === 'GRANTED') {
260
+ getHealthConnectStatus();
261
+ // getDailyFitnessData();
262
+ } else if (isPermissionGranted === 'CANCELLED') {
263
+ showHealthConnectPermissionDeniedDialog();
264
+ }
265
+ } catch (e) {
266
+ if (isLoggingEnabled) {
267
+ console.error(e);
67
268
  }
68
269
  }
69
- }, [finishLocationFlow, warn]);
70
- const checkLocationServices = useCallback(async ({
71
- promptIfDisabled
72
- }) => {
270
+ };
271
+ const getHealthConnectStatus = async () => {
73
272
  try {
74
- if (!(VisitRnSdkLocation !== null && VisitRnSdkLocation !== void 0 && VisitRnSdkLocation.isLocationServicesEnabled)) {
75
- throw new Error('VisitRnSdkLocation native module is unavailable.');
273
+ const healthConnectStatus = await NativeModules.VisitFitnessModule.getHealthConnectStatus();
274
+ if (isLoggingEnabled) {
275
+ console.log('getHealthConnectStatus: ' + healthConnectStatus);
76
276
  }
77
- const isEnabled = await VisitRnSdkLocation.isLocationServicesEnabled();
78
- if (isEnabled) {
79
- finishLocationFlow(true);
80
- return;
277
+ if (healthConnectStatus === 'NOT_SUPPORTED') {
278
+ var _webviewRef$current3;
279
+ (_webviewRef$current3 = webviewRef.current) === null || _webviewRef$current3 === void 0 || _webviewRef$current3.injectJavaScript('window.healthConnectNotSupported()');
280
+ } else if (healthConnectStatus === 'NOT_INSTALLED') {
281
+ var _webviewRef$current4, _webviewRef$current5;
282
+ (_webviewRef$current4 = webviewRef.current) === null || _webviewRef$current4 === void 0 || _webviewRef$current4.injectJavaScript('window.healthConnectNotInstall()');
283
+ (_webviewRef$current5 = webviewRef.current) === null || _webviewRef$current5 === void 0 || _webviewRef$current5.injectJavaScript('window.updateFitnessPermissions(false,0,0)');
284
+ } else if (healthConnectStatus === 'INSTALLED') {
285
+ var _webviewRef$current6, _webviewRef$current7;
286
+ (_webviewRef$current6 = webviewRef.current) === null || _webviewRef$current6 === void 0 || _webviewRef$current6.injectJavaScript('window.healthConnectAvailable()');
287
+ (_webviewRef$current7 = webviewRef.current) === null || _webviewRef$current7 === void 0 || _webviewRef$current7.injectJavaScript('window.updateFitnessPermissions(false,0,0)');
288
+ } else if (healthConnectStatus === 'CONNECTED') {
289
+ getDailyFitnessData();
81
290
  }
82
- if (!promptIfDisabled) {
83
- finishLocationFlow(false);
84
- return;
291
+ } catch (e) {
292
+ if (isLoggingEnabled) {
293
+ console.error(e);
85
294
  }
86
- Alert.alert('Turn on Location Services', 'Enable Location Services in phone settings to continue.', [{
87
- text: 'Cancel',
88
- style: 'cancel',
89
- onPress: () => finishLocationFlow(false)
90
- }, {
91
- text: 'Open Settings',
92
- onPress: openLocationServicesSettings
93
- }], {
94
- cancelable: false
95
- });
96
- } catch (error) {
97
- warn('Unable to check Location Services.', error);
98
- finishLocationFlow(false);
99
295
  }
100
- }, [finishLocationFlow, openLocationServicesSettings, warn]);
101
- const requestLocationPermission = useCallback(async () => {
102
- if (locationFlowInProgressRef.current || pendingSettingsRef.current !== null) {
103
- return;
296
+ };
297
+ const getDailyFitnessData = async () => {
298
+ if (isLoggingEnabled) {
299
+ console.log('getDailyFitnessData() called');
104
300
  }
105
- locationFlowInProgressRef.current = true;
106
301
  try {
107
- let permissionStatus = await check(PERMISSIONS.ANDROID.ACCESS_FINE_LOCATION);
108
- if (permissionStatus === RESULTS.DENIED) {
109
- permissionStatus = await request(PERMISSIONS.ANDROID.ACCESS_FINE_LOCATION);
302
+ const dailyFitnessData = await NativeModules.VisitFitnessModule.requestDailyFitnessData();
303
+ if (dailyFitnessData) {
304
+ var _webviewRef$current8;
305
+ (_webviewRef$current8 = webviewRef.current) === null || _webviewRef$current8 === void 0 || _webviewRef$current8.injectJavaScript(dailyFitnessData);
110
306
  }
111
- if (permissionStatus === RESULTS.GRANTED) {
112
- await checkLocationServices({
113
- promptIfDisabled: true
114
- });
115
- return;
307
+ } catch (error) {
308
+ if (isLoggingEnabled) {
309
+ console.log(error);
310
+ }
311
+ }
312
+ };
313
+ const requestActivityData = async (type, frequency, timeStamp) => {
314
+ if (isLoggingEnabled) {
315
+ console.log('requestActivityData() called');
316
+ }
317
+ try {
318
+ const graphData = await NativeModules.VisitFitnessModule.requestActivityDataFromHealthConnect(type, frequency, timeStamp);
319
+ if (isLoggingEnabled) {
320
+ console.log(`requestActivityData() data: ` + graphData);
116
321
  }
117
- if (permissionStatus === RESULTS.BLOCKED) {
118
- showLocationPermissionSettingsAlert();
119
- return;
322
+ if (graphData) {
323
+ var _webviewRef$current9;
324
+ (_webviewRef$current9 = webviewRef.current) === null || _webviewRef$current9 === void 0 || _webviewRef$current9.injectJavaScript('window.' + graphData);
120
325
  }
121
- finishLocationFlow(false);
122
326
  } catch (error) {
123
- warn('Unable to check or request location permission.', error);
124
- finishLocationFlow(false);
327
+ if (isLoggingEnabled) {
328
+ console.log(error);
329
+ }
125
330
  }
126
- }, [checkLocationServices, finishLocationFlow, showLocationPermissionSettingsAlert, warn]);
127
- const recheckAfterSettings = useCallback(async () => {
128
- const settingsType = pendingSettingsRef.current;
129
- if (!settingsType) {
130
- return;
331
+ };
332
+ const updateApiBaseUrl = async (apiBaseUrl, authtoken, googleFitLastSync, gfHourlyLastSync) => {
333
+ if (isLoggingEnabled) {
334
+ console.log('updateApiBaseUrl() called.');
131
335
  }
132
- pendingSettingsRef.current = null;
133
336
  try {
134
- const permissionStatus = await check(PERMISSIONS.ANDROID.ACCESS_FINE_LOCATION);
135
- if (permissionStatus !== RESULTS.GRANTED) {
136
- finishLocationFlow(false);
137
- return;
337
+ const message = await NativeModules.VisitFitnessModule.updateApiBaseUrl(apiBaseUrl, authtoken, googleFitLastSync, gfHourlyLastSync);
338
+ if (isLoggingEnabled) {
339
+ console.log(message);
138
340
  }
139
- await checkLocationServices({
140
- promptIfDisabled: settingsType === 'location-permission'
141
- });
142
341
  } catch (error) {
143
- warn('Unable to recheck location access after settings.', error);
144
- finishLocationFlow(false);
342
+ if (isLoggingEnabled) {
343
+ console.log(error);
344
+ }
145
345
  }
146
- }, [checkLocationServices, finishLocationFlow, warn]);
346
+ };
147
347
  const runBeforeFirst = `
148
348
  window.isNativeApp = true;
149
349
  window.platform = "ANDROID";
150
- window.setSdkPlatform?.('ANDROID');
350
+ window.setSdkPlatform('ANDROID');
151
351
  true; // note: this is required, or you'll sometimes get silent failures
152
352
  `;
153
- const sendEvent = useCallback((eventName, properties) => {
154
- var _webviewRef$current2;
155
- if (typeof eventName !== 'string' || (eventName === null || eventName === void 0 ? void 0 : eventName.trim()) === '') {
156
- if (isLoggingEnabled) {
157
- console.warn('sendEvent requires a non-empty eventName.');
158
- }
159
- return;
160
- }
161
- (_webviewRef$current2 = webviewRef.current) === null || _webviewRef$current2 === void 0 || _webviewRef$current2.injectJavaScript(`window.sendEventToVisit(${JSON.stringify(eventName)}, ${JSON.stringify(properties ?? {})}); true;`);
162
- }, [isLoggingEnabled]);
163
- useImperativeHandle(ref, () => ({
164
- sendEvent
165
- }), [sendEvent]);
166
- const emitHostEvent = useCallback((eventName, properties) => {
167
- onEvent === null || onEvent === void 0 || onEvent(eventName, properties);
168
- }, [onEvent]);
169
- const startVideoConsultation = useCallback(parsedObject => {
170
- var _videoCallRef$current;
171
- const roomName = parsedObject === null || parsedObject === void 0 ? void 0 : parsedObject.roomName;
172
- const accessToken = parsedObject === null || parsedObject === void 0 ? void 0 : parsedObject.token;
173
- const rawDoctorName = parsedObject === null || parsedObject === void 0 ? void 0 : parsedObject.doctorName;
174
- const visibleDoctorName = rawDoctorName && rawDoctorName.indexOf('Dr.') > -1 ? rawDoctorName.replace('Dr. ', '') : rawDoctorName && rawDoctorName.indexOf('Dr') > -1 ? rawDoctorName.replace('Dr ', '') : null;
175
- const userName = parsedObject === null || parsedObject === void 0 ? void 0 : parsedObject.userName;
176
- if (!roomName || !accessToken) {
177
- if (isLoggingEnabled) {
178
- console.warn('Video call payload missing roomName/accessToken.');
179
- }
180
- return;
181
- }
182
- (_videoCallRef$current = videoCallRef.current) === null || _videoCallRef$current === void 0 || _videoCallRef$current.startVideoCall({
183
- roomName,
184
- accessToken,
185
- doctorName: rawDoctorName ?? '',
186
- visibleDoctorName: visibleDoctorName ?? '',
187
- userName
188
- });
189
- }, [isLoggingEnabled]);
190
353
  const handleMessage = event => {
191
- var _webviewRef$current3;
354
+ var _webviewRef$current0;
192
355
  if (event.nativeEvent.data != null) {
193
356
  try {
194
- const parsedObject = JSON.parse(event.nativeEvent.data);
195
357
  if (isLoggingEnabled) {
196
- console.log('Received WebView method:', parsedObject.method);
358
+ console.log('Event :' + event.nativeEvent.data);
197
359
  }
360
+ const parsedObject = JSON.parse(event.nativeEvent.data);
198
361
  if (parsedObject.method != null) {
199
362
  switch (parsedObject.method) {
200
- case 'startVideoCall':
201
- startVideoConsultation(parsedObject);
363
+ case 'GET_HEALTH_CONNECT_STATUS':
364
+ getHealthConnectStatus();
365
+ break;
366
+ case 'CONNECT_TO_GOOGLE_FIT':
367
+ askForHealthConnectPermission();
202
368
  break;
203
369
  case 'UPDATE_PLATFORM':
204
- (_webviewRef$current3 = webviewRef.current) === null || _webviewRef$current3 === void 0 || _webviewRef$current3.injectJavaScript('window.setSdkPlatform("ANDROID")');
370
+ (_webviewRef$current0 = webviewRef.current) === null || _webviewRef$current0 === void 0 || _webviewRef$current0.injectJavaScript('window.setSdkPlatform("ANDROID")');
371
+ break;
372
+ case 'UPDATE_API_BASE_URL':
373
+ {
374
+ let apiBaseUrl = parsedObject.apiBaseUrl;
375
+ let authtoken = parsedObject.authtoken;
376
+ let googleFitLastSync = parsedObject.googleFitLastSync;
377
+ let gfHourlyLastSync = parsedObject.gfHourlyLastSync;
378
+ if (isLoggingEnabled) {
379
+ console.log('apiBaseUrl: ' + 'NOT SHOWN' + ' authtoken: ' + 'NOT SHOWN' + ' googleFitLastSync: ' + googleFitLastSync + ' gfHourlyLastSync: ' + gfHourlyLastSync);
380
+ }
381
+ updateApiBaseUrl(apiBaseUrl, authtoken, googleFitLastSync, gfHourlyLastSync);
382
+ }
383
+ break;
384
+ case 'GET_DATA_TO_GENERATE_GRAPH':
385
+ {
386
+ let type = parsedObject.type;
387
+ let frequency = parsedObject.frequency;
388
+ let timeStamp = parsedObject.timestamp;
389
+ if (isLoggingEnabled) {
390
+ console.log('type: ' + type + ' frequency:' + frequency + ' timeStamp: ' + timeStamp);
391
+ }
392
+ requestActivityData(type, frequency, timeStamp);
393
+ }
205
394
  break;
206
395
  case 'GET_LOCATION_PERMISSIONS':
396
+ console.log('GET_LOCATION_PERMISSIONS');
207
397
  requestLocationPermission();
208
398
  break;
209
399
  case 'OPEN_PDF':
210
- if (parsedObject.url) {
211
- Linking.openURL(parsedObject.url);
400
+ {
401
+ let pdfUrl = parsedObject.url;
402
+ // console.log("pdfUrl "+pdfUrl);
403
+
404
+ Linking.openURL(pdfUrl);
212
405
  }
213
406
  break;
407
+ case 'OPEN_FACE_SCAN_FLOW':
408
+ EventRegister.emitEvent('visit-event', {
409
+ message: 'OPEN_FACE_SCAN_FLOW'
410
+ });
411
+ break;
214
412
  case 'CLOSE_VIEW':
215
413
  break;
216
- case 'sendEventToHost':
217
- {
218
- const eventName = typeof parsedObject.eventName === 'string' ? parsedObject.eventName : '';
219
- if (eventName) {
220
- const properties = {
221
- ...parsedObject
222
- };
223
- delete properties.method;
224
- delete properties.eventName;
225
- emitHostEvent(eventName, properties);
226
- }
227
- break;
228
- }
229
414
  default:
230
415
  break;
231
416
  }
232
417
  }
233
- } catch (error) {
234
- warn('Unable to handle WebView message.', error);
418
+ } catch (exception) {
419
+ console.log('Exception occured:' + exception.message);
235
420
  }
236
421
  }
237
422
  };
423
+ const [canGoBack, setCanGoBack] = useState(false);
238
424
  const handleBack = useCallback(() => {
239
425
  if (canGoBack && webviewRef.current) {
240
- webviewRef.current.goBack();
426
+ var _webviewRef$current1;
427
+ (_webviewRef$current1 = webviewRef.current) === null || _webviewRef$current1 === void 0 || _webviewRef$current1.goBack();
241
428
  return true;
242
429
  }
243
430
  return false;
244
431
  }, [canGoBack]);
245
432
  useEffect(() => {
246
- const backSub = BackHandler.addEventListener('hardwareBackPress', handleBack);
247
- const appStateSub = AppState.addEventListener('change', nextAppState => {
248
- const wasInBackground = /inactive|background/.test(appStateRef.current);
249
- appStateRef.current = nextAppState;
250
- if (wasInBackground && nextAppState === 'active' && pendingSettingsRef.current) {
251
- recheckAfterSettings();
433
+ // Subscribe to GPS/location setting changes
434
+ const locationSub = addListener(({
435
+ locationEnabled
436
+ }) => {
437
+ if (locationEnabled) {
438
+ checkLocationPermissionAndSendCallback();
252
439
  }
253
440
  });
441
+
442
+ // Subscribe to Android hardware back press
443
+ const backSub = BackHandler.addEventListener('hardwareBackPress', handleBack);
444
+
445
+ // Cleanup subscriptions on unmount
254
446
  return () => {
255
447
  backSub === null || backSub === void 0 || backSub.remove();
256
- appStateSub === null || appStateSub === void 0 || appStateSub.remove();
448
+ locationSub === null || locationSub === void 0 || locationSub.remove();
257
449
  };
258
- }, [handleBack, recheckAfterSettings]);
450
+ }, [handleBack]);
451
+ const checkLocationPermissionAndSendCallback = async () => {
452
+ const isLocationPermissionAvailable = await PermissionsAndroid.check(PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION);
453
+ if (isLoggingEnabled) {
454
+ console.log('checkLocationPermissionAndSendCallback() isLocationPermissionAvailable: ' + isLocationPermissionAvailable + 'isGPSPermissionAvailabe: true');
455
+ }
456
+ if (isLocationPermissionAvailable) {
457
+ var _webviewRef$current10;
458
+ var finalString = `window.checkTheGpsPermission(true)`;
459
+ console.log('listener: ' + finalString);
460
+ (_webviewRef$current10 = webviewRef.current) === null || _webviewRef$current10 === void 0 || _webviewRef$current10.injectJavaScript(finalString);
461
+ }
462
+ };
259
463
  return (
260
464
  /*#__PURE__*/
261
465
  // eslint-disable-next-line react-native/no-inline-styles
@@ -263,7 +467,7 @@ const VisitRnSdkView = /*#__PURE__*/forwardRef(function VisitRnSdkView({
263
467
  style: {
264
468
  flex: 1
265
469
  }
266
- }, source ? /*#__PURE__*/React.createElement(SdkWebView, {
470
+ }, source ? /*#__PURE__*/React.createElement(WebView, {
267
471
  ref: webviewRef,
268
472
  source: {
269
473
  uri: source,
@@ -276,29 +480,69 @@ const VisitRnSdkView = /*#__PURE__*/forwardRef(function VisitRnSdkView({
276
480
  javaScriptEnabled: true,
277
481
  onLoadProgress: event => setCanGoBack(event.nativeEvent.canGoBack),
278
482
  onError: errorMessage => {
483
+ EventRegister.emitEvent('visit-event', {
484
+ message: 'web-view-error',
485
+ errorMessage: errorMessage
486
+ });
279
487
  if (isLoggingEnabled) {
280
488
  console.warn('Webview error: ', errorMessage);
281
489
  }
282
490
  }
283
- }) : null, /*#__PURE__*/React.createElement(VideoCallComponent, {
284
- ref: videoCallRef,
285
- onCallConnected: info => {
286
- if (isLoggingEnabled) {
287
- console.log('Video call connected:', info);
288
- }
289
- },
290
- onCallEnded: info => {
291
- if (isLoggingEnabled) {
292
- console.log('Video call ended:', info);
293
- }
294
- },
295
- onError: error => {
296
- if (isLoggingEnabled) {
297
- console.error('Video call error:', error);
298
- }
299
- }
300
- }))
491
+ }) : null)
301
492
  );
302
- });
493
+ };
494
+ export const fetchDailyFitnessData = (startTimeStamp, isLoggingEnabled) => {
495
+ return new Promise((resolve, reject) => {
496
+ console.log('fetchDailyFitnessData called: ' + startTimeStamp);
497
+ NativeModules.VisitFitnessModule.fetchDailyFitnessData(startTimeStamp).then(result => {
498
+ resolve(result);
499
+ }).catch(err => reject(err));
500
+ });
501
+ };
502
+ export const fetchHourlyFitnessData = (startTimeStamp, isLoggingEnabled) => {
503
+ return new Promise((resolve, reject) => {
504
+ if (isLoggingEnabled) {
505
+ console.log('fetchHourlyFitnessData called: ' + startTimeStamp);
506
+ }
507
+ NativeModules.VisitFitnessModule.fetchHourlyFitnessData(startTimeStamp).then(result => {
508
+ resolve(result);
509
+ }).catch(err => reject(err));
510
+ });
511
+ };
512
+
513
+ // debounce, deferred
514
+ // function debounce(task, ms) {
515
+ // let t = { promise: null, cancel: (_) => void 0 };
516
+ // return async (...args) => {
517
+ // try {
518
+ // t.cancel();
519
+ // t = deferred(ms);
520
+ // await t.promise;
521
+ // await task(...args);
522
+ // } catch (_) {
523
+ // console.log('cleaning up cancelled promise');
524
+ // }
525
+ // };
526
+ // }
527
+
528
+ // function deferred(ms) {
529
+ // let cancel,
530
+ // promise = new Promise((resolve, reject) => {
531
+ // cancel = reject;
532
+ // setTimeout(resolve, ms);
533
+ // });
534
+ // return { promise, cancel };
535
+ // }
536
+
303
537
  export default VisitRnSdkView;
538
+ VisitRnSdkView.defaultProps = {
539
+ cpsid: '',
540
+ token: '',
541
+ baseUrl: '',
542
+ errorBaseUrl: '',
543
+ moduleName: '',
544
+ environment: '',
545
+ magicLink: '',
546
+ isLoggingEnabled: false
547
+ };
304
548
  //# sourceMappingURL=index.android.js.map