react-native-visit-rn-sdk 2.0.13 → 5.0.1

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 (43) hide show
  1. package/README.md +31 -0
  2. package/android/build.gradle +1 -0
  3. package/lib/commonjs/assets/video-call/connecting-lottie.gif +0 -0
  4. package/lib/commonjs/assets/video-call/end-call.png +0 -0
  5. package/lib/commonjs/assets/video-call/mic-off.png +0 -0
  6. package/lib/commonjs/assets/video-call/reconnecting.gif +0 -0
  7. package/lib/commonjs/assets/video-call/switch-camera.png +0 -0
  8. package/lib/commonjs/assets/video-call/toggle-down.png +0 -0
  9. package/lib/commonjs/assets/video-call/toggle-up.png +0 -0
  10. package/lib/commonjs/assets/video-call/video-off.png +0 -0
  11. package/lib/commonjs/components/VideoCallComponent.js +1107 -0
  12. package/lib/commonjs/components/VideoCallComponent.js.map +1 -0
  13. package/lib/commonjs/index.android.js +44 -1
  14. package/lib/commonjs/index.android.js.map +1 -1
  15. package/lib/commonjs/index.ios.js +50 -0
  16. package/lib/commonjs/index.ios.js.map +1 -1
  17. package/lib/module/assets/video-call/connecting-lottie.gif +0 -0
  18. package/lib/module/assets/video-call/end-call.png +0 -0
  19. package/lib/module/assets/video-call/mic-off.png +0 -0
  20. package/lib/module/assets/video-call/reconnecting.gif +0 -0
  21. package/lib/module/assets/video-call/switch-camera.png +0 -0
  22. package/lib/module/assets/video-call/toggle-down.png +0 -0
  23. package/lib/module/assets/video-call/toggle-up.png +0 -0
  24. package/lib/module/assets/video-call/video-off.png +0 -0
  25. package/lib/module/components/VideoCallComponent.js +1098 -0
  26. package/lib/module/components/VideoCallComponent.js.map +1 -0
  27. package/lib/module/index.android.js +44 -1
  28. package/lib/module/index.android.js.map +1 -1
  29. package/lib/module/index.ios.js +50 -0
  30. package/lib/module/index.ios.js.map +1 -1
  31. package/package.json +3 -2
  32. package/react-native-visit-rn-sdk.podspec +0 -1
  33. package/src/assets/video-call/connecting-lottie.gif +0 -0
  34. package/src/assets/video-call/end-call.png +0 -0
  35. package/src/assets/video-call/mic-off.png +0 -0
  36. package/src/assets/video-call/reconnecting.gif +0 -0
  37. package/src/assets/video-call/switch-camera.png +0 -0
  38. package/src/assets/video-call/toggle-down.png +0 -0
  39. package/src/assets/video-call/toggle-up.png +0 -0
  40. package/src/assets/video-call/video-off.png +0 -0
  41. package/src/components/VideoCallComponent.js +1305 -0
  42. package/src/index.android.js +58 -0
  43. package/src/index.ios.js +85 -20
@@ -20,6 +20,7 @@ import LocationEnabler from 'react-native-location-enabler';
20
20
  import DeviceInfo from 'react-native-device-info';
21
21
 
22
22
  import axios from 'axios';
23
+ import VideoCallComponent from './components/VideoCallComponent';
23
24
 
24
25
  import constants from './constants';
25
26
 
