Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

Thumbnail.js 8.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  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 { MEDIA_TYPE, VIDEO_TYPE } from '../../../base/media';
  8. import {
  9. PARTICIPANT_ROLE,
  10. ParticipantView,
  11. getParticipantCount,
  12. isEveryoneModerator,
  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. * Whether local audio (microphone) is muted or not.
  35. */
  36. _audioMuted: 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. * Whether to show the dominant speaker indicator or not.
  51. */
  52. _renderDominantSpeakerIndicator: boolean,
  53. /**
  54. * Whether to show the moderator indicator or not.
  55. */
  56. _renderModeratorIndicator: boolean,
  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. _audioMuted: audioMuted,
  107. _largeVideo: largeVideo,
  108. _onClick,
  109. _onShowRemoteVideoMenu,
  110. _renderDominantSpeakerIndicator: renderDominantSpeakerIndicator,
  111. _renderModeratorIndicator: renderModeratorIndicator,
  112. _styles,
  113. _videoTrack: videoTrack,
  114. disableTint,
  115. participant,
  116. renderDisplayName,
  117. tileView
  118. } = this.props;
  119. const participantId = participant.id;
  120. const participantInLargeVideo
  121. = participantId === largeVideo.participantId;
  122. const videoMuted = !videoTrack || videoTrack.muted;
  123. const isScreenShare = videoTrack && videoTrack.videoType === VIDEO_TYPE.DESKTOP;
  124. return (
  125. <Container
  126. onClick = { _onClick }
  127. onLongPress = { participant.local ? undefined : _onShowRemoteVideoMenu }
  128. style = { [
  129. styles.thumbnail,
  130. participant.pinned && !tileView
  131. ? _styles.thumbnailPinned : null,
  132. this.props.styleOverrides || null
  133. ] }
  134. touchFeedback = { false }>
  135. <ParticipantView
  136. avatarSize = { AVATAR_SIZE }
  137. disableVideo = { isScreenShare }
  138. participantId = { participantId }
  139. style = { _styles.participantViewStyle }
  140. tintEnabled = { participantInLargeVideo && !disableTint }
  141. tintStyle = { _styles.activeThumbnailTint }
  142. zOrder = { 1 } />
  143. { renderDisplayName && <DisplayNameLabel participantId = { participantId } /> }
  144. { renderModeratorIndicator
  145. && <View style = { styles.moderatorIndicatorContainer }>
  146. <ModeratorIndicator />
  147. </View> }
  148. <View
  149. style = { [
  150. styles.thumbnailTopIndicatorContainer,
  151. styles.thumbnailTopLeftIndicatorContainer
  152. ] }>
  153. <RaisedHandIndicator participantId = { participant.id } />
  154. { renderDominantSpeakerIndicator && <DominantSpeakerIndicator /> }
  155. </View>
  156. <View
  157. style = { [
  158. styles.thumbnailTopIndicatorContainer,
  159. styles.thumbnailTopRightIndicatorContainer
  160. ] }>
  161. <ConnectionIndicator participantId = { participant.id } />
  162. </View>
  163. <Container style = { styles.thumbnailIndicatorContainer }>
  164. { audioMuted
  165. && <AudioMutedIndicator /> }
  166. { videoMuted
  167. && <VideoMutedIndicator /> }
  168. </Container>
  169. </Container>
  170. );
  171. }
  172. }
  173. /**
  174. * Maps part of redux actions to component's props.
  175. *
  176. * @param {Function} dispatch - Redux's {@code dispatch} function.
  177. * @param {Props} ownProps - The own props of the component.
  178. * @returns {{
  179. * _onClick: Function,
  180. * _onShowRemoteVideoMenu: Function
  181. * }}
  182. */
  183. function _mapDispatchToProps(dispatch: Function, ownProps): Object {
  184. return {
  185. /**
  186. * Handles click/tap event on the thumbnail.
  187. *
  188. * @protected
  189. * @returns {void}
  190. */
  191. _onClick() {
  192. const { participant, tileView } = ownProps;
  193. if (tileView) {
  194. dispatch(toggleToolboxVisible());
  195. } else {
  196. dispatch(pinParticipant(participant.pinned ? null : participant.id));
  197. }
  198. },
  199. /**
  200. * Handles long press on the thumbnail.
  201. *
  202. * @returns {void}
  203. */
  204. _onShowRemoteVideoMenu() {
  205. const { participant } = ownProps;
  206. dispatch(openDialog(RemoteVideoMenu, {
  207. participant
  208. }));
  209. }
  210. };
  211. }
  212. /**
  213. * Function that maps parts of Redux state tree into component props.
  214. *
  215. * @param {Object} state - Redux state.
  216. * @param {Props} ownProps - Properties of component.
  217. * @returns {Object}
  218. */
  219. function _mapStateToProps(state, ownProps) {
  220. // We need read-only access to the state of features/large-video so that the
  221. // filmstrip doesn't render the video of the participant who is rendered on
  222. // the stage i.e. as a large video.
  223. const largeVideo = state['features/large-video'];
  224. const tracks = state['features/base/tracks'];
  225. const { participant } = ownProps;
  226. const id = participant.id;
  227. const audioTrack
  228. = getTrackByMediaTypeAndParticipant(tracks, MEDIA_TYPE.AUDIO, id);
  229. const videoTrack
  230. = getTrackByMediaTypeAndParticipant(tracks, MEDIA_TYPE.VIDEO, id);
  231. const participantCount = getParticipantCount(state);
  232. const renderDominantSpeakerIndicator = participant.dominantSpeaker && participantCount > 2;
  233. const _isEveryoneModerator = isEveryoneModerator(state);
  234. const renderModeratorIndicator = !_isEveryoneModerator && participant.role === PARTICIPANT_ROLE.MODERATOR;
  235. return {
  236. _audioMuted: audioTrack?.muted ?? true,
  237. _largeVideo: largeVideo,
  238. _renderDominantSpeakerIndicator: renderDominantSpeakerIndicator,
  239. _renderModeratorIndicator: renderModeratorIndicator,
  240. _styles: ColorSchemeRegistry.get(state, 'Thumbnail'),
  241. _videoTrack: videoTrack
  242. };
  243. }
  244. export default connect(_mapStateToProps, _mapDispatchToProps)(Thumbnail);