Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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, {
  5. forwardRef,
  6. useEffect,
  7. useImperativeHandle,
  8. useLayoutEffect,
  9. useRef,
  10. useState
  11. } from 'react';
  12. import { View, ViewStyle } from 'react-native';
  13. import { appNavigate } from './react/features/app/actions.native';
  14. import { App } from './react/features/app/components/App.native';
  15. import { setAudioMuted, setVideoMuted } from './react/features/base/media/actions';
  16. interface IEventListeners {
  17. onConferenceBlurred?: Function;
  18. onConferenceFocused?: Function;
  19. onConferenceJoined?: Function;
  20. onConferenceLeft?: Function;
  21. onConferenceWillJoin?: Function;
  22. onEnterPictureInPicture?: Function;
  23. onParticipantJoined?: Function;
  24. onReadyToClose?: Function;
  25. }
  26. interface IUserInfo {
  27. avatarURL: string;
  28. displayName: string;
  29. email: string;
  30. }
  31. interface IAppProps {
  32. config: object;
  33. eventListeners?: IEventListeners;
  34. flags?: object;
  35. room: string;
  36. serverURL?: string;
  37. style?: Object;
  38. token?: string;
  39. userInfo?: IUserInfo;
  40. }
  41. /**
  42. * Main React Native SDK component that displays a Jitsi Meet conference and gets all required params as props
  43. */
  44. export const JitsiMeeting = forwardRef((props: IAppProps, ref) => {
  45. const [ appProps, setAppProps ] = useState({});
  46. const app = useRef(null);
  47. const {
  48. config,
  49. eventListeners,
  50. flags,
  51. room,
  52. serverURL,
  53. style,
  54. token,
  55. userInfo
  56. } = props;
  57. // eslint-disable-next-line arrow-body-style
  58. useImperativeHandle(ref, () => ({
  59. close: () => {
  60. const dispatch = app.current.state.store.dispatch;
  61. dispatch(appNavigate(undefined));
  62. },
  63. setAudioMuted: muted => {
  64. const dispatch = app.current.state.store.dispatch;
  65. dispatch(setAudioMuted(muted));
  66. },
  67. setVideoMuted: muted => {
  68. const dispatch = app.current.state.store.dispatch;
  69. dispatch(setVideoMuted(muted));
  70. }
  71. }));
  72. useEffect(
  73. () => {
  74. const urlObj = {
  75. config,
  76. jwt: token
  77. };
  78. let urlProps;
  79. if (room.includes('://')) {
  80. urlProps = {
  81. ...urlObj,
  82. url: room
  83. };
  84. } else {
  85. urlProps = {
  86. ...urlObj,
  87. room,
  88. serverURL
  89. };
  90. }
  91. setAppProps({
  92. 'flags': flags,
  93. 'rnSdkHandlers': {
  94. onConferenceBlurred: eventListeners?.onConferenceBlurred,
  95. onConferenceFocused: eventListeners?.onConferenceFocused,
  96. onConferenceJoined: eventListeners?.onConferenceJoined,
  97. onConferenceWillJoin: eventListeners?.onConferenceWillJoin,
  98. onConferenceLeft: eventListeners?.onConferenceLeft,
  99. onEnterPictureInPicture: eventListeners?.onEnterPictureInPicture,
  100. onParticipantJoined: eventListeners?.onParticipantJoined,
  101. onReadyToClose: eventListeners?.onReadyToClose
  102. },
  103. 'url': urlProps,
  104. 'userInfo': userInfo
  105. });
  106. }, []
  107. );
  108. // eslint-disable-next-line arrow-body-style
  109. useLayoutEffect(() => {
  110. /**
  111. * When you close the component you need to reset it.
  112. * In some cases it needs to be added as the parent component may have been destroyed.
  113. * Without this change the call remains active without having the jitsi screen.
  114. */
  115. return () => {
  116. const dispatch = app.current?.state?.store?.dispatch;
  117. dispatch && dispatch(appNavigate(undefined));
  118. };
  119. }, []);
  120. return (
  121. <View style = { style as ViewStyle }>
  122. <App
  123. { ...appProps }
  124. ref = { app } />
  125. </View>
  126. );
  127. });