react-native-visit-rn-sdk 6.0.4 → 7.1.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 (79) hide show
  1. package/README.md +297 -191
  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/index.android.js +328 -205
  12. package/lib/commonjs/index.android.js.map +1 -1
  13. package/lib/commonjs/index.ios.js +159 -116
  14. package/lib/commonjs/index.ios.js.map +1 -1
  15. package/lib/module/index.android.js +328 -206
  16. package/lib/module/index.android.js.map +1 -1
  17. package/lib/module/index.ios.js +161 -117
  18. package/lib/module/index.ios.js.map +1 -1
  19. package/lib/typescript/index.android.d.ts +8 -3
  20. package/lib/typescript/index.android.d.ts.map +1 -1
  21. package/lib/typescript/index.ios.d.ts +6 -3
  22. package/lib/typescript/index.ios.d.ts.map +1 -1
  23. package/package.json +18 -26
  24. package/react-native-visit-rn-sdk.podspec +2 -1
  25. package/src/index.android.js +579 -0
  26. package/src/index.ios.js +284 -0
  27. package/android/src/main/java/com/visitrnsdk/VisitRnSdkLocationModule.kt +0 -37
  28. package/lib/commonjs/assets/video-call/connecting-lottie.gif +0 -0
  29. package/lib/commonjs/assets/video-call/end-call.png +0 -0
  30. package/lib/commonjs/assets/video-call/mic-off.png +0 -0
  31. package/lib/commonjs/assets/video-call/reconnecting.gif +0 -0
  32. package/lib/commonjs/assets/video-call/switch-camera.png +0 -0
  33. package/lib/commonjs/assets/video-call/toggle-down.png +0 -0
  34. package/lib/commonjs/assets/video-call/toggle-up.png +0 -0
  35. package/lib/commonjs/assets/video-call/video-off.png +0 -0
  36. package/lib/commonjs/components/VideoCallComponent.js +0 -1088
  37. package/lib/commonjs/components/VideoCallComponent.js.map +0 -1
  38. package/lib/commonjs/index.js +0 -6
  39. package/lib/commonjs/index.js.map +0 -1
  40. package/lib/commonjs/shims.d.js +0 -2
  41. package/lib/commonjs/shims.d.js.map +0 -1
  42. package/lib/commonjs/types.js +0 -2
  43. package/lib/commonjs/types.js.map +0 -1
  44. package/lib/module/assets/video-call/connecting-lottie.gif +0 -0
  45. package/lib/module/assets/video-call/end-call.png +0 -0
  46. package/lib/module/assets/video-call/mic-off.png +0 -0
  47. package/lib/module/assets/video-call/reconnecting.gif +0 -0
  48. package/lib/module/assets/video-call/switch-camera.png +0 -0
  49. package/lib/module/assets/video-call/toggle-down.png +0 -0
  50. package/lib/module/assets/video-call/toggle-up.png +0 -0
  51. package/lib/module/assets/video-call/video-off.png +0 -0
  52. package/lib/module/components/VideoCallComponent.js +0 -1081
  53. package/lib/module/components/VideoCallComponent.js.map +0 -1
  54. package/lib/module/index.js +0 -2
  55. package/lib/module/index.js.map +0 -1
  56. package/lib/module/shims.d.js +0 -2
  57. package/lib/module/shims.d.js.map +0 -1
  58. package/lib/module/types.js +0 -2
  59. package/lib/module/types.js.map +0 -1
  60. package/lib/typescript/components/VideoCallComponent.d.ts +0 -79
  61. package/lib/typescript/components/VideoCallComponent.d.ts.map +0 -1
  62. package/lib/typescript/index.d.ts +0 -17
  63. package/lib/typescript/index.d.ts.map +0 -1
  64. package/lib/typescript/types.d.ts +0 -24
  65. package/lib/typescript/types.d.ts.map +0 -1
  66. package/src/assets/video-call/connecting-lottie.gif +0 -0
  67. package/src/assets/video-call/end-call.png +0 -0
  68. package/src/assets/video-call/mic-off.png +0 -0
  69. package/src/assets/video-call/reconnecting.gif +0 -0
  70. package/src/assets/video-call/switch-camera.png +0 -0
  71. package/src/assets/video-call/toggle-down.png +0 -0
  72. package/src/assets/video-call/toggle-up.png +0 -0
  73. package/src/assets/video-call/video-off.png +0 -0
  74. package/src/components/VideoCallComponent.tsx +0 -1484
  75. package/src/index.android.tsx +0 -459
  76. package/src/index.ios.tsx +0 -238
  77. package/src/index.tsx +0 -25
  78. package/src/shims.d.ts +0 -49
  79. package/src/types.ts +0 -25
