Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

Thumbnail.js 8.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  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 { ConnectionIndicator } from '../../../connection-indicator';
  19. import { DisplayNameLabel } from '../../../display-name';
  20. import { RemoteVideoMenu } from '../../../remote-video-menu';
  21. import AudioMutedIndicator from './AudioMutedIndicator';
  22. import DominantSpeakerIndicator from './DominantSpeakerIndicator';
  23. import ModeratorIndicator from './ModeratorIndicator';
  24. import RaisedHandIndicator from './RaisedHandIndicator';
  25. import styles, { AVATAR_SIZE } from './styles';
  26. import VideoMutedIndicator from './VideoMutedIndicator';
  27. /**
  28. * Thumbnail component's property types.
  29. */
  30. type Props = {
  31. /**
  32. * The Redux representation of the participant's audio track.
  33. */
  34. _audioTrack: Object,
  35. /**
  36. * True if the local participant is a moderator.
  37. */
  38. _isModerator: boolean,
  39. /**
  40. * The Redux representation of the state "features/large-video".
  41. */
  42. _largeVideo: Object,
  43. /**
  44. * Handles click/tap event on the thumbnail.
  45. */
  46. _onClick: ?Function,
  47. /**
  48. * Handles long press on the thumbnail.
  49. */
  50. _onShowRemoteVideoMenu: ?Function,
  51. /**
  52. * The color-schemed stylesheet of the feature.
  53. */
  54. _styles: StyleType,
  55. /**
  56. * The Redux representation of the participant's video track.
  57. */
  58. _videoTrack: Object,
  59. /**
  60. * If true, tapping on the thumbnail will not pin the participant to large
  61. * video. By default tapping does pin the participant.
  62. */
  63. disablePin?: boolean,
  64. /**
  65. * If true, there will be no color overlay (tint) on the thumbnail
  66. * indicating the participant associated with the thumbnail is displayed on
  67. * large video. By default there will be a tint.
  68. */
  69. disableTint?: boolean,
  70. /**
  71. * Invoked to trigger state changes in Redux.
  72. */
  73. dispatch: Dispatch<any>,
  74. /**
  75. * The Redux representation of the participant to display.
  76. */
  77. participant: Object,
  78. /**
  79. * Whether to display or hide the display name of the participant in the thumbnail.
  80. */
  81. renderDisplayName: ?boolean,
  82. /**
  83. * Optional styling to add or override on the Thumbnail component root.
  84. */
  85. styleOverrides?: Object
  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. _isModerator,
  103. _largeVideo: largeVideo,
  104. _onClick,
  105. _onShowRemoteVideoMenu,
  106. _styles,
  107. _videoTrack: videoTrack,
  108. disablePin,
  109. disableTint,
  110. participant,
  111. renderDisplayName
  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 showRemoteVideoMenu = _isModerator && !participant.local;
  126. return (
  127. <Container
  128. onClick = { disablePin ? undefined : _onClick }
  129. onLongPress = {
  130. showRemoteVideoMenu
  131. ? _onShowRemoteVideoMenu : undefined }
  132. style = { [
  133. styles.thumbnail,
  134. participant.pinned && !disablePin
  135. ? _styles.thumbnailPinned : null,
  136. this.props.styleOverrides || null
  137. ] }
  138. touchFeedback = { false }>
  139. { renderAudio
  140. && <Audio
  141. stream
  142. = { audioTrack.jitsiTrack.getOriginalStream() } /> }
  143. <ParticipantView
  144. avatarSize = { AVATAR_SIZE }
  145. participantId = { participantId }
  146. style = { _styles.participantViewStyle }
  147. tintEnabled = { participantInLargeVideo && !disableTint }
  148. tintStyle = { _styles.activeThumbnailTint }
  149. zOrder = { 1 } />
  150. { renderDisplayName && <DisplayNameLabel participantId = { participantId } /> }
  151. { participant.role === PARTICIPANT_ROLE.MODERATOR
  152. && <View style = { styles.moderatorIndicatorContainer }>
  153. <ModeratorIndicator />
  154. </View> }
  155. <View
  156. style = { [
  157. styles.thumbnailTopIndicatorContainer,
  158. styles.thumbnailTopLeftIndicatorContainer
  159. ] }>
  160. <RaisedHandIndicator participantId = { participant.id } />
  161. { participant.dominantSpeaker
  162. && <DominantSpeakerIndicator /> }
  163. </View>
  164. <View
  165. style = { [
  166. styles.thumbnailTopIndicatorContainer,
  167. styles.thumbnailTopRightIndicatorContainer
  168. ] }>
  169. <ConnectionIndicator participantId = { participant.id } />
  170. </View>
  171. <Container style = { styles.thumbnailIndicatorContainer }>
  172. { audioMuted
  173. && <AudioMutedIndicator /> }
  174. { videoMuted
  175. && <VideoMutedIndicator /> }
  176. </Container>
  177. </Container>
  178. );
  179. }
  180. }
  181. /**
  182. * Maps part of redux actions to component's props.
  183. *
  184. * @param {Function} dispatch - Redux's {@code dispatch} function.
  185. * @param {Props} ownProps - The own props of the component.
  186. * @returns {{
  187. * _onClick: Function,
  188. * _onShowRemoteVideoMenu: Function
  189. * }}
  190. */
  191. function _mapDispatchToProps(dispatch: Function, ownProps): Object {
  192. return {
  193. /**
  194. * Handles click/tap event on the thumbnail.
  195. *
  196. * @protected
  197. * @returns {void}
  198. */
  199. _onClick() {
  200. const { participant } = ownProps;
  201. dispatch(
  202. pinParticipant(participant.pinned ? null : participant.id));
  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. * _isModerator: boolean,
  225. * _largeVideo: Object,
  226. * _styles: StyleType,
  227. * _videoTrack: Track
  228. * }}
  229. */
  230. function _mapStateToProps(state, ownProps) {
  231. // We need read-only access to the state of features/large-video so that the
  232. // filmstrip doesn't render the video of the participant who is rendered on
  233. // the stage i.e. as a large video.
  234. const largeVideo = state['features/large-video'];
  235. const tracks = state['features/base/tracks'];
  236. const id = ownProps.participant.id;
  237. const audioTrack
  238. = getTrackByMediaTypeAndParticipant(tracks, MEDIA_TYPE.AUDIO, id);
  239. const videoTrack
  240. = getTrackByMediaTypeAndParticipant(tracks, MEDIA_TYPE.VIDEO, id);
  241. return {
  242. _audioTrack: audioTrack,
  243. _isModerator: isLocalParticipantModerator(state),
  244. _largeVideo: largeVideo,
  245. _styles: ColorSchemeRegistry.get(state, 'Thumbnail'),
  246. _videoTrack: videoTrack
  247. };
  248. }
  249. export default connect(_mapStateToProps, _mapDispatchToProps)(Thumbnail);