react-native-visit-rn-sdk 6.0.2 → 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 (45) hide show
  1. package/README.md +45 -14
  2. package/lib/commonjs/components/VideoCallComponent.js +11 -16
  3. package/lib/commonjs/components/VideoCallComponent.js.map +1 -1
  4. package/lib/commonjs/index.android.js +43 -13
  5. package/lib/commonjs/index.android.js.map +1 -1
  6. package/lib/commonjs/index.ios.js +73 -37
  7. package/lib/commonjs/index.ios.js.map +1 -1
  8. package/lib/commonjs/index.js +6 -0
  9. package/lib/commonjs/index.js.map +1 -0
  10. package/lib/commonjs/shims.d.js +2 -0
  11. package/lib/commonjs/shims.d.js.map +1 -0
  12. package/lib/commonjs/types.js +2 -0
  13. package/lib/commonjs/types.js.map +1 -0
  14. package/lib/module/components/VideoCallComponent.js +11 -16
  15. package/lib/module/components/VideoCallComponent.js.map +1 -1
  16. package/lib/module/index.android.js +44 -14
  17. package/lib/module/index.android.js.map +1 -1
  18. package/lib/module/index.ios.js +74 -38
  19. package/lib/module/index.ios.js.map +1 -1
  20. package/lib/module/index.js +2 -0
  21. package/lib/module/index.js.map +1 -0
  22. package/lib/module/shims.d.js +2 -0
  23. package/lib/module/shims.d.js.map +1 -0
  24. package/lib/module/types.js +2 -0
  25. package/lib/module/types.js.map +1 -0
  26. package/lib/typescript/components/VideoCallComponent.d.ts +77 -2
  27. package/lib/typescript/components/VideoCallComponent.d.ts.map +1 -1
  28. package/lib/typescript/index.android.d.ts +3 -11
  29. package/lib/typescript/index.android.d.ts.map +1 -1
  30. package/lib/typescript/index.d.ts +17 -0
  31. package/lib/typescript/index.d.ts.map +1 -0
  32. package/lib/typescript/index.ios.d.ts +3 -11
  33. package/lib/typescript/index.ios.d.ts.map +1 -1
  34. package/lib/typescript/types.d.ts +24 -0
  35. package/lib/typescript/types.d.ts.map +1 -0
  36. package/package.json +11 -7
  37. package/src/components/VideoCallComponent.tsx +1484 -0
  38. package/src/index.android.tsx +459 -0
  39. package/src/index.ios.tsx +238 -0
  40. package/src/index.tsx +25 -0
  41. package/src/shims.d.ts +49 -0
  42. package/src/types.ts +25 -0
  43. package/src/components/VideoCallComponent.js +0 -1305
  44. package/src/index.android.js +0 -362
  45. package/src/index.ios.js +0 -157
