You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /* eslint-disable lines-around-comment, no-undef, no-unused-vars */
  2. // NB: This import must always come first.
  3. import './react/bootstrap.native';
  4. import React, { forwardRef, useEffect, useImperativeHandle, useRef, useState } from 'react';
  5. import { View, ViewStyle } from 'react-native';
  6. import { appNavigate } from './react/features/app/actions.native';
  7. import { App } from './react/features/app/components/App.native';
  8. import { setAudioMuted, setVideoMuted } from './react/features/base/media/actions';
  9. interface IEventListeners {
  10. onConferenceJoined?: Function;
  11. onConferenceLeft?: Function;
  12. onConferenceWillJoin?: Function;
  13. onEnterPictureInPicture?: Function;
  14. onParticipantJoined?: Function;
  15. onReadyToClose?: Function;
  16. }
  17. interface IUserInfo {
  18. avatarURL: string;
  19. displayName: string;
  20. email: string;
  21. }
  22. interface IAppProps {
  23. config: object;
  24. flags: object;
  25. eventListeners: IEventListeners;
  26. room: string;
  27. serverURL?: string;
  28. style?: Object;
  29. token?: string;
  30. userInfo?: IUserInfo;
  31. }
  32. /**
  33. * Main React Native SDK component that displays a Jitsi Meet conference and gets all required params as props
  34. */
  35. export const JitsiMeeting = forwardRef((props: IAppProps, ref) => {
  36. const [ appProps, setAppProps ] = useState({});
  37. const app = useRef(null);
  38. const {
  39. config,
  40. eventListeners,
  41. flags,
  42. room,
  43. serverURL,
  44. style,
  45. token,
  46. userInfo
  47. } = props;
  48. // eslint-disable-next-line arrow-body-style
  49. useImperativeHandle(ref, () => ({
  50. close: () => {
  51. const dispatch = app.current.state.store.dispatch;
  52. dispatch(appNavigate(undefined));
  53. },
  54. setAudioMuted: muted => {
  55. const dispatch = app.current.state.store.dispatch;
  56. dispatch(setAudioMuted(muted));
  57. },
  58. setVideoMuted: muted => {
  59. const dispatch = app.current.state.store.dispatch;
  60. dispatch(setVideoMuted(muted));
  61. }
  62. }));
  63. useEffect(
  64. () => {
  65. const urlObj = {
  66. config,
  67. jwt: token
  68. };
  69. let urlProps;
  70. if (room.includes('://')) {
  71. urlProps = {
  72. ...urlObj,
  73. url: room
  74. };
  75. } else {
  76. urlProps = {
  77. ...urlObj,
  78. room,
  79. serverURL
  80. };
  81. }
  82. setAppProps({
  83. 'flags': flags,
  84. 'rnSdkHandlers': {
  85. onConferenceJoined: eventListeners.onConferenceJoined,
  86. onConferenceWillJoin: eventListeners.onConferenceWillJoin,
  87. onConferenceLeft: eventListeners.onConferenceLeft,
  88. onEnterPictureInPicture: eventListeners.onEnterPictureInPicture,
  89. onParticipantJoined: eventListeners.onParticipantJoined,
  90. onReadyToClose: eventListeners.onReadyToClose
  91. },
  92. 'url': urlProps,
  93. 'userInfo': userInfo
  94. });
  95. }, []
  96. );
  97. return (
  98. <View style = { style as ViewStyle }>
  99. <App
  100. { ...appProps }
  101. ref = { app } />
  102. </View>
  103. );
  104. });