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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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. * ParticipantView component's property types.
  22. *
  23. * @static
  24. */
  25. static propTypes = {
  26. /**
  27. * The source (e.g. URI, URL) of the avatar image of the participant
  28. * with {@link #participantId}.
  29. *
  30. * @private
  31. */
  32. _avatar: React.PropTypes.string,
  33. /**
  34. * The video Track of the participant with {@link #participantId}.
  35. */
  36. _videoTrack: React.PropTypes.object,
  37. /**
  38. * The style, if any, of the avatar in addition to the default style.
  39. */
  40. avatarStyle: React.PropTypes.object,
  41. /**
  42. * The ID of the participant (to be) depicted by ParticipantView.
  43. *
  44. * @public
  45. */
  46. participantId: React.PropTypes.string,
  47. /**
  48. * True if the avatar of the depicted participant is to be shown should
  49. * the avatar be available and the video of the participant is not to be
  50. * shown; otherwise, false. If undefined, defaults to true.
  51. */
  52. showAvatar: React.PropTypes.bool,
  53. /**
  54. * True if the video of the depicted participant is to be shown should
  55. * the video be available. If undefined, defaults to true.
  56. */
  57. showVideo: React.PropTypes.bool,
  58. /**
  59. * The style, if any, to apply to ParticipantView in addition to its
  60. * default style.
  61. */
  62. style: React.PropTypes.object,
  63. /**
  64. * The z-order of the Video of ParticipantView in the stacking space of
  65. * all Videos. For more details, refer to the zOrder property of the
  66. * Video class for React Native.
  67. */
  68. zOrder: React.PropTypes.number
  69. }
  70. /**
  71. * Implements React's {@link Component#render()}.
  72. *
  73. * @inheritdoc
  74. * @returns {ReactElement}
  75. */
  76. render() {
  77. // Is the video to be rendered?
  78. const videoTrack = this.props._videoTrack;
  79. // FIXME It's currently impossible to have true as the value of
  80. // waitForVideoStarted because videoTrack's state videoStarted will be
  81. // updated only after videoTrack is rendered.
  82. const waitForVideoStarted = false;
  83. const renderVideo
  84. = shouldRenderVideoTrack(videoTrack, waitForVideoStarted);
  85. // Is the avatar to be rendered?
  86. const avatar = this.props._avatar;
  87. const renderAvatar
  88. = !renderVideo && typeof avatar !== 'undefined' && avatar !== '';
  89. return (
  90. <Container
  91. style = {{
  92. ...styles.participantView,
  93. ...this.props.style
  94. }}>
  95. { renderVideo
  96. // The consumer of this ParticipantView is allowed to forbid
  97. // showing the video if the private logic of this
  98. // ParticipantView determines that the video could be
  99. // rendered.
  100. && _toBoolean(this.props.showVideo, true)
  101. && <VideoTrack
  102. videoTrack = { videoTrack }
  103. waitForVideoStarted = { waitForVideoStarted }
  104. zOrder = { this.props.zOrder } /> }
  105. { renderAvatar
  106. // The consumer of this ParticipantView is allowed to forbid
  107. // showing the avatar if the private logic of this
  108. // ParticipantView determines that the avatar could be
  109. // rendered.
  110. && _toBoolean(this.props.showAvatar, true)
  111. && <Avatar
  112. style = { this.props.avatarStyle }
  113. uri = { avatar } /> }
  114. </Container>
  115. );
  116. }
  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);