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

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