Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

Thumbnail.js 9.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  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 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. * True if the local participant is a moderator.
  42. */
  43. _isModerator: boolean,
  44. /**
  45. * The Redux representation of the state "features/large-video".
  46. */
  47. _largeVideo: Object,
  48. /**
  49. * Handles click/tap event on the thumbnail.
  50. */
  51. _onClick: ?Function,
  52. /**
  53. * Handles long press on the thumbnail.
  54. */
  55. _onShowRemoteVideoMenu: ?Function,
  56. /**
  57. * The color-schemed stylesheet of the feature.
  58. */
  59. _styles: StyleType,
  60. /**
  61. * The Redux representation of the participant's video track.
  62. */
  63. _videoTrack: Object,
  64. /**
  65. * If true, tapping on the thumbnail will not pin the participant to large
  66. * video. By default tapping does pin the participant.
  67. */
  68. disablePin?: boolean,
  69. /**
  70. * If true, there will be no color overlay (tint) on the thumbnail
  71. * indicating the participant associated with the thumbnail is displayed on
  72. * large video. By default there will be a tint.
  73. */
  74. disableTint?: boolean,
  75. /**
  76. * Invoked to trigger state changes in Redux.
  77. */
  78. dispatch: Dispatch<any>,
  79. /**
  80. * The Redux representation of the participant to display.
  81. */
  82. participant: Object,
  83. /**
  84. * Whether to display or hide the display name of the participant in the thumbnail.
  85. */
  86. renderDisplayName: ?boolean,
  87. /**
  88. * Optional styling to add or override on the Thumbnail component root.
  89. */
  90. styleOverrides?: Object
  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. disablePin,
  115. disableTint,
  116. participant,
  117. renderDisplayName
  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 = { disablePin ? undefined : _onClick }
  135. onLongPress = {
  136. showRemoteVideoMenu
  137. ? _onShowRemoteVideoMenu : undefined }
  138. style = { [
  139. styles.thumbnail,
  140. participant.pinned && !disablePin
  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 } = ownProps;
  207. dispatch(
  208. pinParticipant(participant.pinned ? null : participant.id));
  209. },
  210. /**
  211. * Handles long press on the thumbnail.
  212. *
  213. * @returns {void}
  214. */
  215. _onShowRemoteVideoMenu() {
  216. const { participant } = ownProps;
  217. dispatch(openDialog(RemoteVideoMenu, {
  218. participant
  219. }));
  220. }
  221. };
  222. }
  223. /**
  224. * Function that maps parts of Redux state tree into component props.
  225. *
  226. * @param {Object} state - Redux state.
  227. * @param {Props} ownProps - Properties of component.
  228. * @returns {{
  229. * _audioTrack: Track,
  230. * _isModerator: boolean,
  231. * _largeVideo: Object,
  232. * _styles: StyleType,
  233. * _videoTrack: Track
  234. * }}
  235. */
  236. function _mapStateToProps(state, ownProps) {
  237. // We need read-only access to the state of features/large-video so that the
  238. // filmstrip doesn't render the video of the participant who is rendered on
  239. // the stage i.e. as a large video.
  240. const largeVideo = state['features/large-video'];
  241. const tracks = state['features/base/tracks'];
  242. const id = ownProps.participant.id;
  243. const audioTrack
  244. = getTrackByMediaTypeAndParticipant(tracks, MEDIA_TYPE.AUDIO, id);
  245. const videoTrack
  246. = getTrackByMediaTypeAndParticipant(tracks, MEDIA_TYPE.VIDEO, id);
  247. return {
  248. _audioTrack: audioTrack,
  249. _isEveryoneModerator: isEveryoneModerator(state),
  250. _isModerator: isLocalParticipantModerator(state),
  251. _largeVideo: largeVideo,
  252. _styles: ColorSchemeRegistry.get(state, 'Thumbnail'),
  253. _videoTrack: videoTrack
  254. };
  255. }
  256. export default connect(_mapStateToProps, _mapDispatchToProps)(Thumbnail);