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 8.6KB

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