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

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