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.

Thumbnail.js 7.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  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. * Handles click/tap event on the thumbnail.
  39. */
  40. _onClick: ?Function,
  41. /**
  42. * Handles long press on the thumbnail.
  43. */
  44. _onShowRemoteVideoMenu: ?Function,
  45. /**
  46. * The Redux representation of the participant's video track.
  47. */
  48. _videoTrack: Object,
  49. /**
  50. * If true, tapping on the thumbnail will not pin the participant to large
  51. * video. By default tapping does pin the participant.
  52. */
  53. disablePin?: boolean,
  54. /**
  55. * If true, there will be no color overlay (tint) on the thumbnail
  56. * indicating the participant associated with the thumbnail is displayed on
  57. * large video. By default there will be a tint.
  58. */
  59. disableTint?: boolean,
  60. /**
  61. * Invoked to trigger state changes in Redux.
  62. */
  63. dispatch: Dispatch<*>,
  64. /**
  65. * The Redux representation of the participant to display.
  66. */
  67. participant: Object,
  68. /**
  69. * Optional styling to add or override on the Thumbnail component root.
  70. */
  71. styleOverrides?: Object
  72. };
  73. /**
  74. * React component for video thumbnail.
  75. *
  76. * @extends Component
  77. */
  78. class Thumbnail extends Component<Props> {
  79. /**
  80. * Implements React's {@link Component#render()}.
  81. *
  82. * @inheritdoc
  83. * @returns {ReactElement}
  84. */
  85. render() {
  86. const {
  87. _audioTrack: audioTrack,
  88. _isModerator,
  89. _largeVideo: largeVideo,
  90. _onClick,
  91. _onShowRemoteVideoMenu,
  92. _videoTrack: videoTrack,
  93. disablePin,
  94. disableTint,
  95. participant
  96. } = this.props;
  97. // We don't render audio in any of the following:
  98. // 1. The audio (source) is muted. There's no practical reason (that we
  99. // know of, anyway) why we'd want to render it given that it's
  100. // silence (& not even comfort noise).
  101. // 2. The audio is local. If we were to render local audio, the local
  102. // participants would be hearing themselves.
  103. const audioMuted = !audioTrack || audioTrack.muted;
  104. const renderAudio = !audioMuted && !audioTrack.local;
  105. const participantId = participant.id;
  106. const participantInLargeVideo
  107. = participantId === largeVideo.participantId;
  108. const videoMuted = !videoTrack || videoTrack.muted;
  109. const showRemoteVideoMenu = _isModerator && !participant.local;
  110. return (
  111. <Container
  112. onClick = { disablePin ? undefined : _onClick }
  113. onLongPress = {
  114. showRemoteVideoMenu
  115. ? _onShowRemoteVideoMenu : undefined }
  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. }
  146. /**
  147. * Maps part of redux actions to component's props.
  148. *
  149. * @param {Function} dispatch - Redux's {@code dispatch} function.
  150. * @param {Props} ownProps - The own props of the component.
  151. * @returns {{
  152. * _onClick: Function,
  153. * _onShowRemoteVideoMenu: Function
  154. * }}
  155. */
  156. function _mapDispatchToProps(dispatch: Function, ownProps): Object {
  157. return {
  158. /**
  159. * Handles click/tap event on the thumbnail.
  160. *
  161. * @protected
  162. * @returns {void}
  163. */
  164. _onClick() {
  165. const { participant } = ownProps;
  166. dispatch(
  167. pinParticipant(participant.pinned ? null : participant.id));
  168. },
  169. /**
  170. * Handles long press on the thumbnail.
  171. *
  172. * @returns {void}
  173. */
  174. _onShowRemoteVideoMenu() {
  175. const { participant } = ownProps;
  176. dispatch(openDialog(RemoteVideoMenu, {
  177. participant
  178. }));
  179. }
  180. };
  181. }
  182. /**
  183. * Function that maps parts of Redux state tree into component props.
  184. *
  185. * @param {Object} state - Redux state.
  186. * @param {Props} ownProps - Properties of component.
  187. * @returns {{
  188. * _audioTrack: Track,
  189. * _isModerator: boolean,
  190. * _largeVideo: Object,
  191. * _videoTrack: Track
  192. * }}
  193. */
  194. function _mapStateToProps(state, ownProps) {
  195. // We need read-only access to the state of features/large-video so that the
  196. // filmstrip doesn't render the video of the participant who is rendered on
  197. // the stage i.e. as a large video.
  198. const largeVideo = state['features/large-video'];
  199. const tracks = state['features/base/tracks'];
  200. const id = ownProps.participant.id;
  201. const audioTrack
  202. = getTrackByMediaTypeAndParticipant(tracks, MEDIA_TYPE.AUDIO, id);
  203. const videoTrack
  204. = getTrackByMediaTypeAndParticipant(tracks, MEDIA_TYPE.VIDEO, id);
  205. return {
  206. _audioTrack: audioTrack,
  207. _isModerator: isLocalParticipantModerator(state),
  208. _largeVideo: largeVideo,
  209. _videoTrack: videoTrack
  210. };
  211. }
  212. export default connect(_mapStateToProps, _mapDispatchToProps)(Thumbnail);