Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

ParticipantView.native.js 7.8KB

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