您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

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 type { 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. * Whether video should be disabled for his view.
  50. */
  51. disableVideo: ?boolean,
  52. /**
  53. * Callback to invoke when the {@code ParticipantView} is clicked/pressed.
  54. */
  55. onPress: Function,
  56. /**
  57. * The ID of the participant (to be) depicted by {@link ParticipantView}.
  58. *
  59. * @public
  60. */
  61. participantId: string,
  62. /**
  63. * The style, if any, to apply to {@link ParticipantView} in addition to its
  64. * default style.
  65. */
  66. style: Object,
  67. /**
  68. * The function to translate human-readable text.
  69. */
  70. t: Function,
  71. /**
  72. * If true, a tinting will be applied to the view, regardless of video or
  73. * avatar is rendered.
  74. */
  75. tintEnabled: boolean,
  76. /**
  77. * The style of the tinting when applied.
  78. */
  79. tintStyle: StyleType,
  80. /**
  81. * The test hint id which can be used to locate the {@code ParticipantView}
  82. * on the jitsi-meet-torture side. If not provided, the
  83. * {@code participantId} with the following format will be used:
  84. * {@code `org.jitsi.meet.Participant#${participantId}`}
  85. */
  86. testHintId: ?string,
  87. /**
  88. * Indicates if the connectivity info label should be shown, if appropriate.
  89. * It will be shown in case the connection is interrupted.
  90. */
  91. useConnectivityInfoLabel: boolean,
  92. /**
  93. * The z-order of the {@link Video} of {@link ParticipantView} in the
  94. * stacking space of all {@code Video}s. For more details, refer to the
  95. * {@code zOrder} property of the {@code Video} class for React Native.
  96. */
  97. zOrder: number,
  98. /**
  99. * Indicates whether zooming (pinch to zoom and/or drag) is enabled.
  100. */
  101. zoomEnabled: boolean
  102. };
  103. /**
  104. * Implements a React Component which depicts a specific participant's avatar
  105. * and video.
  106. *
  107. * @extends Component
  108. */
  109. class ParticipantView extends Component<Props> {
  110. /**
  111. * Renders the connection status label, if appropriate.
  112. *
  113. * @param {string} connectionStatus - The status of the participant's
  114. * connection.
  115. * @private
  116. * @returns {ReactElement|null}
  117. */
  118. _renderConnectionInfo(connectionStatus) {
  119. let messageKey;
  120. switch (connectionStatus) {
  121. case JitsiParticipantConnectionStatus.INACTIVE:
  122. messageKey = 'connection.LOW_BANDWIDTH';
  123. break;
  124. default:
  125. return null;
  126. }
  127. const {
  128. avatarSize,
  129. _participantName: displayName,
  130. t
  131. } = this.props;
  132. // XXX Consider splitting this component into 2: one for the large view
  133. // and one for the thumbnail. Some of these don't apply to both.
  134. const containerStyle = {
  135. ...styles.connectionInfoContainer,
  136. width: avatarSize * 1.5
  137. };
  138. return (
  139. <View
  140. pointerEvents = 'box-none'
  141. style = { containerStyle }>
  142. <Text style = { styles.connectionInfoText }>
  143. { t(messageKey, { displayName }) }
  144. </Text>
  145. </View>
  146. );
  147. }
  148. /**
  149. * Implements React's {@link Component#render()}.
  150. *
  151. * @inheritdoc
  152. * @returns {ReactElement}
  153. */
  154. render() {
  155. const {
  156. _connectionStatus: connectionStatus,
  157. _renderVideo: renderVideo,
  158. _videoTrack: videoTrack,
  159. onPress,
  160. tintStyle
  161. } = this.props;
  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 = { false }
  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 { disableVideo, 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) && !disableVideo,
  227. _videoTrack:
  228. getTrackByMediaTypeAndParticipant(
  229. state['features/base/tracks'],
  230. MEDIA_TYPE.VIDEO,
  231. participantId)
  232. };
  233. }
  234. export default translate(connect(_mapStateToProps)(ParticipantView));