react-native-visit-rn-sdk 6.0.1 → 6.0.3

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 (50) hide show
  1. package/README.md +89 -10
  2. package/android/src/main/java/com/visitrnsdk/VisitRnSdkLocationModule.kt +37 -0
  3. package/android/src/main/java/com/visitrnsdk/VisitRnSdkPackage.kt +1 -1
  4. package/lib/commonjs/components/VideoCallComponent.js +11 -16
  5. package/lib/commonjs/components/VideoCallComponent.js.map +1 -1
  6. package/lib/commonjs/index.android.js +177 -146
  7. package/lib/commonjs/index.android.js.map +1 -1
  8. package/lib/commonjs/index.ios.js +74 -48
  9. package/lib/commonjs/index.ios.js.map +1 -1
  10. package/lib/commonjs/index.js +6 -0
  11. package/lib/commonjs/index.js.map +1 -0
  12. package/lib/commonjs/shims.d.js +2 -0
  13. package/lib/commonjs/shims.d.js.map +1 -0
  14. package/lib/commonjs/types.js +2 -0
  15. package/lib/commonjs/types.js.map +1 -0
  16. package/lib/module/components/VideoCallComponent.js +11 -16
  17. package/lib/module/components/VideoCallComponent.js.map +1 -1
  18. package/lib/module/index.android.js +179 -149
  19. package/lib/module/index.android.js.map +1 -1
  20. package/lib/module/index.ios.js +75 -49
  21. package/lib/module/index.ios.js.map +1 -1
  22. package/lib/module/index.js +2 -0
  23. package/lib/module/index.js.map +1 -0
  24. package/lib/module/shims.d.js +2 -0
  25. package/lib/module/shims.d.js.map +1 -0
  26. package/lib/module/types.js +2 -0
  27. package/lib/module/types.js.map +1 -0
  28. package/lib/typescript/components/VideoCallComponent.d.ts +79 -0
  29. package/lib/typescript/components/VideoCallComponent.d.ts.map +1 -0
  30. package/lib/typescript/index.android.d.ts +5 -0
  31. package/lib/typescript/index.android.d.ts.map +1 -0
  32. package/lib/typescript/index.d.ts +17 -0
  33. package/lib/typescript/index.d.ts.map +1 -0
  34. package/lib/typescript/index.ios.d.ts +5 -0
  35. package/lib/typescript/index.ios.d.ts.map +1 -0
  36. package/lib/typescript/types.d.ts +24 -0
  37. package/lib/typescript/types.d.ts.map +1 -0
  38. package/package.json +20 -11
  39. package/react-native-visit-rn-sdk.podspec +1 -1
  40. package/src/components/VideoCallComponent.tsx +1484 -0
  41. package/src/index.android.tsx +459 -0
  42. package/src/index.ios.tsx +238 -0
  43. package/src/index.tsx +25 -0
  44. package/src/shims.d.ts +49 -0
  45. package/src/types.ts +25 -0
  46. package/lib/typescript/index.test.d.ts +0 -1
  47. package/lib/typescript/index.test.d.ts.map +0 -1
  48. package/src/components/VideoCallComponent.js +0 -1305
  49. package/src/index.android.js +0 -342
  50. package/src/index.ios.js +0 -168
