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

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