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