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

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