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

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