@@ -1,362 +0,0 @@
1
- import React, { useRef, useEffect, useState, useCallback } from 'react';
2
- import {
3
- Alert,
4
- AppState,
5
- BackHandler,
6
- Linking,
7
- NativeModules,
8
- SafeAreaView,
9
- } from 'react-native';
10
- import {
11
- check,
12
- openSettings,
13
- PERMISSIONS,
14
- request,
15
- RESULTS,
16
- } from 'react-native-permissions';
17
- import WebView from 'react-native-webview';
18
-
19
- import VideoCallComponent from './components/VideoCallComponent';
20
-
21
- const LOCATION_SOURCE_SETTINGS = 'android.settings.LOCATION_SOURCE_SETTINGS';
22
- const GENERAL_SETTINGS = 'android.settings.SETTINGS';
23
- const { VisitRnSdkLocation } = NativeModules;
24
-
25
- const VisitRnSdkView = ({ ssoLink, isLoggingEnabled }) => {
26
- const source = typeof ssoLink === 'string' ? ssoLink.trim() : '';
27
- const webviewRef = useRef(null);
28
- const videoCallRef = useRef(null);
29
- const locationFlowInProgressRef = useRef(false);
30
- const pendingSettingsRef = useRef(null);
31
- const appStateRef = useRef(AppState.currentState);
32
- const [canGoBack, setCanGoBack] = useState(false);
33
-
34
- const warn = useCallback(
35
- (message, error) => {
36
- if (isLoggingEnabled) {
37
- console.warn(message, error);
38
- }
39
- },
40
- [isLoggingEnabled]
41
- );
42
-
43
- const finishLocationFlow = useCallback((granted) => {
44
- locationFlowInProgressRef.current = false;
45
- pendingSettingsRef.current = null;
46
- webviewRef.current?.injectJavaScript(
47
- `window.checkTheGpsPermission(${granted}); true;`
48
- );
49
- }, []);
50
-
51
- const showLocationPermissionSettingsAlert = useCallback(() => {
52
- Alert.alert(
53
- 'Location permission required',
54
- 'Allow location access in app settings to continue.',
55
- [
56
- {
57
- text: 'Cancel',
58
- style: 'cancel',
59
- onPress: () => finishLocationFlow(false),
60
- },
61
- {
62
- text: 'Open Settings',
63
- onPress: async () => {
64
- pendingSettingsRef.current = 'location-permission';
65
- try {
66
- await openSettings();
67
- } catch (error) {
68
- warn('Unable to open application settings.', error);
69
- finishLocationFlow(false);
70
- }
71
- },
72
- },
73
- ],
74
- { cancelable: false }
75
- );
76
- }, [finishLocationFlow, warn]);
77
-
78
- const openLocationServicesSettings = useCallback(async () => {
79
- pendingSettingsRef.current = 'location-services';
80
- try {
81
- await Linking.sendIntent(LOCATION_SOURCE_SETTINGS);
82
- } catch (locationSettingsError) {
83
- warn(
84
- 'Unable to open Location Services settings; opening general settings.',
85
- locationSettingsError
86
- );
87
- try {
88
- await Linking.sendIntent(GENERAL_SETTINGS);
89
- } catch (generalSettingsError) {
90
- warn('Unable to open Android settings.', generalSettingsError);
91
- finishLocationFlow(false);
92
- }
93
- }
94
- }, [finishLocationFlow, warn]);
95
-
96
- const checkLocationServices = useCallback(
97
- async ({ promptIfDisabled }) => {
98
- try {
99
- if (!VisitRnSdkLocation?.isLocationServicesEnabled) {
100
- throw new Error('VisitRnSdkLocation native module is unavailable.');
101
- }
102
-
103
- const isEnabled = await VisitRnSdkLocation.isLocationServicesEnabled();
104
- if (isEnabled) {
105
- finishLocationFlow(true);
106
- return;
107
- }
108
-
109
- if (!promptIfDisabled) {
110
- finishLocationFlow(false);
111
- return;
112
- }
113
-
114
- Alert.alert(
115
- 'Turn on Location Services',
116
- 'Enable Location Services in phone settings to continue.',
117
- [
118
- {
119
- text: 'Cancel',
120
- style: 'cancel',
121
- onPress: () => finishLocationFlow(false),
122
- },
123
- {
124
- text: 'Open Settings',
125
- onPress: openLocationServicesSettings,
126
- },
127
- ],
128
- { cancelable: false }
129
- );
130
- } catch (error) {
131
- warn('Unable to check Location Services.', error);
132
- finishLocationFlow(false);
133
- }
134
- },
135
- [finishLocationFlow, openLocationServicesSettings, warn]
136
- );
137
-
138
- const requestLocationPermission = useCallback(async () => {
139
- if (
140
- locationFlowInProgressRef.current ||
141
- pendingSettingsRef.current !== null
142
- ) {
143
- return;
144
- }
145
-
146
- locationFlowInProgressRef.current = true;
147
-
148
- try {
149
- let permissionStatus = await check(
150
- PERMISSIONS.ANDROID.ACCESS_FINE_LOCATION
151
- );
152
-
153
- if (permissionStatus === RESULTS.DENIED) {
154
- permissionStatus = await request(
155
- PERMISSIONS.ANDROID.ACCESS_FINE_LOCATION
156
- );
157
- }
158
-
159
- if (permissionStatus === RESULTS.GRANTED) {
160
- await checkLocationServices({ promptIfDisabled: true });
161
- return;
162
- }
163
-
164
- if (permissionStatus === RESULTS.BLOCKED) {
165
- showLocationPermissionSettingsAlert();
166
- return;
167
- }
168
-
169
- finishLocationFlow(false);
170
- } catch (error) {
171
- warn('Unable to check or request location permission.', error);
172
- finishLocationFlow(false);
173
- }
174
- }, [
175
- checkLocationServices,
176
- finishLocationFlow,
177
- showLocationPermissionSettingsAlert,
178
- warn,
179
- ]);
180
-
181
- const recheckAfterSettings = useCallback(async () => {
182
- const settingsType = pendingSettingsRef.current;
183
- if (!settingsType) {
184
- return;
185
- }
186
-
187
- pendingSettingsRef.current = null;
188
-
189
- try {
190
- const permissionStatus = await check(
191
- PERMISSIONS.ANDROID.ACCESS_FINE_LOCATION
192
- );
193
- if (permissionStatus !== RESULTS.GRANTED) {
194
- finishLocationFlow(false);
195
- return;
196
- }
197
-
198
- await checkLocationServices({
199
- promptIfDisabled: settingsType === 'location-permission',
200
- });
201
- } catch (error) {
202
- warn('Unable to recheck location access after settings.', error);
203
- finishLocationFlow(false);
204
- }
205
- }, [checkLocationServices, finishLocationFlow, warn]);
206
-
207
- const runBeforeFirst = `
208
- window.isNativeApp = true;
209
- window.platform = "ANDROID";
210
- window.setSdkPlatform('ANDROID');
211
- true; // note: this is required, or you'll sometimes get silent failures
212
- `;
213
-
214
- const startVideoConsultation = useCallback(
215
- (parsedObject) => {
216
- const roomName = parsedObject?.roomName;
217
- const accessToken = parsedObject?.token;
218
- const rawDoctorName = parsedObject?.doctorName;
219
- const visibleDoctorName =
220
- rawDoctorName && rawDoctorName.indexOf('Dr.') > -1
221
- ? rawDoctorName.replace('Dr. ', '')
222
- : rawDoctorName && rawDoctorName.indexOf('Dr') > -1
223
- ? rawDoctorName.replace('Dr ', '')
224
- : null;
225
- const userName = parsedObject?.userName;
226
-
227
- if (!roomName || !accessToken) {
228
- if (isLoggingEnabled) {
229
- console.warn('Video call payload missing roomName/accessToken.');
230
- }
231
- return;
232
- }
233
-
234
- videoCallRef.current?.startVideoCall({
235
- roomName,
236
- accessToken,
237
- doctorName: rawDoctorName ?? '',
238
- visibleDoctorName: visibleDoctorName ?? '',
239
- userName,
240
- });
241
- },
242
- [isLoggingEnabled]
243
- );
244
-
245
- const handleMessage = (event) => {
246
- if (event.nativeEvent.data != null) {
247
- try {
248
- const parsedObject = JSON.parse(event.nativeEvent.data);
249
- if (isLoggingEnabled) {
250
- console.log('Received WebView method:', parsedObject.method);
251
- }
252
- if (parsedObject.method != null) {
253
- switch (parsedObject.method) {
254
- case 'startVideoCall':
255
- startVideoConsultation(parsedObject);
256
- break;
257
- case 'UPDATE_PLATFORM':
258
- webviewRef.current?.injectJavaScript(
259
- 'window.setSdkPlatform("ANDROID")'
260
- );
261
- break;
262
- case 'GET_LOCATION_PERMISSIONS':
263
- requestLocationPermission();
264
- break;
265
- case 'OPEN_PDF':
266
- Linking.openURL(parsedObject.url);
267
- break;
268
- case 'CLOSE_VIEW':
269
- break;
270
- default:
271
- break;
272
- }
273
- }
274
- } catch (error) {
275
- warn('Unable to handle WebView message.', error);
276
- }
277
- }
278
- };
279
-
280
- const handleBack = useCallback(() => {
281
- if (canGoBack && webviewRef.current) {
282
- webviewRef.current.goBack();
283
- return true;
284
- }
285
- return false;
286
- }, [canGoBack]);
287
-
288
- useEffect(() => {
289
- const backSub = BackHandler.addEventListener(
290
- 'hardwareBackPress',
291
- handleBack
292
- );
293
- const appStateSub = AppState.addEventListener('change', (nextAppState) => {
294
- const wasInBackground = /inactive|background/.test(appStateRef.current);
295
- appStateRef.current = nextAppState;
296
-
297
- if (
298
- wasInBackground &&
299
- nextAppState === 'active' &&
300
- pendingSettingsRef.current
301
- ) {
302
- recheckAfterSettings();
303
- }
304
- });
305
-
306
- return () => {
307
- backSub?.remove();
308
- appStateSub?.remove();
309
- };
310
- }, [handleBack, recheckAfterSettings]);
311
-
312
- return (
313
- // eslint-disable-next-line react-native/no-inline-styles
314
- <SafeAreaView style={{ flex: 1 }}>
315
- {source ? (
316
- <WebView
317
- ref={webviewRef}
318
- source={{
319
- uri: source,
320
- headers: {
321
- platform: 'ANDROID',
322
- },
323
- }}
324
- onMessage={handleMessage}
325
- injectedJavaScriptBeforeContentLoaded={runBeforeFirst}
326
- javaScriptEnabled={true}
327
- onLoadProgress={(event) => setCanGoBack(event.nativeEvent.canGoBack)}
328
- onError={(errorMessage) => {
329
- if (isLoggingEnabled) {
330
- console.warn('Webview error: ', errorMessage);
331
- }
332
- }}
333
- />
334
- ) : null}
335
- <VideoCallComponent
336
- ref={videoCallRef}
337
- onCallConnected={(info) => {
338
- if (isLoggingEnabled) {
339
- console.log('Video call connected:', info);
340
- }
341
- }}
342
- onCallEnded={(info) => {
343
- if (isLoggingEnabled) {
344
- console.log('Video call ended:', info);
345
- }
346
- }}
347
- onError={(error) => {
348
- if (isLoggingEnabled) {
349
- console.error('Video call error:', error);
350
- }
351
- }}
352
- />
353
- </SafeAreaView>
354
- );
355
- };
356
-
357
- export default VisitRnSdkView;
358
-
359
- VisitRnSdkView.defaultProps = {
360
- ssoLink: '',
361
- isLoggingEnabled: false,
362
- };
package/src/index.ios.js DELETED
@@ -1,157 +0,0 @@
1
- import React, { useRef, useCallback } from 'react';
2
- import { StyleSheet, SafeAreaView, Linking, Dimensions } from 'react-native';
3
- import { WebView } from 'react-native-webview';
4
- import VideoCallComponent from './components/VideoCallComponent';
5
-
6
- const escapeChars = {
7
- lt: '<',
8
- gt: '>',
9
- quot: '"',
10
- apos: "'",
11
- amp: '&',
12
- };
13
-
14
- const unescapeHTML = (str) =>
15
- // modified from underscore.string and string.js
16
- // eslint-disable-next-line no-useless-escape
17
- str.replace(/\&([^;]+);/g, (entity, entityCode) => {
18
- let match;
19
-
20
- if (entityCode in escapeChars) {
21
- return escapeChars[entityCode];
22
- } else if ((match = entityCode.match(/^#x([\da-fA-F]+)$/))) {
23
- return String.fromCharCode(parseInt(match[1], 16));
24
- } else if ((match = entityCode.match(/^#(\d+)$/))) {
25
- return String.fromCharCode(match[1]);
26
- } else {
27
- return entity;
28
- }
29
- });
30
-
31
- const VisitRnSdkView = ({ ssoLink, isLoggingEnabled }) => {
32
- const source = typeof ssoLink === 'string' ? ssoLink.trim() : '';
33
-
34
- const webviewRef = useRef(null);
35
- const videoCallRef = useRef(null);
36
-
37
- const runBeforeFirst = `
38
- window.isNativeApp = true;
39
- window.platform = "IOS";
40
- window.setSdkPlatform('IOS');
41
- true; // note: this is required, or you'll sometimes get silent failures
42
- `;
43
-
44
- const startVideoConsultation = useCallback(
45
- (payload) => {
46
- const roomName = payload?.roomName;
47
- const accessToken = payload?.token;
48
- const rawDoctorName = payload?.doctorName;
49
- const visibleDoctorName =
50
- rawDoctorName && rawDoctorName.indexOf('Dr.') > -1
51
- ? rawDoctorName.replace('Dr. ', '')
52
- : rawDoctorName && rawDoctorName.indexOf('Dr') > -1
53
- ? rawDoctorName.replace('Dr ', '')
54
- : null;
55
- const userName = payload?.userName;
56
-
57
- if (!roomName || !accessToken) {
58
- if (isLoggingEnabled) {
59
- console.warn('Video call payload missing roomName/accessToken.');
60
- }
61
- return;
62
- }
63
-
64
- videoCallRef.current?.startVideoCall({
65
- roomName,
66
- accessToken,
67
- doctorName: rawDoctorName ?? '',
68
- visibleDoctorName: visibleDoctorName ?? '',
69
- userName,
70
- });
71
- },
72
- [isLoggingEnabled]
73
- );
74
-
75
- const handleMessage = (event) => {
76
- const data = JSON.parse(unescapeHTML(event.nativeEvent.data));
77
- const { method, url } = data;
78
- if (isLoggingEnabled) {
79
- console.log('Received WebView method:', method);
80
- }
81
- switch (method) {
82
- case 'startVideoCall':
83
- startVideoConsultation(data);
84
- break;
85
- case 'UPDATE_PLATFORM':
86
- webviewRef.current?.injectJavaScript('window.setSdkPlatform("IOS")');
87
- break;
88
-
89
- case 'OPEN_PDF':
90
- Linking.openURL(url);
91
- break;
92
- case 'CLOSE_VIEW':
93
- break;
94
- case 'GET_LOCATION_PERMISSIONS':
95
- webviewRef.current?.injectJavaScript(
96
- 'window.checkTheGpsPermission(true)'
97
- );
98
- break;
99
-
100
- default:
101
- break;
102
- }
103
- };
104
-
105
- const { height, width } = Dimensions.get('screen');
106
- return (
107
- // eslint-disable-next-line react-native/no-inline-styles
108
- <SafeAreaView style={{ flex: 1, backgroundColor: 'white', height, width }}>
109
- {source ? (
110
- <WebView
111
- ref={webviewRef}
112
- source={{ uri: source }}
113
- style={styles.webView}
114
- javascriptEnabled
115
- onMessage={handleMessage}
116
- injectedJavaScriptBeforeContentLoaded={runBeforeFirst}
117
- onError={(errorMessage) => {
118
- if (isLoggingEnabled) {
119
- console.warn('Webview error: ', errorMessage);
120
- }
121
- }}
122
- />
123
- ) : null}
124
- <VideoCallComponent
125
- ref={videoCallRef}
126
- onCallConnected={(info) => {
127
- if (isLoggingEnabled) {
128
- console.log('Video call connected:', info);
129
- }
130
- }}
131
- onCallEnded={(info) => {
132
- if (isLoggingEnabled) {
133
- console.log('Video call ended:', info);
134
- }
135
- }}
136
- onError={(error) => {
137
- if (isLoggingEnabled) {
138
- console.error('Video call error:', error);
139
- }
140
- }}
141
- />
142
- </SafeAreaView>
143
- );
144
- };
145
-
146
- const styles = StyleSheet.create({
147
- webView: {
148
- flex: 1,
149
- },
150
- });
151
-
152
- VisitRnSdkView.defaultProps = {
153
- ssoLink: '',
154
- isLoggingEnabled: false,
155
- };
156
-
157
- export default VisitRnSdkView;