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
@@ -0,0 +1,284 @@
1
+ import React, {
2
+ useRef,
3
+ useEffect,
4
+ useState,
5
+ useMemo,
6
+ useCallback,
7
+ } from 'react';
8
+ import {
9
+ StyleSheet,
10
+ SafeAreaView,
11
+ NativeModules,
12
+ Linking,
13
+ Platform,
14
+ Dimensions,
15
+ Alert,
16
+ AppState,
17
+ } from 'react-native';
18
+ import { EventRegister } from 'react-native-event-listeners';
19
+ import { WebView } from 'react-native-webview';
20
+
21
+ const LINKING_ERROR =
22
+ `The package 'react-native-visit-rn-sdk' doesn't seem to be linked. Make sure: \n\n` +
23
+ Platform.select({ ios: "- You have run 'pod install'\n", default: '' }) +
24
+ '- You rebuilt the app after installing the package\n' +
25
+ '- You are not using Expo Go\n';
26
+
27
+ const escapeChars = {
28
+ lt: '<',
29
+ gt: '>',
30
+ quot: '"',
31
+ apos: "'",
32
+ amp: '&',
33
+ };
34
+
35
+ const unescapeHTML = (str) =>
36
+ // modified from underscore.string and string.js
37
+ // eslint-disable-next-line no-useless-escape
38
+ str.replace(/\&([^;]+);/g, (entity, entityCode) => {
39
+ let match;
40
+
41
+ if (entityCode in escapeChars) {
42
+ return escapeChars[entityCode];
43
+ } else if ((match = entityCode.match(/^#x([\da-fA-F]+)$/))) {
44
+ return String.fromCharCode(parseInt(match[1], 16));
45
+ } else if ((match = entityCode.match(/^#(\d+)$/))) {
46
+ return String.fromCharCode(match[1]);
47
+ } else {
48
+ return entity;
49
+ }
50
+ });
51
+
52
+ const visitEvent = 'visit-event';
53
+
54
+ /** @param {{ ssoURL: string, isLoggingEnabled?: boolean }} props */
55
+ const VisitRnSdkView = ({ ssoURL, isLoggingEnabled = false }) => {
56
+ const source = ssoURL?.trim();
57
+ const VisitRnSdkViewManager = useMemo(
58
+ () =>
59
+ NativeModules.VisitRnSdkViewManager
60
+ ? NativeModules.VisitRnSdkViewManager
61
+ : new Proxy(
62
+ {},
63
+ {
64
+ get() {
65
+ throw new Error(LINKING_ERROR);
66
+ },
67
+ }
68
+ ),
69
+ []
70
+ );
71
+
72
+ const webviewRef = useRef(null);
73
+ const [hasLoadedOnce, setHasLoadedOnce] = useState(false);
74
+
75
+ const refreshHealthKitPermissionState = useCallback(async () => {
76
+ try {
77
+ const status = await VisitRnSdkViewManager?.getHealthKitConnectStatus?.();
78
+
79
+ if (isLoggingEnabled) {
80
+ console.log('getHealthKitConnectStatus on foreground: ', status);
81
+ }
82
+
83
+ if (status === 'NOT_SUPPORTED') {
84
+ webviewRef.current?.injectJavaScript(
85
+ 'window.unsupportedHealthKitDevice(true)'
86
+ );
87
+ return;
88
+ }
89
+
90
+ if (status === 'CONNECTED') {
91
+ const [steps, sleep] = await Promise.allSettled([
92
+ VisitRnSdkViewManager?.getTodayStepCount?.(),
93
+ VisitRnSdkViewManager?.getTodaySleepMinutes?.(),
94
+ ]);
95
+ const stepCount =
96
+ steps.status === 'fulfilled' ? Number(steps.value) || 0 : 0;
97
+ const sleepMinutes =
98
+ sleep.status === 'fulfilled' ? Number(sleep.value) || 0 : 0;
99
+ webviewRef.current?.injectJavaScript(
100
+ `window.updateFitnessPermissions(true,${stepCount},${sleepMinutes})`
101
+ );
102
+ return;
103
+ }
104
+
105
+ webviewRef.current?.injectJavaScript(
106
+ 'window.updateFitnessPermissions(false,0,0)'
107
+ );
108
+ } catch (err) {
109
+ if (isLoggingEnabled) {
110
+ console.warn('refreshHealthKitPermissionState failed: ', err?.message);
111
+ }
112
+ }
113
+ }, [VisitRnSdkViewManager, isLoggingEnabled]);
114
+
115
+ useEffect(() => {
116
+ const subscription = AppState.addEventListener('change', (nextAppState) => {
117
+ if (nextAppState === 'active') {
118
+ refreshHealthKitPermissionState();
119
+ }
120
+ });
121
+
122
+ return () => {
123
+ subscription.remove();
124
+ };
125
+ }, [refreshHealthKitPermissionState]);
126
+
127
+ const handleMessage = async (event) => {
128
+ const data = JSON.parse(unescapeHTML(event.nativeEvent.data));
129
+ const {
130
+ method,
131
+ type,
132
+ frequency,
133
+ timestamp,
134
+ apiBaseUrl,
135
+ authtoken,
136
+ googleFitLastSync,
137
+ gfHourlyLastSync,
138
+ url,
139
+ } = data;
140
+ console.log('handleMessage data is', data);
141
+ console.log(unescapeHTML(event.nativeEvent.data));
142
+ switch (method) {
143
+ case 'UPDATE_PLATFORM':
144
+ webviewRef.current?.injectJavaScript('window.setSdkPlatform("IOS")');
145
+ break;
146
+ case 'CONNECT_TO_GOOGLE_FIT':
147
+ if (Platform.isPad) {
148
+ console.log('unsupportedHealthKitDevice triggered');
149
+ webviewRef.current?.injectJavaScript(
150
+ 'window.unsupportedHealthKitDevice(true)'
151
+ );
152
+ } else {
153
+ VisitRnSdkViewManager?.connectToAppleHealth((res) => {
154
+ const authStatus = res?.authStatus;
155
+ const steps = Number(res?.numberOfSteps) || 0;
156
+ const sleep = Number(res?.sleepTime) || 0;
157
+
158
+ if (authStatus === 'GRANTED') {
159
+ webviewRef.current?.injectJavaScript(
160
+ `window.updateFitnessPermissions(true,${steps},${sleep})`
161
+ );
162
+ return;
163
+ }
164
+
165
+ // Denied / unavailable: tell the WebView permission isn't granted
166
+ // and offer to open the Apple Health app so the user can toggle
167
+ // it manually (mirrors Android's Health Connect flow).
168
+ webviewRef.current?.injectJavaScript(
169
+ 'window.updateFitnessPermissions(false,0,0)'
170
+ );
171
+
172
+ if (authStatus === 'DENIED') {
173
+ Alert.alert(
174
+ 'Permission Denied',
175
+ 'To allow permission, please follow these steps:\n\n' +
176
+ '1. Open Settings\n' +
177
+ '2. Tap on Apps → Health\n' +
178
+ '3. Tap Data Access & Devices\n' +
179
+ '4. Select this app and enable all categories',
180
+ [
181
+ { text: 'Cancel', style: 'cancel' },
182
+ {
183
+ text: 'Open Settings',
184
+ onPress: () => {
185
+ VisitRnSdkViewManager?.openAppleHealthApp?.().catch(
186
+ (err) =>
187
+ console.log(
188
+ 'openAppleHealthApp failed:',
189
+ err?.message
190
+ )
191
+ );
192
+ },
193
+ },
194
+ ]
195
+ );
196
+ }
197
+ });
198
+ }
199
+ break;
200
+ case 'GET_DATA_TO_GENERATE_GRAPH':
201
+ VisitRnSdkViewManager?.renderGraph(
202
+ { type, frequency, timestamp },
203
+ (err, results) => {
204
+ if (err) {
205
+ console.log('error initializing Healthkit: ', err);
206
+ return;
207
+ }
208
+ if (results[0]) {
209
+ console.log('results initializing Healthkit: ', results[0]);
210
+ webviewRef.current?.injectJavaScript(`window.${results[0]}`);
211
+ }
212
+ }
213
+ );
214
+ break;
215
+ case 'UPDATE_API_BASE_URL':
216
+ if (!hasLoadedOnce) {
217
+ VisitRnSdkViewManager?.updateApiUrl({
218
+ apiBaseUrl,
219
+ authToken: authtoken,
220
+ googleFitLastSync,
221
+ gfHourlyLastSync,
222
+ });
223
+ setHasLoadedOnce(true);
224
+ }
225
+ break;
226
+
227
+ case 'OPEN_PDF':
228
+ Linking.openURL(url);
229
+ break;
230
+ case 'OPEN_FACE_SCAN_FLOW':
231
+ EventRegister.emitEvent('visit-event', {
232
+ message: 'OPEN_FACE_SCAN_FLOW',
233
+ });
234
+ break;
235
+ case 'CLOSE_VIEW':
236
+ break;
237
+ case 'GET_LOCATION_PERMISSIONS':
238
+ webviewRef.current?.injectJavaScript(
239
+ 'window.checkTheGpsPermission(true)'
240
+ );
241
+ break;
242
+
243
+ default:
244
+ break;
245
+ }
246
+ };
247
+
248
+ const { height, width } = Dimensions.get('screen');
249
+ return (
250
+ // eslint-disable-next-line react-native/no-inline-styles
251
+ <SafeAreaView style={{ flex: 1, backgroundColor: 'white', height, width }}>
252
+ {source ? (
253
+ <WebView
254
+ ref={webviewRef}
255
+ source={{ uri: source }}
256
+ style={styles.webView}
257
+ javascriptEnabled
258
+ onMessage={handleMessage}
259
+ onError={(errorMessage) => {
260
+ EventRegister.emitEvent(visitEvent, {
261
+ message: 'web-view-error',
262
+ errorMessage: errorMessage,
263
+ });
264
+ if (isLoggingEnabled) {
265
+ console.warn('Webview error: ', errorMessage);
266
+ }
267
+ }}
268
+ />
269
+ ) : null}
270
+ </SafeAreaView>
271
+ );
272
+ };
273
+
274
+ const styles = StyleSheet.create({
275
+ webViewContainer: {
276
+ flex: 1,
277
+ backgroundColor: 'white',
278
+ },
279
+ webView: {
280
+ flex: 1,
281
+ },
282
+ });
283
+
284
+ export default VisitRnSdkView;
@@ -1,37 +0,0 @@
1
- package com.visitrnsdk
2
-
3
- import android.content.Context
4
- import android.location.LocationManager
5
- import android.os.Build
6
- import com.facebook.react.bridge.Promise
7
- import com.facebook.react.bridge.ReactApplicationContext
8
- import com.facebook.react.bridge.ReactContextBaseJavaModule
9
- import com.facebook.react.bridge.ReactMethod
10
-
11
- class VisitRnSdkLocationModule(
12
- reactContext: ReactApplicationContext
13
- ) : ReactContextBaseJavaModule(reactContext) {
14
- override fun getName() = "VisitRnSdkLocation"
15
-
16
- @ReactMethod
17
- fun isLocationServicesEnabled(promise: Promise) {
18
- try {
19
- val locationManager =
20
- reactApplicationContext.getSystemService(Context.LOCATION_SERVICE) as LocationManager
21
- val isEnabled = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
22
- locationManager.isLocationEnabled
23
- } else {
24
- locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER) ||
25
- locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)
26
- }
27
-
28
- promise.resolve(isEnabled)
29
- } catch (error: Exception) {
30
- promise.reject(
31
- "LOCATION_SERVICES_CHECK_FAILED",
32
- "Unable to determine whether Location Services are enabled.",
33
- error
34
- )
35
- }
36
- }
37
- }