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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  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 { Audio, MEDIA_TYPE } 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. return (
  126. <Container
  127. onClick = { _onClick }
  128. onLongPress = { participant.local ? undefined : _onShowRemoteVideoMenu }
  129. style = { [
  130. styles.thumbnail,
  131. participant.pinned && !tileView
  132. ? _styles.thumbnailPinned : null,
  133. this.props.styleOverrides || null
  134. ] }
  135. touchFeedback = { false }>
  136. { renderAudio
  137. && <Audio
  138. stream
  139. = { audioTrack.jitsiTrack.getOriginalStream() } /> }
  140. <ParticipantView
  141. avatarSize = { AVATAR_SIZE }
  142. participantId = { participantId }
  143. style = { _styles.participantViewStyle }
  144. tintEnabled = { participantInLargeVideo && !disableTint }
  145. tintStyle = { _styles.activeThumbnailTint }
  146. zOrder = { 1 } />
  147. { renderDisplayName && <DisplayNameLabel participantId = { participantId } /> }
  148. { !_isEveryoneModerator && participant.role === PARTICIPANT_ROLE.MODERATOR
  149. && <View style = { styles.moderatorIndicatorContainer }>
  150. <ModeratorIndicator />
  151. </View> }
  152. <View
  153. style = { [
  154. styles.thumbnailTopIndicatorContainer,
  155. styles.thumbnailTopLeftIndicatorContainer
  156. ] }>
  157. <RaisedHandIndicator participantId = { participant.id } />
  158. { participant.dominantSpeaker
  159. && <DominantSpeakerIndicator /> }
  160. </View>
  161. <View
  162. style = { [
  163. styles.thumbnailTopIndicatorContainer,
  164. styles.thumbnailTopRightIndicatorContainer
  165. ] }>
  166. <ConnectionIndicator participantId = { participant.id } />
  167. </View>
  168. <Container style = { styles.thumbnailIndicatorContainer }>
  169. { audioMuted
  170. && <AudioMutedIndicator /> }
  171. { videoMuted
  172. && <VideoMutedIndicator /> }
  173. </Container>
  174. </Container>
  175. );
  176. }
  177. }
  178. /**
  179. * Maps part of redux actions to component's props.
  180. *
  181. * @param {Function} dispatch - Redux's {@code dispatch} function.
  182. * @param {Props} ownProps - The own props of the component.
  183. * @returns {{
  184. * _onClick: Function,
  185. * _onShowRemoteVideoMenu: Function
  186. * }}
  187. */
  188. function _mapDispatchToProps(dispatch: Function, ownProps): Object {
  189. return {
  190. /**
  191. * Handles click/tap event on the thumbnail.
  192. *
  193. * @protected
  194. * @returns {void}
  195. */
  196. _onClick() {
  197. const { participant, tileView } = ownProps;
  198. if (tileView) {
  199. dispatch(toggleToolboxVisible());
  200. } else {
  201. dispatch(pinParticipant(participant.pinned ? null : participant.id));
  202. }
  203. },
  204. /**
  205. * Handles long press on the thumbnail.
  206. *
  207. * @returns {void}
  208. */
  209. _onShowRemoteVideoMenu() {
  210. const { participant } = ownProps;
  211. dispatch(openDialog(RemoteVideoMenu, {
  212. participant
  213. }));
  214. }
  215. };
  216. }
  217. /**
  218. * Function that maps parts of Redux state tree into component props.
  219. *
  220. * @param {Object} state - Redux state.
  221. * @param {Props} ownProps - Properties of component.
  222. * @returns {{
  223. * _audioTrack: Track,
  224. * _largeVideo: Object,
  225. * _styles: StyleType,
  226. * _videoTrack: Track
  227. * }}
  228. */
  229. function _mapStateToProps(state, ownProps) {
  230. // We need read-only access to the state of features/large-video so that the
  231. // filmstrip doesn't render the video of the participant who is rendered on
  232. // the stage i.e. as a large video.
  233. const largeVideo = state['features/large-video'];
  234. const tracks = state['features/base/tracks'];
  235. const id = ownProps.participant.id;
  236. const audioTrack
  237. = getTrackByMediaTypeAndParticipant(tracks, MEDIA_TYPE.AUDIO, id);
  238. const videoTrack
  239. = getTrackByMediaTypeAndParticipant(tracks, MEDIA_TYPE.VIDEO, id);
  240. return {
  241. _audioTrack: audioTrack,
  242. _isEveryoneModerator: isEveryoneModerator(state),
  243. _largeVideo: largeVideo,
  244. _styles: ColorSchemeRegistry.get(state, 'Thumbnail'),
  245. _videoTrack: videoTrack
  246. };
  247. }
  248. export default connect(_mapStateToProps, _mapDispatchToProps)(Thumbnail);