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 9.2KB

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