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.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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 source (e.g. URI, URL) of the avatar image of the participant
  29. * with {@link #participantId}.
  30. *
  31. * @private
  32. */
  33. _avatar: React.PropTypes.string,
  34. /**
  35. * The connection status for the participant. Its video will only be
  36. * rendered if the connection status is 'active', otherwise the avatar
  37. * will be rendered. If undefined, we have no indication, so the same
  38. * course of action as 'active' is taken.
  39. */
  40. _connectionStatus: React.PropTypes.string,
  41. /**
  42. * The video Track of the participant with {@link #participantId}.
  43. */
  44. _videoTrack: React.PropTypes.object,
  45. /**
  46. * The style, if any, of the avatar in addition to the default style.
  47. */
  48. avatarStyle: React.PropTypes.object,
  49. /**
  50. * The ID of the participant (to be) depicted by ParticipantView.
  51. *
  52. * @public
  53. */
  54. participantId: React.PropTypes.string,
  55. /**
  56. * True if the avatar of the depicted participant is to be shown should
  57. * the avatar be available and the video of the participant is not to be
  58. * shown; otherwise, false. If undefined, defaults to true.
  59. */
  60. showAvatar: React.PropTypes.bool,
  61. /**
  62. * True if the video of the depicted participant is to be shown should
  63. * the video be available. If undefined, defaults to true.
  64. */
  65. showVideo: React.PropTypes.bool,
  66. /**
  67. * The style, if any, to apply to ParticipantView in addition to its
  68. * default style.
  69. */
  70. style: React.PropTypes.object,
  71. /**
  72. * The z-order of the Video of ParticipantView in the stacking space of
  73. * all Videos. For more details, refer to the zOrder property of the
  74. * Video class for React Native.
  75. */
  76. zOrder: React.PropTypes.number
  77. }
  78. /**
  79. * Implements React's {@link Component#render()}.
  80. *
  81. * @inheritdoc
  82. * @returns {ReactElement}
  83. */
  84. render() {
  85. const {
  86. _avatar: avatar,
  87. _connectionStatus: connectionStatus,
  88. _videoTrack: videoTrack
  89. } = this.props;
  90. // Is the video to be rendered?
  91. // FIXME It's currently impossible to have true as the value of
  92. // waitForVideoStarted because videoTrack's state videoStarted will be
  93. // updated only after videoTrack is rendered.
  94. const waitForVideoStarted = false;
  95. const renderVideo
  96. = shouldRenderVideoTrack(videoTrack, waitForVideoStarted)
  97. && (typeof connectionStatus === 'undefined'
  98. || connectionStatus
  99. === JitsiParticipantConnectionStatus.ACTIVE);
  100. // Is the avatar to be rendered?
  101. const renderAvatar = Boolean(!renderVideo && avatar);
  102. return (
  103. <Container
  104. style = {{
  105. ...styles.participantView,
  106. ...this.props.style
  107. }}>
  108. { renderVideo
  109. // The consumer of this ParticipantView is allowed to forbid
  110. // showing the video if the private logic of this
  111. // ParticipantView determines that the video could be
  112. // rendered.
  113. && _toBoolean(this.props.showVideo, true)
  114. && <VideoTrack
  115. videoTrack = { videoTrack }
  116. waitForVideoStarted = { waitForVideoStarted }
  117. zOrder = { this.props.zOrder } /> }
  118. { renderAvatar
  119. // The consumer of this ParticipantView is allowed to forbid
  120. // showing the avatar if the private logic of this
  121. // ParticipantView determines that the avatar could be
  122. // rendered.
  123. && _toBoolean(this.props.showAvatar, true)
  124. && <Avatar
  125. style = { this.props.avatarStyle }
  126. uri = { avatar } /> }
  127. </Container>
  128. );
  129. }
  130. }
  131. /**
  132. * Converts the specified value to a boolean value. If the specified value is
  133. * undefined, returns the boolean value of undefinedValue.
  134. *
  135. * @param {any} value - The value to convert to a boolean value should it not be
  136. * undefined.
  137. * @param {any} undefinedValue - The value to convert to a boolean value should
  138. * the specified value be undefined.
  139. * @private
  140. * @returns {boolean}
  141. */
  142. function _toBoolean(value, undefinedValue) {
  143. return Boolean(typeof value === 'undefined' ? undefinedValue : value);
  144. }
  145. /**
  146. * Maps (parts of) the Redux state to the associated ParticipantView's props.
  147. *
  148. * @param {Object} state - The Redux state.
  149. * @param {Object} ownProps - The React Component props passed to the associated
  150. * (instance of) ParticipantView.
  151. * @private
  152. * @returns {{
  153. * _avatar: string,
  154. * _connectionStatus: string,
  155. * _videoTrack: Track
  156. * }}
  157. */
  158. function _mapStateToProps(state, ownProps) {
  159. const { participantId } = ownProps;
  160. const participant
  161. = getParticipantById(
  162. state['features/base/participants'],
  163. participantId);
  164. return {
  165. _avatar: participant && getAvatarURL(participant),
  166. _connectionStatus: participant && participant.connectionStatus,
  167. _videoTrack:
  168. getTrackByMediaTypeAndParticipant(
  169. state['features/base/tracks'],
  170. MEDIA_TYPE.VIDEO,
  171. participantId)
  172. };
  173. }
  174. export default connect(_mapStateToProps)(ParticipantView);