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

LargeVideo.native.js 8.4KB

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