@@ -277,6 +278,7 @@ const VisitRnSdkView = ({
277
278
  );
278
279
 
279
280
  const webviewRef = useRef(null);
281
+ const videoCallRef = useRef(null);
280
282
 
281
283
  const showLocationPermissionAlert = () => {
282
284
  Alert.alert(
@@ -520,6 +522,39 @@ const VisitRnSdkView = ({
520
522
  true; // note: this is required, or you'll sometimes get silent failures
521
523
  `;
522
524
 
525
+ const startVideoConsultation = useCallback(
526
+ (parsedObject) => {
527
+ const roomName = parsedObject?.roomName;
528
+ const accessToken = parsedObject?.token;
529
+ const rawDoctorName = parsedObject?.doctorName;
530
+ const visibleDoctorName =
531
+ rawDoctorName && rawDoctorName.indexOf('Dr.') > -1
532
+ ? rawDoctorName.replace('Dr. ', '')
533
+ : rawDoctorName && rawDoctorName.indexOf('Dr') > -1
534
+ ? rawDoctorName.replace('Dr ', '')
535
+ : null;
536
+ const userName = parsedObject?.userName;
537
+
538
+ if (!roomName || !accessToken) {
539
+ if (isLoggingEnabled) {
540
+ console.warn(
541
+ 'Video call payload missing roomName/accessToken.'
542
+ );
543
+ }
544
+ return;
545
+ }
546
+
547
+ videoCallRef.current?.startVideoCall({
548
+ roomName,
549
+ accessToken,
550
+ doctorName: rawDoctorName ?? '',
551
+ visibleDoctorName: visibleDoctorName ?? '',
552
+ userName,
553
+ });
554
+ },
555
+ [isLoggingEnabled]
556
+ );
557
+
523
558
  const handleMessage = (event) => {
524
559
  if (event.nativeEvent.data != null) {
525
560
  try {
@@ -534,6 +569,10 @@ const VisitRnSdkView = ({
534
569
  break;
535
570
  case 'CONNECT_TO_GOOGLE_FIT':
536
571
  askForHealthConnectPermission();
572
+
573
+ break;
574
+ case 'startVideoCall':
575
+ startVideoConsultation(parsedObject);
537
576
  break;
538
577
  case 'UPDATE_PLATFORM':
539
578
  webviewRef.current?.injectJavaScript(
@@ -699,6 +738,24 @@ const VisitRnSdkView = ({
699
738
  }}
700
739
  />
701
740
  ) : null}
741
+ <VideoCallComponent
742
+ ref={videoCallRef}
743
+ onCallConnected={(info) => {
744
+ if (isLoggingEnabled) {
745
+ console.log('Video call connected:', info);
746
+ }
747
+ }}
748
+ onCallEnded={(info) => {
749
+ if (isLoggingEnabled) {
750
+ console.log('Video call ended:', info);
751
+ }
752
+ }}
753
+ onError={(error) => {
754
+ if (isLoggingEnabled) {
755
+ console.error('Video call error:', error);
756
+ }
757
+ }}
758
+ />
702
759
  </SafeAreaView>
703
760
  );
704
761
  };
@@ -729,6 +786,7 @@ export const fetchHourlyFitnessData = (startTimeStamp, isLoggingEnabled) => {
729
786
  });
730
787
  };
731
788
 
789
+
732
790
  // debounce, deferred
733
791
  // function debounce(task, ms) {
734
792
  // let t = { promise: null, cancel: (_) => void 0 };
package/src/index.ios.js CHANGED
@@ -20,6 +20,7 @@ import { WebView } from 'react-native-webview';
20
20
  import DeviceInfo from 'react-native-device-info';
21
21
  import { getWebViewLink, httpClient } from './Services';
22
22
  import constants from './constants';
23
+ import VideoCallComponent from './components/VideoCallComponent';
23
24
 
24
25
  const LINKING_ERROR =
25
26
  `The package 'react-native-visit-rn-sdk' doesn't seem to be linked. Make sure: \n\n` +
@@ -183,10 +184,52 @@ const VisitRnSdkView = ({
183
184
  );
184
185
 
185
186
  const webviewRef = useRef(null);
187
+ const videoCallRef = useRef(null);
186
188
  const [apiBaseUrl, setApiBaseUrl] = useState('');
187
189
  const [authToken, setAuthToken] = useState('');
188
190
  const [hasLoadedOnce, setHasLoadedOnce] = useState(false);
189
191
 
192
+
193
+ const runBeforeFirst = `
194
+ window.isNativeApp = true;
195
+ window.platform = "IOS";
196
+ window.setSdkPlatform('IOS');
197
+ true; // note: this is required, or you'll sometimes get silent failures
198
+ `;
199
+
200
+ const startVideoConsultation = useCallback(
201
+ (payload) => {
202
+ const roomName = payload?.roomName;
203
+ const accessToken = payload?.token;
204
+ const rawDoctorName = payload?.doctorName;
205
+ const visibleDoctorName =
206
+ rawDoctorName && rawDoctorName.indexOf('Dr.') > -1
207
+ ? rawDoctorName.replace('Dr. ', '')
208
+ : rawDoctorName && rawDoctorName.indexOf('Dr') > -1
209
+ ? rawDoctorName.replace('Dr ', '')
210
+ : null;
211
+ const userName = payload?.userName;
212
+
213
+ if (!roomName || !accessToken) {
214
+ if (isLoggingEnabled) {
215
+ console.warn(
216
+ 'Video call payload missing roomName/accessToken.'
217
+ );
218
+ }
219
+ return;
220
+ }
221
+
222
+ videoCallRef.current?.startVideoCall({
223
+ roomName,
224
+ accessToken,
225
+ doctorName: rawDoctorName ?? '',
226
+ visibleDoctorName: visibleDoctorName ?? '',
227
+ userName,
228
+ });
229
+ },
230
+ [isLoggingEnabled]
231
+ );
232
+
190
233
  const callSyncApi = useCallback(
191
234
  (data) =>
192
235
  httpClient
@@ -248,6 +291,9 @@ const VisitRnSdkView = ({
248
291
  console.log('handleMessage data is', data);
249
292
  console.log(unescapeHTML(event.nativeEvent.data));
250
293
  switch (method) {
294
+ case 'startVideoCall':
295
+ startVideoConsultation(data);
296
+ break;
251
297
  case 'UPDATE_PLATFORM':
252
298
  webviewRef.current?.injectJavaScript('window.setSdkPlatform("IOS")');
253
299
  break;
@@ -324,26 +370,45 @@ const VisitRnSdkView = ({
324
370
  return (
325
371
  // eslint-disable-next-line react-native/no-inline-styles
326
372
  <SafeAreaView style={{ flex: 1, backgroundColor: 'white', height, width }}>
327
- {loading ? (
328
- <LoadingIndicator />
329
- ) : (
330
- <WebView
331
- ref={webviewRef}
332
- source={{ uri: source }}
333
- style={styles.webView}
334
- javascriptEnabled
335
- onMessage={handleMessage}
336
- onError={(errorMessage) => {
337
- EventRegister.emitEvent(visitEvent, {
338
- message: 'web-view-error',
339
- errorMessage: errorMessage,
340
- });
341
- if (isLoggingEnabled) {
342
- console.warn('Webview error: ', errorMessage);
343
- }
344
- }}
345
- />
346
- )}
373
+ {loading ? (
374
+ <LoadingIndicator />
375
+ ) : (
376
+ <WebView
377
+ ref={webviewRef}
378
+ source={{ uri: source }}
379
+ style={styles.webView}
380
+ javascriptEnabled
381
+ onMessage={handleMessage}
382
+ injectedJavaScriptBeforeContentLoaded={runBeforeFirst}
383
+ onError={(errorMessage) => {
384
+ EventRegister.emitEvent(visitEvent, {
385
+ message: 'web-view-error',
386
+ errorMessage: errorMessage,
387
+ });
388
+ if (isLoggingEnabled) {
389
+ console.warn('Webview error: ', errorMessage);
390
+ }
391
+ }}
392
+ />
393
+ )}
394
+ <VideoCallComponent
395
+ ref={videoCallRef}
396
+ onCallConnected={(info) => {
397
+ if (isLoggingEnabled) {
398
+ console.log('Video call connected:', info);
399
+ }
400
+ }}
401
+ onCallEnded={(info) => {
402
+ if (isLoggingEnabled) {
403
+ console.log('Video call ended:', info);
404
+ }
405
+ }}
406
+ onError={(error) => {
407
+ if (isLoggingEnabled) {
408
+ console.error('Video call error:', error);
409
+ }
410
+ }}
411
+ />
347
412
  </SafeAreaView>
348
413
  );
349
414
  };