Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

ParticipantView.native.js 7.8KB

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