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