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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. import PropTypes from 'prop-types';
  2. import React, { Component } from 'react';
  3. import { connect } from 'react-redux';
  4. import { JitsiParticipantConnectionStatus } from '../../lib-jitsi-meet';
  5. import { prefetch } from '../../../mobile/image-cache';
  6. import {
  7. MEDIA_TYPE,
  8. shouldRenderVideoTrack,
  9. VideoTrack
  10. } from '../../media';
  11. import { Container } from '../../react';
  12. import { getTrackByMediaTypeAndParticipant } from '../../tracks';
  13. import Avatar from './Avatar';
  14. import { getAvatarURL, getParticipantById } from '../functions';
  15. import styles from './styles';
  16. /**
  17. * Implements a React Component which depicts a specific participant's avatar
  18. * and video.
  19. *
  20. * @extends Component
  21. */
  22. class ParticipantView extends Component {
  23. /**
  24. * ParticipantView component's property types.
  25. *
  26. * @static
  27. */
  28. static propTypes = {
  29. /**
  30. * The indicator which determines whether conferencing is in audio-only
  31. * mode.
  32. *
  33. * @private
  34. */
  35. _audioOnly: PropTypes.bool,
  36. /**
  37. * The source (e.g. URI, URL) of the avatar image of the participant
  38. * with {@link #participantId}.
  39. *
  40. * @private
  41. */
  42. _avatar: PropTypes.string,
  43. /**
  44. * The connection status of the participant. Her video will only be
  45. * rendered if the connection status is 'active'; otherwise, the avatar
  46. * will be rendered. If undefined, 'active' is presumed.
  47. *
  48. * @private
  49. */
  50. _connectionStatus: PropTypes.string,
  51. /**
  52. * The video Track of the participant with {@link #participantId}.
  53. */
  54. _videoTrack: PropTypes.object,
  55. /**
  56. * The style, if any, of the avatar in addition to the default style.
  57. */
  58. avatarStyle: PropTypes.object,
  59. /**
  60. * The ID of the participant (to be) depicted by ParticipantView.
  61. *
  62. * @public
  63. */
  64. participantId: PropTypes.string,
  65. /**
  66. * True if the avatar of the depicted participant is to be shown should
  67. * the avatar be available and the video of the participant is not to be
  68. * shown; otherwise, false. If undefined, defaults to true.
  69. */
  70. showAvatar: PropTypes.bool,
  71. /**
  72. * True if the video of the depicted participant is to be shown should
  73. * the video be available. If undefined, defaults to true.
  74. */
  75. showVideo: PropTypes.bool,
  76. /**
  77. * The style, if any, to apply to ParticipantView in addition to its
  78. * default style.
  79. */
  80. style: PropTypes.object,
  81. /**
  82. * The z-order of the Video of ParticipantView in the stacking space of
  83. * all Videos. For more details, refer to the zOrder property of the
  84. * Video class for React Native.
  85. */
  86. zOrder: PropTypes.number
  87. };
  88. /**
  89. * Implements React's {@link Component#render()}.
  90. *
  91. * @inheritdoc
  92. * @returns {ReactElement}
  93. */
  94. render() {
  95. const {
  96. _avatar: avatar,
  97. _connectionStatus: connectionStatus,
  98. _videoTrack: videoTrack
  99. } = this.props;
  100. // Is the video to be rendered?
  101. // FIXME It's currently impossible to have true as the value of
  102. // waitForVideoStarted because videoTrack's state videoStarted will be
  103. // updated only after videoTrack is rendered.
  104. const waitForVideoStarted = false;
  105. const renderVideo
  106. = !this.props._audioOnly
  107. && (connectionStatus
  108. === JitsiParticipantConnectionStatus.ACTIVE)
  109. && shouldRenderVideoTrack(videoTrack, waitForVideoStarted);
  110. // Is the avatar to be rendered?
  111. const renderAvatar = Boolean(!renderVideo && avatar);
  112. return (
  113. <Container
  114. style = {{
  115. ...styles.participantView,
  116. ...this.props.style
  117. }}>
  118. { renderVideo
  119. // The consumer of this ParticipantView is allowed to forbid
  120. // showing the video if the private logic of this
  121. // ParticipantView determines that the video could be
  122. // rendered.
  123. && _toBoolean(this.props.showVideo, true)
  124. && <VideoTrack
  125. videoTrack = { videoTrack }
  126. waitForVideoStarted = { waitForVideoStarted }
  127. zOrder = { this.props.zOrder } /> }
  128. { renderAvatar
  129. // The consumer of this ParticipantView is allowed to forbid
  130. // showing the avatar if the private logic of this
  131. // ParticipantView determines that the avatar could be
  132. // rendered.
  133. && _toBoolean(this.props.showAvatar, true)
  134. && <Avatar
  135. style = { this.props.avatarStyle }
  136. uri = { avatar } /> }
  137. </Container>
  138. );
  139. }
  140. }
  141. /**
  142. * Converts the specified value to a boolean value. If the specified value is
  143. * undefined, returns the boolean value of undefinedValue.
  144. *
  145. * @param {any} value - The value to convert to a boolean value should it not be
  146. * undefined.
  147. * @param {any} undefinedValue - The value to convert to a boolean value should
  148. * the specified value be undefined.
  149. * @private
  150. * @returns {boolean}
  151. */
  152. function _toBoolean(value, undefinedValue) {
  153. return Boolean(typeof value === 'undefined' ? undefinedValue : value);
  154. }
  155. /**
  156. * Maps (parts of) the Redux state to the associated ParticipantView's props.
  157. *
  158. * @param {Object} state - The Redux state.
  159. * @param {Object} ownProps - The React Component props passed to the associated
  160. * (instance of) ParticipantView.
  161. * @private
  162. * @returns {{
  163. * _audioOnly: boolean,
  164. * _avatar: string,
  165. * _connectionStatus: string,
  166. * _videoTrack: Track
  167. * }}
  168. */
  169. function _mapStateToProps(state, ownProps) {
  170. const { participantId } = ownProps;
  171. const participant
  172. = getParticipantById(
  173. state['features/base/participants'],
  174. participantId);
  175. let avatar;
  176. let connectionStatus;
  177. if (participant) {
  178. avatar = getAvatarURL(participant);
  179. connectionStatus = participant.connectionStatus;
  180. // Avatar (on React Native) now has the ability to generate an
  181. // automatically-colored default image when no URI/URL is specified or
  182. // when it fails to load. In order to make the coloring permanent(ish)
  183. // per participant, Avatar will need something permanent(ish) per
  184. // perticipant, obviously. A participant's ID is such a piece of data.
  185. // But the local participant changes her ID as she joins, leaves.
  186. // TODO @lyubomir: The participants may change their avatar URLs at
  187. // runtime which means that, if their old and new avatar URLs fail to
  188. // download, Avatar will change their automatically-generated colors.
  189. avatar || participant.local || (avatar = `#${participant.id}`);
  190. // ParticipantView knows before Avatar that an avatar URL will be used
  191. // so it's advisable to prefetch here.
  192. avatar && prefetch({ uri: avatar });
  193. }
  194. return {
  195. _audioOnly: state['features/base/conference'].audioOnly,
  196. _avatar: avatar,
  197. _connectionStatus:
  198. connectionStatus
  199. || JitsiParticipantConnectionStatus.ACTIVE,
  200. _videoTrack:
  201. getTrackByMediaTypeAndParticipant(
  202. state['features/base/tracks'],
  203. MEDIA_TYPE.VIDEO,
  204. participantId)
  205. };
  206. }
  207. export default connect(_mapStateToProps)(ParticipantView);