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

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