您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

Thumbnail.js 6.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. // @flow
  2. import React, { Component } from 'react';
  3. import { connect } from 'react-redux';
  4. import { openDialog } from '../../../base/dialog';
  5. import { Audio, MEDIA_TYPE } from '../../../base/media';
  6. import {
  7. PARTICIPANT_ROLE,
  8. ParticipantView,
  9. isLocalParticipantModerator,
  10. pinParticipant
  11. } from '../../../base/participants';
  12. import { Container } from '../../../base/react';
  13. import { getTrackByMediaTypeAndParticipant } from '../../../base/tracks';
  14. import { RemoteVideoMenu } from '../../../remote-video-menu';
  15. import AudioMutedIndicator from './AudioMutedIndicator';
  16. import DominantSpeakerIndicator from './DominantSpeakerIndicator';
  17. import ModeratorIndicator from './ModeratorIndicator';
  18. import { AVATAR_SIZE } from '../styles';
  19. import styles from './styles';
  20. import VideoMutedIndicator from './VideoMutedIndicator';
  21. /**
  22. * Thumbnail component's property types.
  23. */
  24. type Props = {
  25. /**
  26. * The Redux representation of the participant's audio track.
  27. */
  28. _audioTrack: Object,
  29. /**
  30. * True if the local participant is a moderator.
  31. */
  32. _isModerator: boolean,
  33. /**
  34. * The Redux representation of the state "features/large-video".
  35. */
  36. _largeVideo: Object,
  37. /**
  38. * The Redux representation of the participant's video track.
  39. */
  40. _videoTrack: Object,
  41. /**
  42. * If true, tapping on the thumbnail will not pin the participant to large
  43. * video. By default tapping does pin the participant.
  44. */
  45. disablePin?: boolean,
  46. /**
  47. * If true, there will be no color overlay (tint) on the thumbnail
  48. * indicating the participant associated with the thumbnail is displayed on
  49. * large video. By default there will be a tint.
  50. */
  51. disableTint?: boolean,
  52. /**
  53. * Invoked to trigger state changes in Redux.
  54. */
  55. dispatch: Dispatch<*>,
  56. /**
  57. * The Redux representation of the participant to display.
  58. */
  59. participant: Object,
  60. /**
  61. * Optional styling to add or override on the Thumbnail component root.
  62. */
  63. styleOverrides?: Object
  64. };
  65. /**
  66. * React component for video thumbnail.
  67. *
  68. * @extends Component
  69. */
  70. class Thumbnail extends Component<Props> {
  71. /**
  72. * Initializes new Video Thumbnail component.
  73. *
  74. * @param {Object} props - Component props.
  75. */
  76. constructor(props: Props) {
  77. super(props);
  78. // Bind event handlers so they are only bound once for every instance.
  79. this._onClick = this._onClick.bind(this);
  80. this._onShowRemoteVideoMenu = this._onShowRemoteVideoMenu.bind(this);
  81. }
  82. /**
  83. * Implements React's {@link Component#render()}.
  84. *
  85. * @inheritdoc
  86. * @returns {ReactElement}
  87. */
  88. render() {
  89. const {
  90. _audioTrack: audioTrack,
  91. _isModerator,
  92. _largeVideo: largeVideo,
  93. _videoTrack: videoTrack,
  94. disablePin,
  95. disableTint,
  96. participant
  97. } = this.props;
  98. // We don't render audio in any of the following:
  99. // 1. The audio (source) is muted. There's no practical reason (that we
  100. // know of, anyway) why we'd want to render it given that it's
  101. // silence (& not even comfort noise).
  102. // 2. The audio is local. If we were to render local audio, the local
  103. // participants would be hearing themselves.
  104. const audioMuted = !audioTrack || audioTrack.muted;
  105. const renderAudio = !audioMuted && !audioTrack.local;
  106. const participantId = participant.id;
  107. const participantInLargeVideo
  108. = participantId === largeVideo.participantId;
  109. const videoMuted = !videoTrack || videoTrack.muted;
  110. const showRemoteVideoMenu = _isModerator && !participant.local;
  111. return (
  112. <Container
  113. onClick = { disablePin ? undefined : this._onClick }
  114. onLongPress = {
  115. showRemoteVideoMenu && this._onShowRemoteVideoMenu }
  116. style = { [
  117. styles.thumbnail,
  118. participant.pinned && !disablePin
  119. ? styles.thumbnailPinned : null,
  120. this.props.styleOverrides || null
  121. ] }
  122. touchFeedback = { false }>
  123. { renderAudio
  124. && <Audio
  125. stream
  126. = { audioTrack.jitsiTrack.getOriginalStream() } /> }
  127. <ParticipantView
  128. avatarSize = { AVATAR_SIZE }
  129. participantId = { participantId }
  130. tintEnabled = { participantInLargeVideo && !disableTint }
  131. zOrder = { 1 } />
  132. { participant.role === PARTICIPANT_ROLE.MODERATOR
  133. && <ModeratorIndicator /> }
  134. { participant.dominantSpeaker
  135. && <DominantSpeakerIndicator /> }
  136. <Container style = { styles.thumbnailIndicatorContainer }>
  137. { audioMuted
  138. && <AudioMutedIndicator /> }
  139. { videoMuted
  140. && <VideoMutedIndicator /> }
  141. </Container>
  142. </Container>
  143. );
  144. }
  145. _onClick: () => void;
  146. /**
  147. * Handles click/tap event on the thumbnail.
  148. *
  149. * @returns {void}
  150. */
  151. _onClick() {
  152. const { dispatch, participant } = this.props;
  153. // TODO The following currently ignores interfaceConfig.filmStripOnly.
  154. dispatch(pinParticipant(participant.pinned ? null : participant.id));
  155. }
  156. _onShowRemoteVideoMenu: () => void;
  157. /**
  158. * Handles long press on the thumbnail.
  159. *
  160. * @returns {void}
  161. */
  162. _onShowRemoteVideoMenu() {
  163. const { dispatch, participant } = this.props;
  164. dispatch(openDialog(RemoteVideoMenu, {
  165. participant
  166. }));
  167. }
  168. }
  169. /**
  170. * Function that maps parts of Redux state tree into component props.
  171. *
  172. * @param {Object} state - Redux state.
  173. * @param {Object} ownProps - Properties of component.
  174. * @private
  175. * @returns {{
  176. * _audioTrack: Track,
  177. * _isModerator: boolean,
  178. * _largeVideo: Object,
  179. * _videoTrack: Track
  180. * }}
  181. */
  182. function _mapStateToProps(state, ownProps) {
  183. // We need read-only access to the state of features/large-video so that the
  184. // filmstrip doesn't render the video of the participant who is rendered on
  185. // the stage i.e. as a large video.
  186. const largeVideo = state['features/large-video'];
  187. const tracks = state['features/base/tracks'];
  188. const id = ownProps.participant.id;
  189. const audioTrack
  190. = getTrackByMediaTypeAndParticipant(tracks, MEDIA_TYPE.AUDIO, id);
  191. const videoTrack
  192. = getTrackByMediaTypeAndParticipant(tracks, MEDIA_TYPE.VIDEO, id);
  193. return {
  194. _audioTrack: audioTrack,
  195. _isModerator: isLocalParticipantModerator(state),
  196. _largeVideo: largeVideo,
  197. _videoTrack: videoTrack
  198. };
  199. }
  200. export default connect(_mapStateToProps)(Thumbnail);