Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

ParticipantView.native.js 7.7KB

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