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.6KB

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