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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  1. // @flow
  2. import React, { Component } from 'react';
  3. import { Text, View } from 'react-native';
  4. import { connect } from 'react-redux';
  5. import { translate } from '../../i18n';
  6. import { JitsiParticipantConnectionStatus } from '../../lib-jitsi-meet';
  7. import {
  8. MEDIA_TYPE,
  9. shouldRenderVideoTrack,
  10. VideoTrack
  11. } from '../../media';
  12. import { prefetch } from '../../../mobile/image-cache';
  13. import { Container, TintedView } from '../../react';
  14. import { getTrackByMediaTypeAndParticipant } from '../../tracks';
  15. import Avatar from './Avatar';
  16. import {
  17. getAvatarURL,
  18. getParticipantById,
  19. getParticipantDisplayName
  20. } from '../functions';
  21. import styles from './styles';
  22. /**
  23. * The type of the React {@link Component} props of {@link ParticipantView}.
  24. */
  25. type Props = {
  26. /**
  27. * The indicator which determines whether conferencing is in audio-only
  28. * mode.
  29. *
  30. * @private
  31. */
  32. _audioOnly: boolean,
  33. /**
  34. * The source (e.g. URI, URL) of the avatar image of the participant with
  35. * {@link #participantId}.
  36. *
  37. * @private
  38. */
  39. _avatar: string,
  40. /**
  41. * The connection status of the participant. Her video will only be rendered
  42. * if the connection status is 'active'; otherwise, the avatar will be
  43. * rendered. If undefined, 'active' is presumed.
  44. *
  45. * @private
  46. */
  47. _connectionStatus: string,
  48. /**
  49. * The name of the participant which this component represents.
  50. *
  51. * @private
  52. */
  53. _participantName: string,
  54. /**
  55. * The video Track of the participant with {@link #participantId}.
  56. */
  57. _videoTrack: Object,
  58. /**
  59. * The avatar size.
  60. */
  61. avatarSize: number,
  62. /**
  63. * Callback to invoke when the {@code ParticipantView} is clicked/pressed.
  64. */
  65. onPress: Function,
  66. /**
  67. * The ID of the participant (to be) depicted by {@link ParticipantView}.
  68. *
  69. * @public
  70. */
  71. participantId: string,
  72. /**
  73. * True if the avatar of the depicted participant is to be shown should the
  74. * avatar be available and the video of the participant is not to be shown;
  75. * otherwise, false. If undefined, defaults to true.
  76. */
  77. showAvatar: boolean,
  78. /**
  79. * True if the video of the depicted participant is to be shown should the
  80. * video be available. If undefined, defaults to true.
  81. */
  82. showVideo: boolean,
  83. /**
  84. * The style, if any, to apply to {@link ParticipantView} in addition to its
  85. * default style.
  86. */
  87. style: Object,
  88. /**
  89. * The function to translate human-readable text.
  90. */
  91. t: Function,
  92. /**
  93. * Indicates if the connectivity info label should be shown, if appropriate.
  94. * It will be shown in case the connection is interrupted.
  95. */
  96. useConnectivityInfoLabel: boolean,
  97. /**
  98. * The z-order of the {@link Video} of {@link ParticipantView} in the
  99. * stacking space of all {@code Video}s. For more details, refer to the
  100. * {@code zOrder} property of the {@code Video} class for React Native.
  101. */
  102. zOrder: number,
  103. /**
  104. * Indicates whether zooming (pinch to zoom and/or drag) is enabled.
  105. */
  106. zoomEnabled: boolean
  107. };
  108. /**
  109. * Implements a React Component which depicts a specific participant's avatar
  110. * and video.
  111. *
  112. * @extends Component
  113. */
  114. class ParticipantView extends Component<Props> {
  115. /**
  116. * Renders the connection status label, if appropriate.
  117. *
  118. * @param {string} connectionStatus - The status of the participant's
  119. * connection.
  120. * @private
  121. * @returns {ReactElement|null}
  122. */
  123. _renderConnectionInfo(connectionStatus) {
  124. let messageKey;
  125. switch (connectionStatus) {
  126. case JitsiParticipantConnectionStatus.INACTIVE:
  127. messageKey = 'connection.LOW_BANDWIDTH';
  128. break;
  129. case JitsiParticipantConnectionStatus.INTERRUPTED:
  130. messageKey = 'connection.USER_CONNECTION_INTERRUPTED';
  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. onPress,
  165. _avatar: avatar,
  166. _connectionStatus: connectionStatus,
  167. _videoTrack: videoTrack
  168. } = this.props;
  169. // Is the video to be rendered?
  170. // FIXME It's currently impossible to have true as the value of
  171. // waitForVideoStarted because videoTrack's state videoStarted will be
  172. // updated only after videoTrack is rendered.
  173. // XXX Note that, unlike on web, we don't render video when the
  174. // connection status is interrupted, this is because the renderer
  175. // doesn't retain the last frame forever, so we would end up with a
  176. // black screen.
  177. const waitForVideoStarted = false;
  178. let renderVideo
  179. = !this.props._audioOnly
  180. && (connectionStatus
  181. === JitsiParticipantConnectionStatus.ACTIVE)
  182. && shouldRenderVideoTrack(videoTrack, waitForVideoStarted);
  183. // Is the avatar to be rendered?
  184. let renderAvatar = Boolean(!renderVideo && avatar);
  185. // The consumer of this ParticipantView is allowed to forbid showing the
  186. // video if the private logic of this ParticipantView determines that
  187. // the video could be rendered.
  188. renderVideo = renderVideo && _toBoolean(this.props.showVideo, true);
  189. // The consumer of this ParticipantView is allowed to forbid showing the
  190. // avatar if the private logic of this ParticipantView determines that
  191. // the avatar could be rendered.
  192. renderAvatar = renderAvatar && _toBoolean(this.props.showAvatar, true);
  193. // If the connection has problems, we will "tint" the video / avatar.
  194. const useTint
  195. = connectionStatus === JitsiParticipantConnectionStatus.INACTIVE
  196. || connectionStatus
  197. === JitsiParticipantConnectionStatus.INTERRUPTED;
  198. return (
  199. <Container
  200. onClick = { renderVideo ? undefined : onPress }
  201. style = {{
  202. ...styles.participantView,
  203. ...this.props.style
  204. }}
  205. touchFeedback = { false }>
  206. { renderVideo
  207. && <VideoTrack
  208. onPress = { renderVideo ? onPress : undefined }
  209. videoTrack = { videoTrack }
  210. waitForVideoStarted = { waitForVideoStarted }
  211. zOrder = { this.props.zOrder }
  212. zoomEnabled = { this.props.zoomEnabled } /> }
  213. { renderAvatar
  214. && <Avatar
  215. size = { this.props.avatarSize }
  216. uri = { avatar } /> }
  217. { useTint
  218. // If the connection has problems, tint the video / avatar.
  219. && <TintedView /> }
  220. { this.props.useConnectivityInfoLabel
  221. && this._renderConnectionInfo(connectionStatus) }
  222. </Container>
  223. );
  224. }
  225. }
  226. /**
  227. * Converts the specified value to a boolean value. If the specified value is
  228. * undefined, returns the boolean value of undefinedValue.
  229. *
  230. * @param {any} value - The value to convert to a boolean value should it not be
  231. * undefined.
  232. * @param {any} undefinedValue - The value to convert to a boolean value should
  233. * the specified value be undefined.
  234. * @private
  235. * @returns {boolean}
  236. */
  237. function _toBoolean(value, undefinedValue) {
  238. return Boolean(typeof value === 'undefined' ? undefinedValue : value);
  239. }
  240. /**
  241. * Maps (parts of) the redux state to the associated {@link ParticipantView}'s
  242. * props.
  243. *
  244. * @param {Object} state - The redux state.
  245. * @param {Object} ownProps - The React {@code Component} props passed to the
  246. * associated (instance of) {@code ParticipantView}.
  247. * @private
  248. * @returns {{
  249. * _audioOnly: boolean,
  250. * _avatar: string,
  251. * _connectionStatus: string,
  252. * _participantName: string,
  253. * _videoTrack: Track
  254. * }}
  255. */
  256. function _mapStateToProps(state, ownProps) {
  257. const { participantId } = ownProps;
  258. const participant
  259. = getParticipantById(
  260. state['features/base/participants'],
  261. participantId);
  262. let avatar;
  263. let connectionStatus;
  264. let participantName;
  265. if (participant) {
  266. avatar = getAvatarURL(participant);
  267. connectionStatus = participant.connectionStatus;
  268. participantName = getParticipantDisplayName(state, participant.id);
  269. // Avatar (on React Native) now has the ability to generate an
  270. // automatically-colored default image when no URI/URL is specified or
  271. // when it fails to load. In order to make the coloring permanent(ish)
  272. // per participant, Avatar will need something permanent(ish) per
  273. // perticipant, obviously. A participant's ID is such a piece of data.
  274. // But the local participant changes her ID as she joins, leaves.
  275. // TODO @lyubomir: The participants may change their avatar URLs at
  276. // runtime which means that, if their old and new avatar URLs fail to
  277. // download, Avatar will change their automatically-generated colors.
  278. avatar || participant.local || (avatar = `#${participant.id}`);
  279. // ParticipantView knows before Avatar that an avatar URL will be used
  280. // so it's advisable to prefetch here.
  281. avatar && prefetch({ uri: avatar });
  282. }
  283. return {
  284. _audioOnly: state['features/base/conference'].audioOnly,
  285. _avatar: avatar,
  286. _connectionStatus:
  287. connectionStatus
  288. || JitsiParticipantConnectionStatus.ACTIVE,
  289. _participantName: participantName,
  290. _videoTrack:
  291. getTrackByMediaTypeAndParticipant(
  292. state['features/base/tracks'],
  293. MEDIA_TYPE.VIDEO,
  294. participantId)
  295. };
  296. }
  297. export default translate(connect(_mapStateToProps)(ParticipantView));