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.

LargeVideo.native.js 8.2KB

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