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

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