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

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