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.

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