@@ -3,267 +3,359 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.default = void 0;
6
+ 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
12
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
13
13
  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';
14
+ const messageEmitter = new _reactNative.NativeEventEmitter(_reactNative.NativeModules.VisitFitnessModule);
18
15
  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) => {
16
+ PRIORITIES: {
17
+ HIGH_ACCURACY
18
+ },
19
+ useLocationSettings,
20
+ addListener
21
+ } = _reactNativeLocationEnabler.default;
22
+
23
+ /** @param {{ ssoURL: string, isLoggingEnabled?: boolean }} props */
24
+ const VisitRnSdkView = ({
25
+ ssoURL,
26
+ isLoggingEnabled = false
27
+ }) => {
28
+ const source = ssoURL === null || ssoURL === void 0 ? void 0 : ssoURL.trim();
29
+ const [appState, setAppState] = (0, _react.useState)(_reactNative.AppState.currentState);
30
+ const [showPermissionAlreadyDeniedDialog, setShowPermissionAlreadyDeniedDialog] = (0, _react.useState)(false);
31
+ (0, _react.useEffect)(() => {
34
32
  if (isLoggingEnabled) {
35
- console.warn(message, error);
33
+ console.log('useEffect ran');
36
34
  }
35
+ _reactNative.NativeModules.VisitFitnessModule.initiateSDK(isLoggingEnabled);
37
36
  }, [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;`);
37
+ (0, _react.useEffect)(() => {
38
+ const subscription = messageEmitter.addListener('onMessage', message => {
39
+ console.log('Received message:', message);
40
+ if (typeof message === 'string' && message.includes('RemoteException')) {
41
+ _reactNative.Alert.alert('Error!', 'Something went wrong while connecting to Health Connect. Please try again.', []);
42
+ }
43
+ _reactNativeEventListeners.EventRegister.emitEvent('visit-event', {
44
+ message: 'health-connect-error-event',
45
+ errorMessage: message
46
+ });
47
+ });
48
+ return () => {
49
+ // Clean up the subscription when the component unmounts
50
+ subscription.remove();
51
+ };
43
52
  }, []);
44
- const showLocationPermissionSettingsAlert = (0, _react.useCallback)(() => {
45
- _reactNative.Alert.alert('Location permission required', 'Allow location access in app settings to continue.', [{
53
+ (0, _react.useEffect)(() => {
54
+ const subscription = _reactNative.AppState.addEventListener('change', nextAppState => {
55
+ if (appState !== null && appState !== void 0 && appState.match(/inactive|background/) && nextAppState === 'active') {
56
+ if (isLoggingEnabled) {
57
+ console.log('App has come to the foreground!');
58
+ }
59
+ 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.');
60
+ }
61
+ setAppState(nextAppState);
62
+ });
63
+ console.log(`AppState.addEventListener added, current state: ${appState}`);
64
+ return () => {
65
+ subscription.remove();
66
+ };
67
+ }, [appState, isLoggingEnabled]);
68
+ const [enabled, requestResolution] = useLocationSettings({
69
+ priority: HIGH_ACCURACY,
70
+ // default BALANCED_POWER_ACCURACY
71
+ alwaysShow: true,
72
+ // default false
73
+ needBle: true // default false
74
+ }, false /* optional: default undefined */);
75
+ const webviewRef = (0, _react.useRef)(null);
76
+ const showLocationPermissionAlert = () => {
77
+ _reactNative.Alert.alert('Permission Required', 'Allow location permission from app settings', [{
46
78
  text: 'Cancel',
47
- style: 'cancel',
48
- onPress: () => finishLocationFlow(false)
79
+ onPress: () => {
80
+ console.log('Cancel clicked');
81
+ }
49
82
  }, {
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);
83
+ text: 'Go to Settings',
84
+ onPress: () => {
85
+ _reactNative.Linking.openSettings();
86
+ }
87
+ }]);
88
+ };
89
+ const requestLocationPermission = async () => {
90
+ try {
91
+ console.log('requestLocationPermission called');
92
+ const isLocationPermissionPresent = await _reactNative.PermissionsAndroid.check(_reactNative.PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION);
93
+ console.log('isLocationPermissionPresent: ' + isLocationPermissionPresent + ' showPermissionAlreadyDeniedDialog: ' + showPermissionAlreadyDeniedDialog);
94
+ if (!isLocationPermissionPresent && showPermissionAlreadyDeniedDialog) {
95
+ console.log('showLocationPermissionAlert() called');
96
+ showLocationPermissionAlert();
97
+ } else {
98
+ console.log('requesting location permission');
99
+ const granted = await _reactNative.PermissionsAndroid.request(_reactNative.PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION, {
100
+ title: 'Need Location Permission',
101
+ message: 'Need access to location permission',
102
+ buttonNeutral: 'Ask Me Later',
103
+ buttonNegative: 'Cancel',
104
+ buttonPositive: 'OK'
105
+ });
106
+ if (granted === _reactNative.PermissionsAndroid.RESULTS.GRANTED) {
107
+ if (isLoggingEnabled) {
108
+ console.log('Location permission granted');
109
+ }
110
+ setShowPermissionAlreadyDeniedDialog(false);
111
+ if (!enabled) {
112
+ requestResolution();
113
+ } else {
114
+ var _webviewRef$current;
115
+ var finalString = `window.checkTheGpsPermission(true)`;
116
+ console.log('requestLocationPermission: ' + finalString);
117
+ (_webviewRef$current = webviewRef.current) === null || _webviewRef$current === void 0 || _webviewRef$current.injectJavaScript(finalString);
118
+ }
119
+ } else {
120
+ var _webviewRef$current2;
121
+ setShowPermissionAlreadyDeniedDialog(true);
122
+ console.log('Location permission denied');
123
+ var finalString = `window.checkTheGpsPermission(false)`;
124
+ console.log('requestLocationPermission: ' + finalString);
125
+ (_webviewRef$current2 = webviewRef.current) === null || _webviewRef$current2 === void 0 || _webviewRef$current2.injectJavaScript(finalString);
58
126
  }
59
127
  }
60
- }], {
61
- cancelable: false
62
- });
63
- }, [finishLocationFlow, warn]);
64
- const openLocationServicesSettings = (0, _react.useCallback)(async () => {
65
- pendingSettingsRef.current = 'location-services';
128
+ } catch (e) {
129
+ console.error(e);
130
+ }
131
+ };
132
+ const showHealthConnectPermissionDeniedDialog = () => {
133
+ _reactNative.Alert.alert('Permission Denied', 'Go to Health Connect App to allow app permission', [{
134
+ text: 'Cancel',
135
+ onPress: () => {
136
+ console.log('Cancel clicked');
137
+ }
138
+ }, {
139
+ text: 'Open Health Connect',
140
+ onPress: () => {
141
+ openHealthConnectApp();
142
+ }
143
+ }]);
144
+ };
145
+ const openHealthConnectApp = async () => {
146
+ _reactNative.NativeModules.VisitFitnessModule.openHealthConnectApp();
147
+ };
148
+ const askForHealthConnectPermission = async () => {
66
149
  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);
150
+ const isPermissionGranted = await _reactNative.NativeModules.VisitFitnessModule.askForFitnessPermission();
151
+ if (isLoggingEnabled) {
152
+ console.log('isPermissionGranted: ' + isPermissionGranted);
153
+ }
154
+ if (isPermissionGranted === 'GRANTED') {
155
+ getHealthConnectStatus();
156
+ // getDailyFitnessData();
157
+ } else if (isPermissionGranted === 'CANCELLED') {
158
+ showHealthConnectPermissionDeniedDialog();
159
+ }
160
+ } catch (e) {
161
+ if (isLoggingEnabled) {
162
+ console.error(e);
75
163
  }
76
164
  }
77
- }, [finishLocationFlow, warn]);
78
- const checkLocationServices = (0, _react.useCallback)(async ({
79
- promptIfDisabled
80
- }) => {
165
+ };
166
+ const getHealthConnectStatus = async () => {
81
167
  try {
82
- if (!(VisitRnSdkLocation !== null && VisitRnSdkLocation !== void 0 && VisitRnSdkLocation.isLocationServicesEnabled)) {
83
- throw new Error('VisitRnSdkLocation native module is unavailable.');
168
+ const healthConnectStatus = await _reactNative.NativeModules.VisitFitnessModule.getHealthConnectStatus();
169
+ if (isLoggingEnabled) {
170
+ console.log('getHealthConnectStatus: ' + healthConnectStatus);
84
171
  }
85
- const isEnabled = await VisitRnSdkLocation.isLocationServicesEnabled();
86
- if (isEnabled) {
87
- finishLocationFlow(true);
88
- return;
172
+ if (healthConnectStatus === 'NOT_SUPPORTED') {
173
+ var _webviewRef$current3;
174
+ (_webviewRef$current3 = webviewRef.current) === null || _webviewRef$current3 === void 0 || _webviewRef$current3.injectJavaScript('window.healthConnectNotSupported()');
175
+ } else if (healthConnectStatus === 'NOT_INSTALLED') {
176
+ var _webviewRef$current4, _webviewRef$current5;
177
+ (_webviewRef$current4 = webviewRef.current) === null || _webviewRef$current4 === void 0 || _webviewRef$current4.injectJavaScript('window.healthConnectNotInstall()');
178
+ (_webviewRef$current5 = webviewRef.current) === null || _webviewRef$current5 === void 0 || _webviewRef$current5.injectJavaScript('window.updateFitnessPermissions(false,0,0)');
179
+ } else if (healthConnectStatus === 'INSTALLED') {
180
+ var _webviewRef$current6, _webviewRef$current7;
181
+ (_webviewRef$current6 = webviewRef.current) === null || _webviewRef$current6 === void 0 || _webviewRef$current6.injectJavaScript('window.healthConnectAvailable()');
182
+ (_webviewRef$current7 = webviewRef.current) === null || _webviewRef$current7 === void 0 || _webviewRef$current7.injectJavaScript('window.updateFitnessPermissions(false,0,0)');
183
+ } else if (healthConnectStatus === 'CONNECTED') {
184
+ getDailyFitnessData();
89
185
  }
90
- if (!promptIfDisabled) {
91
- finishLocationFlow(false);
92
- return;
186
+ } catch (e) {
187
+ if (isLoggingEnabled) {
188
+ console.error(e);
93
189
  }
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
190
  }
108
- }, [finishLocationFlow, openLocationServicesSettings, warn]);
109
- const requestLocationPermission = (0, _react.useCallback)(async () => {
110
- if (locationFlowInProgressRef.current || pendingSettingsRef.current !== null) {
111
- return;
191
+ };
192
+ const getDailyFitnessData = async () => {
193
+ if (isLoggingEnabled) {
194
+ console.log('getDailyFitnessData() called');
112
195
  }
113
- locationFlowInProgressRef.current = true;
114
196
  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);
197
+ const dailyFitnessData = await _reactNative.NativeModules.VisitFitnessModule.requestDailyFitnessData();
198
+ if (dailyFitnessData) {
199
+ var _webviewRef$current8;
200
+ (_webviewRef$current8 = webviewRef.current) === null || _webviewRef$current8 === void 0 || _webviewRef$current8.injectJavaScript(dailyFitnessData);
118
201
  }
119
- if (permissionStatus === _reactNativePermissions.RESULTS.GRANTED) {
120
- await checkLocationServices({
121
- promptIfDisabled: true
122
- });
123
- return;
202
+ } catch (error) {
203
+ if (isLoggingEnabled) {
204
+ console.log(error);
205
+ }
206
+ }
207
+ };
208
+ const requestActivityData = async (type, frequency, timeStamp) => {
209
+ if (isLoggingEnabled) {
210
+ console.log('requestActivityData() called');
211
+ }
212
+ try {
213
+ const graphData = await _reactNative.NativeModules.VisitFitnessModule.requestActivityDataFromHealthConnect(type, frequency, timeStamp);
214
+ if (isLoggingEnabled) {
215
+ console.log(`requestActivityData() data: ` + graphData);
124
216
  }
125
- if (permissionStatus === _reactNativePermissions.RESULTS.BLOCKED) {
126
- showLocationPermissionSettingsAlert();
127
- return;
217
+ if (graphData) {
218
+ var _webviewRef$current9;
219
+ (_webviewRef$current9 = webviewRef.current) === null || _webviewRef$current9 === void 0 || _webviewRef$current9.injectJavaScript('window.' + graphData);
128
220
  }
129
- finishLocationFlow(false);
130
221
  } catch (error) {
131
- warn('Unable to check or request location permission.', error);
132
- finishLocationFlow(false);
222
+ if (isLoggingEnabled) {
223
+ console.log(error);
224
+ }
133
225
  }
134
- }, [checkLocationServices, finishLocationFlow, showLocationPermissionSettingsAlert, warn]);
135
- const recheckAfterSettings = (0, _react.useCallback)(async () => {
136
- const settingsType = pendingSettingsRef.current;
137
- if (!settingsType) {
138
- return;
226
+ };
227
+ const updateApiBaseUrl = async (apiBaseUrl, authtoken, googleFitLastSync, gfHourlyLastSync) => {
228
+ if (isLoggingEnabled) {
229
+ console.log('updateApiBaseUrl() called.');
139
230
  }
140
- pendingSettingsRef.current = null;
141
231
  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;
232
+ const message = await _reactNative.NativeModules.VisitFitnessModule.updateApiBaseUrl(apiBaseUrl, authtoken, googleFitLastSync, gfHourlyLastSync);
233
+ if (isLoggingEnabled) {
234
+ console.log(message);
146
235
  }
147
- await checkLocationServices({
148
- promptIfDisabled: settingsType === 'location-permission'
149
- });
150
236
  } catch (error) {
151
- warn('Unable to recheck location access after settings.', error);
152
- finishLocationFlow(false);
237
+ if (isLoggingEnabled) {
238
+ console.log(error);
239
+ }
153
240
  }
154
- }, [checkLocationServices, finishLocationFlow, warn]);
241
+ };
155
242
  const runBeforeFirst = `
156
243
  window.isNativeApp = true;
157
244
  window.platform = "ANDROID";
158
- window.setSdkPlatform?.('ANDROID');
245
+ window.setSdkPlatform('ANDROID');
159
246
  true; // note: this is required, or you'll sometimes get silent failures
160
247
  `;
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
248
  const handleMessage = event => {
199
- var _webviewRef$current3;
249
+ var _webviewRef$current0;
200
250
  if (event.nativeEvent.data != null) {
201
251
  try {
202
- const parsedObject = JSON.parse(event.nativeEvent.data);
203
252
  if (isLoggingEnabled) {
204
- console.log('Received WebView method:', parsedObject.method);
253
+ console.log('Event :' + event.nativeEvent.data);
205
254
  }
255
+ const parsedObject = JSON.parse(event.nativeEvent.data);
206
256
  if (parsedObject.method != null) {
207
257
  switch (parsedObject.method) {
208
- case 'startVideoCall':
209
- startVideoConsultation(parsedObject);
258
+ case 'GET_HEALTH_CONNECT_STATUS':
259
+ getHealthConnectStatus();
260
+ break;
261
+ case 'CONNECT_TO_GOOGLE_FIT':
262
+ askForHealthConnectPermission();
210
263
  break;
211
264
  case 'UPDATE_PLATFORM':
212
- (_webviewRef$current3 = webviewRef.current) === null || _webviewRef$current3 === void 0 || _webviewRef$current3.injectJavaScript('window.setSdkPlatform("ANDROID")');
265
+ (_webviewRef$current0 = webviewRef.current) === null || _webviewRef$current0 === void 0 || _webviewRef$current0.injectJavaScript('window.setSdkPlatform("ANDROID")');
266
+ break;
267
+ case 'UPDATE_API_BASE_URL':
268
+ {
269
+ let apiBaseUrl = parsedObject.apiBaseUrl;
270
+ let authtoken = parsedObject.authtoken;
271
+ let googleFitLastSync = parsedObject.googleFitLastSync;
272
+ let gfHourlyLastSync = parsedObject.gfHourlyLastSync;
273
+ if (isLoggingEnabled) {
274
+ console.log('apiBaseUrl: ' + 'NOT SHOWN' + ' authtoken: ' + 'NOT SHOWN' + ' googleFitLastSync: ' + googleFitLastSync + ' gfHourlyLastSync: ' + gfHourlyLastSync);
275
+ }
276
+ updateApiBaseUrl(apiBaseUrl, authtoken, googleFitLastSync, gfHourlyLastSync);
277
+ }
278
+ break;
279
+ case 'GET_DATA_TO_GENERATE_GRAPH':
280
+ {
281
+ let type = parsedObject.type;
282
+ let frequency = parsedObject.frequency;
283
+ let timeStamp = parsedObject.timestamp;
284
+ if (isLoggingEnabled) {
285
+ console.log('type: ' + type + ' frequency:' + frequency + ' timeStamp: ' + timeStamp);
286
+ }
287
+ requestActivityData(type, frequency, timeStamp);
288
+ }
213
289
  break;
214
290
  case 'GET_LOCATION_PERMISSIONS':
291
+ console.log('GET_LOCATION_PERMISSIONS');
215
292
  requestLocationPermission();
216
293
  break;
217
294
  case 'OPEN_PDF':
218
- if (parsedObject.url) {
219
- _reactNative.Linking.openURL(parsedObject.url);
295
+ {
296
+ let pdfUrl = parsedObject.url;
297
+ // console.log("pdfUrl "+pdfUrl);
298
+
299
+ _reactNative.Linking.openURL(pdfUrl);
220
300
  }
221
301
  break;
302
+ case 'OPEN_FACE_SCAN_FLOW':
303
+ _reactNativeEventListeners.EventRegister.emitEvent('visit-event', {
304
+ message: 'OPEN_FACE_SCAN_FLOW'
305
+ });
306
+ break;
222
307
  case 'CLOSE_VIEW':
223
308
  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
309
  default:
238
310
  break;
239
311
  }
240
312
  }
241
- } catch (error) {
242
- warn('Unable to handle WebView message.', error);
313
+ } catch (exception) {
314
+ console.log('Exception occured:' + exception.message);
243
315
  }
244
316
  }
245
317
  };
318
+ const [canGoBack, setCanGoBack] = (0, _react.useState)(false);
246
319
  const handleBack = (0, _react.useCallback)(() => {
247
320
  if (canGoBack && webviewRef.current) {
248
- webviewRef.current.goBack();
321
+ var _webviewRef$current1;
322
+ (_webviewRef$current1 = webviewRef.current) === null || _webviewRef$current1 === void 0 || _webviewRef$current1.goBack();
249
323
  return true;
250
324
  }
251
325
  return false;
252
326
  }, [canGoBack]);
253
327
  (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();
328
+ const checkLocationPermissionAndSendCallback = async () => {
329
+ const isLocationPermissionAvailable = await _reactNative.PermissionsAndroid.check(_reactNative.PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION);
330
+ if (isLoggingEnabled) {
331
+ console.log('checkLocationPermissionAndSendCallback() isLocationPermissionAvailable: ' + isLocationPermissionAvailable + 'isGPSPermissionAvailabe: true');
332
+ }
333
+ if (isLocationPermissionAvailable) {
334
+ var _webviewRef$current10;
335
+ var finalString = `window.checkTheGpsPermission(true)`;
336
+ console.log('listener: ' + finalString);
337
+ (_webviewRef$current10 = webviewRef.current) === null || _webviewRef$current10 === void 0 || _webviewRef$current10.injectJavaScript(finalString);
338
+ }
339
+ };
340
+
341
+ // Subscribe to GPS/location setting changes
342
+ const locationSub = addListener(({
343
+ locationEnabled
344
+ }) => {
345
+ if (locationEnabled) {
346
+ checkLocationPermissionAndSendCallback();
260
347
  }
261
348
  });
349
+
350
+ // Subscribe to Android hardware back press
351
+ const backSub = _reactNative.BackHandler.addEventListener('hardwareBackPress', handleBack);
352
+
353
+ // Cleanup subscriptions on unmount
262
354
  return () => {
263
355
  backSub === null || backSub === void 0 || backSub.remove();
264
- appStateSub === null || appStateSub === void 0 || appStateSub.remove();
356
+ locationSub === null || locationSub === void 0 || locationSub.remove();
265
357
  };
266
- }, [handleBack, recheckAfterSettings]);
358
+ }, [handleBack, isLoggingEnabled]);
267
359
  return (
268
360
  /*#__PURE__*/
269
361
  // eslint-disable-next-line react-native/no-inline-styles
@@ -271,7 +363,7 @@ const VisitRnSdkView = /*#__PURE__*/(0, _react.forwardRef)(function VisitRnSdkVi
271
363
  style: {
272
364
  flex: 1
273
365
  }
274
- }, source ? /*#__PURE__*/_react.default.createElement(SdkWebView, {
366
+ }, source ? /*#__PURE__*/_react.default.createElement(_reactNativeWebview.default, {
275
367
  ref: webviewRef,
276
368
  source: {
277
369
  uri: source,
@@ -284,29 +376,60 @@ const VisitRnSdkView = /*#__PURE__*/(0, _react.forwardRef)(function VisitRnSdkVi
284
376
  javaScriptEnabled: true,
285
377
  onLoadProgress: event => setCanGoBack(event.nativeEvent.canGoBack),
286
378
  onError: errorMessage => {
379
+ _reactNativeEventListeners.EventRegister.emitEvent('visit-event', {
380
+ message: 'web-view-error',
381
+ errorMessage: errorMessage
382
+ });
287
383
  if (isLoggingEnabled) {
288
384
  console.warn('Webview error: ', errorMessage);
289
385
  }
290
386
  }
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
- }))
387
+ }) : null)
309
388
  );
310
- });
389
+ };
390
+ const fetchDailyFitnessData = (startTimeStamp, isLoggingEnabled) => {
391
+ return new Promise((resolve, reject) => {
392
+ console.log('fetchDailyFitnessData called: ' + startTimeStamp);
393
+ _reactNative.NativeModules.VisitFitnessModule.fetchDailyFitnessData(startTimeStamp).then(result => {
394
+ resolve(result);
395
+ }).catch(err => reject(err));
396
+ });
397
+ };
398
+ exports.fetchDailyFitnessData = fetchDailyFitnessData;
399
+ const fetchHourlyFitnessData = (startTimeStamp, isLoggingEnabled) => {
400
+ return new Promise((resolve, reject) => {
401
+ if (isLoggingEnabled) {
402
+ console.log('fetchHourlyFitnessData called: ' + startTimeStamp);
403
+ }
404
+ _reactNative.NativeModules.VisitFitnessModule.fetchHourlyFitnessData(startTimeStamp).then(result => {
405
+ resolve(result);
406
+ }).catch(err => reject(err));
407
+ });
408
+ };
409
+
410
+ // debounce, deferred
411
+ // function debounce(task, ms) {
412
+ // let t = { promise: null, cancel: (_) => void 0 };
413
+ // return async (...args) => {
414
+ // try {
415
+ // t.cancel();
416
+ // t = deferred(ms);
417
+ // await t.promise;
418
+ // await task(...args);
419
+ // } catch (_) {
420
+ // console.log('cleaning up cancelled promise');
421
+ // }
422
+ // };
423
+ // }
424
+
425
+ // function deferred(ms) {
426
+ // let cancel,
427
+ // promise = new Promise((resolve, reject) => {
428
+ // cancel = reject;
429
+ // setTimeout(resolve, ms);
430
+ // });
431
+ // return { promise, cancel };
432
+ // }
433
+ exports.fetchHourlyFitnessData = fetchHourlyFitnessData;
311
434
  var _default = exports.default = VisitRnSdkView;
312
435
  //# sourceMappingURL=index.android.js.map