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.js 5.4KB

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