選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

LargeVideo.native.tsx 8.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. import React, { PureComponent } from 'react';
  2. import { connect } from 'react-redux';
  3. import { IReduxState, IStore } from '../../app/types';
  4. import { JitsiTrackEvents } from '../../base/lib-jitsi-meet';
  5. import ParticipantView from '../../base/participants/components/ParticipantView.native';
  6. import { getParticipantById, isLocalScreenshareParticipant } from '../../base/participants/functions';
  7. import { trackStreamingStatusChanged } from '../../base/tracks/actions.native';
  8. import { getVideoTrackByParticipant, isLocalVideoTrackDesktop } from '../../base/tracks/functions.native';
  9. import { ITrack } from '../../base/tracks/types';
  10. import { AVATAR_SIZE } from './styles';
  11. /**
  12. * The type of the React {@link Component} props of {@link LargeVideo}.
  13. */
  14. interface IProps {
  15. /**
  16. * Whether video should be disabled.
  17. */
  18. _disableVideo: boolean;
  19. /**
  20. * Application's viewport height.
  21. */
  22. _height: number;
  23. /**
  24. * The ID of the participant (to be) depicted by LargeVideo.
  25. *
  26. * @private
  27. */
  28. _participantId: string;
  29. /**
  30. * The video track that will be displayed in the thumbnail.
  31. */
  32. _videoTrack?: ITrack;
  33. /**
  34. * Application's viewport height.
  35. */
  36. _width: number;
  37. /**
  38. * Invoked to trigger state changes in Redux.
  39. */
  40. dispatch: IStore['dispatch'];
  41. /**
  42. * Callback to invoke when the {@code LargeVideo} is clicked/pressed.
  43. */
  44. onClick?: Function;
  45. }
  46. /**
  47. * The type of the React {@link Component} state of {@link LargeVideo}.
  48. */
  49. interface IState {
  50. /**
  51. * Size for the Avatar. It will be dynamically adjusted based on the
  52. * available size.
  53. */
  54. avatarSize: number;
  55. /**
  56. * Whether the connectivity indicator will be shown or not. It will be true
  57. * by default, but it may be turned off if there is not enough space.
  58. */
  59. useConnectivityInfoLabel: boolean;
  60. }
  61. const DEFAULT_STATE = {
  62. avatarSize: AVATAR_SIZE,
  63. useConnectivityInfoLabel: true
  64. };
  65. /** .
  66. * Implements a React {@link Component} which represents the large video (a.k.a.
  67. * The conference participant who is on the local stage) on mobile/React Native.
  68. *
  69. * @augments Component
  70. */
  71. class LargeVideo extends PureComponent<IProps, IState> {
  72. /**
  73. * Creates new LargeVideo component.
  74. *
  75. * @param {IProps} props - The props of the component.
  76. * @returns {LargeVideo}
  77. */
  78. constructor(props: IProps) {
  79. super(props);
  80. this.handleTrackStreamingStatusChanged = this.handleTrackStreamingStatusChanged.bind(this);
  81. }
  82. state = {
  83. ...DEFAULT_STATE
  84. };
  85. /**
  86. * Handles dimension changes. In case we deem it's too
  87. * small, the connectivity indicator won't be rendered and the avatar
  88. * will occupy the entirety of the available screen state.
  89. *
  90. * @inheritdoc
  91. */
  92. static getDerivedStateFromProps(props: IProps) {
  93. const { _height, _width } = props;
  94. // Get the size, rounded to the nearest even number.
  95. const size = 2 * Math.round(Math.min(_height, _width) / 2);
  96. if (size < AVATAR_SIZE * 1.5) {
  97. return {
  98. avatarSize: size - 15, // Leave some margin.
  99. useConnectivityInfoLabel: false
  100. };
  101. }
  102. return DEFAULT_STATE;
  103. }
  104. /**
  105. * Starts listening for track streaming status updates after the initial render.
  106. *
  107. * @inheritdoc
  108. * @returns {void}
  109. */
  110. componentDidMount() {
  111. // Listen to track streaming status changed event to keep it updated.
  112. // TODO: after converting this component to a react function component,
  113. // use a custom hook to update local track streaming status.
  114. const { _videoTrack, dispatch } = this.props;
  115. if (_videoTrack && !_videoTrack.local) {
  116. _videoTrack.jitsiTrack.on(JitsiTrackEvents.TRACK_STREAMING_STATUS_CHANGED,
  117. this.handleTrackStreamingStatusChanged);
  118. dispatch(trackStreamingStatusChanged(_videoTrack.jitsiTrack,
  119. _videoTrack.jitsiTrack.getTrackStreamingStatus()));
  120. }
  121. }
  122. /**
  123. * Stops listening for track streaming status updates on the old track and starts listening instead on the new
  124. * track.
  125. *
  126. * @inheritdoc
  127. * @returns {void}
  128. */
  129. componentDidUpdate(prevProps: IProps) {
  130. // TODO: after converting this component to a react function component,
  131. // use a custom hook to update local track streaming status.
  132. const { _videoTrack, dispatch } = this.props;
  133. if (prevProps._videoTrack?.jitsiTrack?.getSourceName() !== _videoTrack?.jitsiTrack?.getSourceName()) {
  134. if (prevProps._videoTrack && !prevProps._videoTrack.local) {
  135. prevProps._videoTrack.jitsiTrack.off(JitsiTrackEvents.TRACK_STREAMING_STATUS_CHANGED,
  136. this.handleTrackStreamingStatusChanged);
  137. dispatch(trackStreamingStatusChanged(prevProps._videoTrack.jitsiTrack,
  138. prevProps._videoTrack.jitsiTrack.getTrackStreamingStatus()));
  139. }
  140. if (_videoTrack && !_videoTrack.local) {
  141. _videoTrack.jitsiTrack.on(JitsiTrackEvents.TRACK_STREAMING_STATUS_CHANGED,
  142. this.handleTrackStreamingStatusChanged);
  143. dispatch(trackStreamingStatusChanged(_videoTrack.jitsiTrack,
  144. _videoTrack.jitsiTrack.getTrackStreamingStatus()));
  145. }
  146. }
  147. }
  148. /**
  149. * Remove listeners for track streaming status update.
  150. *
  151. * @inheritdoc
  152. * @returns {void}
  153. */
  154. componentWillUnmount() {
  155. // TODO: after converting this component to a react function component,
  156. // use a custom hook to update local track streaming status.
  157. const { _videoTrack, dispatch } = this.props;
  158. if (_videoTrack && !_videoTrack.local) {
  159. _videoTrack.jitsiTrack.off(JitsiTrackEvents.TRACK_STREAMING_STATUS_CHANGED,
  160. this.handleTrackStreamingStatusChanged);
  161. dispatch(trackStreamingStatusChanged(_videoTrack.jitsiTrack,
  162. _videoTrack.jitsiTrack.getTrackStreamingStatus()));
  163. }
  164. }
  165. /**
  166. * Handle track streaming status change event by by dispatching an action to update track streaming status for the
  167. * given track in app state.
  168. *
  169. * @param {JitsiTrack} jitsiTrack - The track with streaming status updated.
  170. * @param {JitsiTrackStreamingStatus} streamingStatus - The updated track streaming status.
  171. * @returns {void}
  172. */
  173. handleTrackStreamingStatusChanged(jitsiTrack: any, streamingStatus: string) {
  174. this.props.dispatch(trackStreamingStatusChanged(jitsiTrack, streamingStatus));
  175. }
  176. /**
  177. * Implements React's {@link Component#render()}.
  178. *
  179. * @inheritdoc
  180. * @returns {ReactElement}
  181. */
  182. render() {
  183. const {
  184. avatarSize,
  185. useConnectivityInfoLabel
  186. } = this.state;
  187. const {
  188. _disableVideo,
  189. _participantId,
  190. onClick
  191. } = this.props;
  192. return (
  193. <ParticipantView
  194. avatarSize = { avatarSize }
  195. disableVideo = { _disableVideo }
  196. onPress = { onClick }
  197. participantId = { _participantId }
  198. testHintId = 'org.jitsi.meet.LargeVideo'
  199. useConnectivityInfoLabel = { useConnectivityInfoLabel }
  200. zOrder = { 0 }
  201. zoomEnabled = { true } />
  202. );
  203. }
  204. }
  205. /**
  206. * Maps (parts of) the Redux state to the associated LargeVideo's props.
  207. *
  208. * @param {Object} state - Redux state.
  209. * @private
  210. * @returns {IProps}
  211. */
  212. function _mapStateToProps(state: IReduxState) {
  213. const { participantId } = state['features/large-video'];
  214. const participant = getParticipantById(state, participantId ?? '');
  215. const { clientHeight: height, clientWidth: width } = state['features/base/responsive-ui'];
  216. const videoTrack = getVideoTrackByParticipant(state, participant);
  217. let disableVideo = false;
  218. if (isLocalScreenshareParticipant(participant)) {
  219. disableVideo = true;
  220. } else if (participant?.local) {
  221. disableVideo = isLocalVideoTrackDesktop(state);
  222. }
  223. return {
  224. _disableVideo: disableVideo,
  225. _height: height,
  226. _participantId: participantId ?? '',
  227. _videoTrack: videoTrack,
  228. _width: width
  229. };
  230. }
  231. export default connect(_mapStateToProps)(LargeVideo);