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 8.5KB

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