@@ -1,342 +0,0 @@
1
- import React, { useRef, useEffect, useState, useCallback } from 'react';
2
- import { EventRegister } from 'react-native-event-listeners';
3
-
4
- import {
5
- SafeAreaView,
6
- PermissionsAndroid,
7
- BackHandler,
8
- Linking,
9
- Alert,
10
- } from 'react-native';
11
-
12
- import WebView from 'react-native-webview';
13
-
14
- import LocationEnabler from '@visit-health/react-native-location-enabler';
15
-
16
- import VideoCallComponent from './components/VideoCallComponent';
17
-
18
- const {
19
- PRIORITIES: { HIGH_ACCURACY },
20
- useLocationSettings,
21
- addListener,
22
- } = LocationEnabler;
23
-
24
- const VisitRnSdkView = ({ ssoLink, isLoggingEnabled }) => {
25
- const source = typeof ssoLink === 'string' ? ssoLink.trim() : '';
26
-
27
- const [
28
- showPermissionAlreadyDeniedDialog,
29
- setShowPermissionAlreadyDeniedDialog,
30
- ] = useState(false);
31
-
32
- const [enabled, requestResolution] = useLocationSettings(
33
- {
34
- priority: HIGH_ACCURACY, // default BALANCED_POWER_ACCURACY
35
- alwaysShow: true, // default false
36
- needBle: true, // default false
37
- },
38
- false /* optional: default undefined */
39
- );
40
-
41
- const webviewRef = useRef(null);
42
- const videoCallRef = useRef(null);
43
-
44
- const showLocationPermissionAlert = () => {
45
- Alert.alert(
46
- 'Permission Required',
47
- 'Allow location permission from app settings',
48
- [
49
- {
50
- text: 'Cancel',
51
- onPress: () => {
52
- console.log('Cancel clicked');
53
- },
54
- },
55
- {
56
- text: 'Go to Settings',
57
- onPress: () => {
58
- Linking.openSettings();
59
- },
60
- },
61
- ]
62
- );
63
- };
64
-
65
- const requestLocationPermission = async () => {
66
- try {
67
- console.log('requestLocationPermission called');
68
-
69
- const isLocationPermissionPresent = await PermissionsAndroid.check(
70
- PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION
71
- );
72
-
73
- console.log(
74
- 'isLocationPermissionPresent: ' +
75
- isLocationPermissionPresent +
76
- ' showPermissionAlreadyDeniedDialog: ' +
77
- showPermissionAlreadyDeniedDialog
78
- );
79
-
80
- if (!isLocationPermissionPresent && showPermissionAlreadyDeniedDialog) {
81
- console.log('showLocationPermissionAlert() called');
82
-
83
- showLocationPermissionAlert();
84
- } else {
85
- console.log('requesting location permission');
86
-
87
- const granted = await PermissionsAndroid.request(
88
- PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION,
89
- {
90
- title: 'Need Location Permission',
91
- message: 'Need access to location permission',
92
- buttonNeutral: 'Ask Me Later',
93
- buttonNegative: 'Cancel',
94
- buttonPositive: 'OK',
95
- }
96
- );
97
- if (granted === PermissionsAndroid.RESULTS.GRANTED) {
98
- if (isLoggingEnabled) {
99
- console.log('Location permission granted');
100
- }
101
- setShowPermissionAlreadyDeniedDialog(false);
102
-
103
- if (!enabled) {
104
- requestResolution();
105
- } else {
106
- var finalString = `window.checkTheGpsPermission(true)`;
107
- console.log('requestLocationPermission: ' + finalString);
108
-
109
- webviewRef.current?.injectJavaScript(finalString);
110
- }
111
- } else {
112
- setShowPermissionAlreadyDeniedDialog(true);
113
- console.log('Location permission denied');
114
-
115
- var finalString = `window.checkTheGpsPermission(false)`;
116
- console.log('requestLocationPermission: ' + finalString);
117
-
118
- webviewRef.current?.injectJavaScript(finalString);
119
- }
120
- }
121
- } catch (e) {
122
- console.error(e);
123
- }
124
- };
125
-
126
- const runBeforeFirst = `
127
- window.isNativeApp = true;
128
- window.platform = "ANDROID";
129
- window.setSdkPlatform('ANDROID');
130
- true; // note: this is required, or you'll sometimes get silent failures
131
- `;
132
-
133
- const startVideoConsultation = useCallback(
134
- (parsedObject) => {
135
- const roomName = parsedObject?.roomName;
136
- const accessToken = parsedObject?.token;
137
- const rawDoctorName = parsedObject?.doctorName;
138
- const visibleDoctorName =
139
- rawDoctorName && rawDoctorName.indexOf('Dr.') > -1
140
- ? rawDoctorName.replace('Dr. ', '')
141
- : rawDoctorName && rawDoctorName.indexOf('Dr') > -1
142
- ? rawDoctorName.replace('Dr ', '')
143
- : null;
144
- const userName = parsedObject?.userName;
145
-
146
- if (!roomName || !accessToken) {
147
- if (isLoggingEnabled) {
148
- console.warn('Video call payload missing roomName/accessToken.');
149
- }
150
- return;
151
- }
152
-
153
- videoCallRef.current?.startVideoCall({
154
- roomName,
155
- accessToken,
156
- doctorName: rawDoctorName ?? '',
157
- visibleDoctorName: visibleDoctorName ?? '',
158
- userName,
159
- });
160
- },
161
- [isLoggingEnabled]
162
- );
163
-
164
- const handleMessage = (event) => {
165
- if (event.nativeEvent.data != null) {
166
- try {
167
- if (isLoggingEnabled) {
168
- console.log('Event :' + event.nativeEvent.data);
169
- }
170
- const parsedObject = JSON.parse(event.nativeEvent.data);
171
- if (parsedObject.method != null) {
172
- switch (parsedObject.method) {
173
- case 'startVideoCall':
174
- startVideoConsultation(parsedObject);
175
- break;
176
- case 'UPDATE_PLATFORM':
177
- webviewRef.current?.injectJavaScript(
178
- 'window.setSdkPlatform("ANDROID")'
179
- );
180
- break;
181
- case 'GET_LOCATION_PERMISSIONS':
182
- console.log('GET_LOCATION_PERMISSIONS');
183
- requestLocationPermission();
184
- break;
185
- case 'OPEN_PDF':
186
- {
187
- let pdfUrl = parsedObject.url;
188
- // console.log("pdfUrl "+pdfUrl);
189
-
190
- Linking.openURL(pdfUrl);
191
- }
192
- break;
193
- case 'OPEN_FACE_SCAN_FLOW':
194
- EventRegister.emitEvent('visit-event', {
195
- message: 'OPEN_FACE_SCAN_FLOW',
196
- });
197
- break;
198
- case 'CLOSE_VIEW':
199
- break;
200
-
201
- default:
202
- break;
203
- }
204
- }
205
- } catch (exception) {
206
- console.log('Exception occured:' + exception.message);
207
- }
208
- }
209
- };
210
-
211
- const [canGoBack, setCanGoBack] = useState(false);
212
-
213
- const handleBack = useCallback(() => {
214
- if (canGoBack && webviewRef.current) {
215
- webviewRef.current?.goBack();
216
- return true;
217
- }
218
- return false;
219
- }, [canGoBack]);
220
-
221
- const checkLocationPermissionAndSendCallback = useCallback(async () => {
222
- const isLocationPermissionAvailable = await PermissionsAndroid.check(
223
- PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION
224
- );
225
-
226
- if (isLoggingEnabled) {
227
- console.log(
228
- 'checkLocationPermissionAndSendCallback() isLocationPermissionAvailable: ' +
229
- isLocationPermissionAvailable +
230
- 'isGPSPermissionAvailabe: true'
231
- );
232
- }
233
-
234
- if (isLocationPermissionAvailable) {
235
- var finalString = `window.checkTheGpsPermission(true)`;
236
-
237
- console.log('listener: ' + finalString);
238
-
239
- webviewRef.current?.injectJavaScript(finalString);
240
- }
241
- }, [isLoggingEnabled]);
242
-
243
- useEffect(() => {
244
- // Subscribe to GPS/location setting changes
245
- const locationSub = addListener(({ locationEnabled }) => {
246
- if (locationEnabled) {
247
- checkLocationPermissionAndSendCallback();
248
- }
249
- });
250
-
251
- // Subscribe to Android hardware back press
252
- const backSub = BackHandler.addEventListener(
253
- 'hardwareBackPress',
254
- handleBack
255
- );
256
-
257
- // Cleanup subscriptions on unmount
258
- return () => {
259
- backSub?.remove();
260
- locationSub?.remove();
261
- };
262
- }, [handleBack, checkLocationPermissionAndSendCallback]);
263
-
264
- return (
265
- // eslint-disable-next-line react-native/no-inline-styles
266
- <SafeAreaView style={{ flex: 1 }}>
267
- {source ? (
268
- <WebView
269
- ref={webviewRef}
270
- source={{
271
- uri: source,
272
- headers: {
273
- platform: 'ANDROID',
274
- },
275
- }}
276
- onMessage={handleMessage}
277
- injectedJavaScriptBeforeContentLoaded={runBeforeFirst}
278
- javaScriptEnabled={true}
279
- onLoadProgress={(event) => setCanGoBack(event.nativeEvent.canGoBack)}
280
- onError={(errorMessage) => {
281
- EventRegister.emitEvent('visit-event', {
282
- message: 'web-view-error',
283
- errorMessage: errorMessage,
284
- });
285
- if (isLoggingEnabled) {
286
- console.warn('Webview error: ', errorMessage);
287
- }
288
- }}
289
- />
290
- ) : null}
291
- <VideoCallComponent
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
- />
309
- </SafeAreaView>
310
- );
311
- };
312
-
313
- // debounce, deferred
314
- // function debounce(task, ms) {
315
- // let t = { promise: null, cancel: (_) => void 0 };
316
- // return async (...args) => {
317
- // try {
318
- // t.cancel();
319
- // t = deferred(ms);
320
- // await t.promise;
321
- // await task(...args);
322
- // } catch (_) {
323
- // console.log('cleaning up cancelled promise');
324
- // }
325
- // };
326
- // }
327
-
328
- // function deferred(ms) {
329
- // let cancel,
330
- // promise = new Promise((resolve, reject) => {
331
- // cancel = reject;
332
- // setTimeout(resolve, ms);
333
- // });
334
- // return { promise, cancel };
335
- // }
336
-
337
- export default VisitRnSdkView;
338
-
339
- VisitRnSdkView.defaultProps = {
340
- ssoLink: '',
341
- isLoggingEnabled: false,
342
- };
package/src/index.ios.js DELETED
@@ -1,168 +0,0 @@
1
- import React, { useRef, useCallback } from 'react';
2
- import { StyleSheet, SafeAreaView, Linking, Dimensions } from 'react-native';
3
- import { EventRegister } from 'react-native-event-listeners';
4
- import { WebView } from 'react-native-webview';
5
- import VideoCallComponent from './components/VideoCallComponent';
6
-
7
- const escapeChars = {
8
- lt: '<',
9
- gt: '>',
10
- quot: '"',
11
- apos: "'",
12
- amp: '&',
13
- };
14
-
15
- const unescapeHTML = (str) =>
16
- // modified from underscore.string and string.js
17
- // eslint-disable-next-line no-useless-escape
18
- str.replace(/\&([^;]+);/g, (entity, entityCode) => {
19
- let match;
20
-
21
- if (entityCode in escapeChars) {
22
- return escapeChars[entityCode];
23
- } else if ((match = entityCode.match(/^#x([\da-fA-F]+)$/))) {
24
- return String.fromCharCode(parseInt(match[1], 16));
25
- } else if ((match = entityCode.match(/^#(\d+)$/))) {
26
- return String.fromCharCode(match[1]);
27
- } else {
28
- return entity;
29
- }
30
- });
31
-
32
- const visitEvent = 'visit-event';
33
-
34
- const VisitRnSdkView = ({ ssoLink, isLoggingEnabled }) => {
35
- const source = typeof ssoLink === 'string' ? ssoLink.trim() : '';
36
-
37
- const webviewRef = useRef(null);
38
- const videoCallRef = useRef(null);
39
-
40
- const runBeforeFirst = `
41
- window.isNativeApp = true;
42
- window.platform = "IOS";
43
- window.setSdkPlatform('IOS');
44
- true; // note: this is required, or you'll sometimes get silent failures
45
- `;
46
-
47
- const startVideoConsultation = useCallback(
48
- (payload) => {
49
- const roomName = payload?.roomName;
50
- const accessToken = payload?.token;
51
- const rawDoctorName = payload?.doctorName;
52
- const visibleDoctorName =
53
- rawDoctorName && rawDoctorName.indexOf('Dr.') > -1
54
- ? rawDoctorName.replace('Dr. ', '')
55
- : rawDoctorName && rawDoctorName.indexOf('Dr') > -1
56
- ? rawDoctorName.replace('Dr ', '')
57
- : null;
58
- const userName = payload?.userName;
59
-
60
- if (!roomName || !accessToken) {
61
- if (isLoggingEnabled) {
62
- console.warn('Video call payload missing roomName/accessToken.');
63
- }
64
- return;
65
- }
66
-
67
- videoCallRef.current?.startVideoCall({
68
- roomName,
69
- accessToken,
70
- doctorName: rawDoctorName ?? '',
71
- visibleDoctorName: visibleDoctorName ?? '',
72
- userName,
73
- });
74
- },
75
- [isLoggingEnabled]
76
- );
77
-
78
- const handleMessage = async (event) => {
79
- const data = JSON.parse(unescapeHTML(event.nativeEvent.data));
80
- const { method, url } = data;
81
- console.log('handleMessage data is', data);
82
- console.log(unescapeHTML(event.nativeEvent.data));
83
- switch (method) {
84
- case 'startVideoCall':
85
- startVideoConsultation(data);
86
- break;
87
- case 'UPDATE_PLATFORM':
88
- webviewRef.current?.injectJavaScript('window.setSdkPlatform("IOS")');
89
- break;
90
-
91
- case 'OPEN_PDF':
92
- Linking.openURL(url);
93
- break;
94
- case 'OPEN_FACE_SCAN_FLOW':
95
- EventRegister.emitEvent('visit-event', {
96
- message: 'OPEN_FACE_SCAN_FLOW',
97
- });
98
- break;
99
- case 'CLOSE_VIEW':
100
- break;
101
- case 'GET_LOCATION_PERMISSIONS':
102
- webviewRef.current?.injectJavaScript(
103
- 'window.checkTheGpsPermission(true)'
104
- );
105
- break;
106
-
107
- default:
108
- break;
109
- }
110
- };
111
-
112
- const { height, width } = Dimensions.get('screen');
113
- return (
114
- // eslint-disable-next-line react-native/no-inline-styles
115
- <SafeAreaView style={{ flex: 1, backgroundColor: 'white', height, width }}>
116
- {source ? (
117
- <WebView
118
- ref={webviewRef}
119
- source={{ uri: source }}
120
- style={styles.webView}
121
- javascriptEnabled
122
- onMessage={handleMessage}
123
- injectedJavaScriptBeforeContentLoaded={runBeforeFirst}
124
- onError={(errorMessage) => {
125
- EventRegister.emitEvent(visitEvent, {
126
- message: 'web-view-error',
127
- errorMessage: errorMessage,
128
- });
129
- if (isLoggingEnabled) {
130
- console.warn('Webview error: ', errorMessage);
131
- }
132
- }}
133
- />
134
- ) : null}
135
- <VideoCallComponent
136
- ref={videoCallRef}
137
- onCallConnected={(info) => {
138
- if (isLoggingEnabled) {
139
- console.log('Video call connected:', info);
140
- }
141
- }}
142
- onCallEnded={(info) => {
143
- if (isLoggingEnabled) {
144
- console.log('Video call ended:', info);
145
- }
146
- }}
147
- onError={(error) => {
148
- if (isLoggingEnabled) {
149
- console.error('Video call error:', error);
150
- }
151
- }}
152
- />
153
- </SafeAreaView>
154
- );
155
- };
156
-
157
- const styles = StyleSheet.create({
158
- webView: {
159
- flex: 1,
160
- },
161
- });
162
-
163
- VisitRnSdkView.defaultProps = {
164
- ssoLink: '',
165
- isLoggingEnabled: false,
166
- };
167
-
168
- export default VisitRnSdkView;