react-native-visit-rn-sdk 6.0.2 → 6.0.4

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