Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

ParticipantView.native.tsx 9.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. import React, { Component } from 'react';
  2. import { GestureResponderEvent, Text, TextStyle, View, ViewStyle } from 'react-native';
  3. import { connect } from 'react-redux';
  4. import { IReduxState } from '../../../app/types';
  5. import {
  6. isTrackStreamingStatusActive,
  7. isTrackStreamingStatusInactive
  8. } from '../../../connection-indicator/functions';
  9. import SharedVideo from '../../../shared-video/components/native/SharedVideo';
  10. import { IStateful } from '../../app/types';
  11. import Avatar from '../../avatar/components/Avatar';
  12. import { translate } from '../../i18n/functions';
  13. import VideoTrack from '../../media/components/native/VideoTrack';
  14. import { shouldRenderVideoTrack } from '../../media/functions';
  15. import Container from '../../react/components/native/Container';
  16. import { toState } from '../../redux/functions';
  17. import { StyleType } from '../../styles/functions.any';
  18. import TestHint from '../../testing/components/TestHint';
  19. import { getVideoTrackByParticipant } from '../../tracks/functions';
  20. import { ITrack } from '../../tracks/types';
  21. import { getParticipantById, getParticipantDisplayName, isSharedVideoParticipant } from '../functions';
  22. import styles from './styles';
  23. /**
  24. * The type of the React {@link Component} props of {@link ParticipantView}.
  25. */
  26. interface IProps {
  27. /**
  28. * Whether the connection is inactive or not.
  29. *
  30. * @private
  31. */
  32. _isConnectionInactive: boolean;
  33. /**
  34. * Whether the participant is a shared video participant.
  35. */
  36. _isSharedVideoParticipant: boolean;
  37. /**
  38. * The name of the participant which this component represents.
  39. *
  40. * @private
  41. */
  42. _participantName: string;
  43. /**
  44. * True if the video should be rendered, false otherwise.
  45. */
  46. _renderVideo: boolean;
  47. /**
  48. * The video Track of the participant with {@link #participantId}.
  49. */
  50. _videoTrack?: ITrack;
  51. /**
  52. * The avatar size.
  53. */
  54. avatarSize: number;
  55. /**
  56. * Whether video should be disabled for his view.
  57. */
  58. disableVideo?: boolean;
  59. /**
  60. * Callback to invoke when the {@code ParticipantView} is clicked/pressed.
  61. */
  62. onPress: (e?: GestureResponderEvent) => void;
  63. /**
  64. * The ID of the participant (to be) depicted by {@link ParticipantView}.
  65. *
  66. * @public
  67. */
  68. participantId: string;
  69. /**
  70. * The style, if any, to apply to {@link ParticipantView} in addition to its
  71. * default style.
  72. */
  73. style: StyleType;
  74. /**
  75. * The function to translate human-readable text.
  76. */
  77. t: Function;
  78. /**
  79. * The test hint id which can be used to locate the {@code ParticipantView}
  80. * on the jitsi-meet-torture side. If not provided, the
  81. * {@code participantId} with the following format will be used:
  82. * {@code `org.jitsi.meet.Participant#${participantId}`}.
  83. */
  84. testHintId?: string;
  85. /**
  86. * Indicates if the connectivity info label should be shown, if appropriate.
  87. * It will be shown in case the connection is interrupted.
  88. */
  89. useConnectivityInfoLabel: boolean;
  90. /**
  91. * The z-order of the {@link Video} of {@link ParticipantView} in the
  92. * stacking space of all {@code Video}s. For more details, refer to the
  93. * {@code zOrder} property of the {@code Video} class for React Native.
  94. */
  95. zOrder: number;
  96. /**
  97. * Indicates whether zooming (pinch to zoom and/or drag) is enabled.
  98. */
  99. zoomEnabled: boolean;
  100. }
  101. /**
  102. * Implements a React Component which depicts a specific participant's avatar
  103. * and video.
  104. *
  105. * @augments Component
  106. */
  107. class ParticipantView extends Component<IProps> {
  108. /**
  109. * Renders the inactive connection status label.
  110. *
  111. * @private
  112. * @returns {ReactElement}
  113. */
  114. _renderInactiveConnectionInfo() {
  115. const {
  116. avatarSize,
  117. _participantName: displayName,
  118. t
  119. } = this.props;
  120. // XXX Consider splitting this component into 2: one for the large view
  121. // and one for the thumbnail. Some of these don't apply to both.
  122. const containerStyle = {
  123. ...styles.connectionInfoContainer,
  124. width: avatarSize * 1.5
  125. };
  126. return (
  127. <View
  128. pointerEvents = 'box-none'
  129. style = { containerStyle as ViewStyle }>
  130. <Text style = { styles.connectionInfoText as TextStyle }>
  131. { t('connection.LOW_BANDWIDTH', { displayName }) }
  132. </Text>
  133. </View>
  134. );
  135. }
  136. /**
  137. * Implements React's {@link Component#render()}.
  138. *
  139. * @inheritdoc
  140. * @returns {ReactElement}
  141. */
  142. render() {
  143. const {
  144. _isConnectionInactive,
  145. _isSharedVideoParticipant,
  146. _renderVideo: renderVideo,
  147. _videoTrack: videoTrack,
  148. disableVideo,
  149. onPress
  150. } = this.props;
  151. const testHintId
  152. = this.props.testHintId
  153. ? this.props.testHintId
  154. : `org.jitsi.meet.Participant#${this.props.participantId}`;
  155. const renderSharedVideo = _isSharedVideoParticipant && !disableVideo;
  156. return (
  157. <Container
  158. onClick = { renderVideo || renderSharedVideo ? undefined : onPress }
  159. style = {{
  160. ...styles.participantView,
  161. ...this.props.style
  162. }}
  163. touchFeedback = { false }>
  164. <TestHint
  165. id = { testHintId }
  166. onPress = { renderSharedVideo ? undefined : onPress }
  167. value = '' />
  168. { renderSharedVideo && <SharedVideo /> }
  169. { renderVideo
  170. && <VideoTrack
  171. onPress = { onPress }
  172. videoTrack = { videoTrack }
  173. waitForVideoStarted = { false }
  174. zOrder = { this.props.zOrder }
  175. zoomEnabled = { this.props.zoomEnabled } /> }
  176. { !renderSharedVideo && !renderVideo
  177. && <View style = { styles.avatarContainer as ViewStyle }>
  178. <Avatar
  179. participantId = { this.props.participantId }
  180. size = { this.props.avatarSize } />
  181. </View> }
  182. { _isConnectionInactive && this.props.useConnectivityInfoLabel
  183. && this._renderInactiveConnectionInfo() }
  184. </Container>
  185. );
  186. }
  187. }
  188. /**
  189. * Maps (parts of) the redux state to the associated {@link ParticipantView}'s
  190. * props.
  191. *
  192. * @param {Object} state - The redux state.
  193. * @param {Object} ownProps - The React {@code Component} props passed to the
  194. * associated (instance of) {@code ParticipantView}.
  195. * @private
  196. * @returns {IProps}
  197. */
  198. function _mapStateToProps(state: IReduxState, ownProps: any) {
  199. const { disableVideo, participantId } = ownProps;
  200. const participant = getParticipantById(state, participantId);
  201. const videoTrack = getVideoTrackByParticipant(state, participant);
  202. return {
  203. _isConnectionInactive: isTrackStreamingStatusInactive(videoTrack),
  204. _isSharedVideoParticipant: isSharedVideoParticipant(participant),
  205. _participantName: getParticipantDisplayName(state, participantId),
  206. _renderVideo: shouldRenderParticipantVideo(state, participantId) && !disableVideo,
  207. _videoTrack: videoTrack
  208. };
  209. }
  210. /**
  211. * Returns true if the video of the participant should be rendered.
  212. *
  213. * @param {Object|Function} stateful - Object or function that can be resolved
  214. * to the Redux state.
  215. * @param {string} id - The ID of the participant.
  216. * @returns {boolean}
  217. */
  218. function shouldRenderParticipantVideo(stateful: IStateful, id: string) {
  219. const state = toState(stateful);
  220. const participant = getParticipantById(state, id);
  221. if (!participant) {
  222. return false;
  223. }
  224. /* First check if we have an unmuted video track. */
  225. const videoTrack = getVideoTrackByParticipant(state, participant);
  226. if (!videoTrack) {
  227. return false;
  228. }
  229. if (!shouldRenderVideoTrack(videoTrack, /* waitForVideoStarted */ false)) {
  230. return false;
  231. }
  232. /* Then check if the participant connection or track streaming status is active. */
  233. if (!videoTrack.local && !isTrackStreamingStatusActive(videoTrack)) {
  234. return false;
  235. }
  236. /* Then check if audio-only mode is not active. */
  237. const audioOnly = state['features/base/audio-only'].enabled;
  238. if (!audioOnly) {
  239. return true;
  240. }
  241. /* Last, check if the participant is sharing their screen and they are on stage. */
  242. const remoteScreenShares = state['features/video-layout'].remoteScreenShares || [];
  243. const largeVideoParticipantId = state['features/large-video'].participantId;
  244. const participantIsInLargeVideoWithScreen
  245. = participant.id === largeVideoParticipantId && remoteScreenShares.includes(participant.id);
  246. return participantIsInLargeVideoWithScreen;
  247. }
  248. export default translate(connect(_mapStateToProps)(ParticipantView));