Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

Thumbnail.js 9.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  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 ConnectionStatusComponent from '../../../remote-video-menu/components/native/ConnectionStatusComponent';
  23. import { toggleToolboxVisible } from '../../../toolbox/actions.native';
  24. import AudioMutedIndicator from './AudioMutedIndicator';
  25. import DominantSpeakerIndicator from './DominantSpeakerIndicator';
  26. import ModeratorIndicator from './ModeratorIndicator';
  27. import RaisedHandIndicator from './RaisedHandIndicator';
  28. import ScreenShareIndicator from './ScreenShareIndicator';
  29. import VideoMutedIndicator from './VideoMutedIndicator';
  30. import styles, { AVATAR_SIZE } from './styles';
  31. /**
  32. * Thumbnail component's property types.
  33. */
  34. type Props = {
  35. /**
  36. * Whether local audio (microphone) is muted or not.
  37. */
  38. _audioMuted: 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. _onThumbnailLongPress: ?Function,
  51. /**
  52. * Whether to show the dominant speaker indicator or not.
  53. */
  54. _renderDominantSpeakerIndicator: boolean,
  55. /**
  56. * Whether to show the moderator indicator or not.
  57. */
  58. _renderModeratorIndicator: boolean,
  59. /**
  60. * The color-schemed stylesheet of the feature.
  61. */
  62. _styles: StyleType,
  63. /**
  64. * The Redux representation of the participant's video track.
  65. */
  66. _videoTrack: Object,
  67. /**
  68. * If true, there will be no color overlay (tint) on the thumbnail
  69. * indicating the participant associated with the thumbnail is displayed on
  70. * large video. By default there will be a tint.
  71. */
  72. disableTint?: boolean,
  73. /**
  74. * Invoked to trigger state changes in Redux.
  75. */
  76. dispatch: Dispatch<any>,
  77. /**
  78. * The Redux representation of the participant to display.
  79. */
  80. participant: Object,
  81. /**
  82. * Whether to display or hide the display name of the participant in the thumbnail.
  83. */
  84. renderDisplayName: ?boolean,
  85. /**
  86. * Optional styling to add or override on the Thumbnail component root.
  87. */
  88. styleOverrides?: Object,
  89. /**
  90. * If true, it tells the thumbnail that it needs to behave differently. E.g. react differently to a single tap.
  91. */
  92. tileView?: boolean
  93. };
  94. /**
  95. * React component for video thumbnail.
  96. *
  97. * @param {Props} props - Properties passed to this functional component.
  98. * @returns {Component} - A React component.
  99. */
  100. function Thumbnail(props: Props) {
  101. const {
  102. _audioMuted: audioMuted,
  103. _largeVideo: largeVideo,
  104. _onClick,
  105. _onThumbnailLongPress,
  106. _renderDominantSpeakerIndicator: renderDominantSpeakerIndicator,
  107. _renderModeratorIndicator: renderModeratorIndicator,
  108. _styles,
  109. _videoTrack: videoTrack,
  110. disableTint,
  111. participant,
  112. renderDisplayName,
  113. tileView
  114. } = props;
  115. const participantId = participant.id;
  116. const participantInLargeVideo
  117. = participantId === largeVideo.participantId;
  118. const videoMuted = !videoTrack || videoTrack.muted;
  119. const isScreenShare = videoTrack && videoTrack.videoType === VIDEO_TYPE.DESKTOP;
  120. return (
  121. <Container
  122. onClick = { _onClick }
  123. onLongPress = { _onThumbnailLongPress }
  124. style = { [
  125. styles.thumbnail,
  126. participant.pinned && !tileView
  127. ? _styles.thumbnailPinned : null,
  128. props.styleOverrides || null
  129. ] }
  130. touchFeedback = { false }>
  131. <ParticipantView
  132. avatarSize = { tileView ? AVATAR_SIZE * 1.5 : AVATAR_SIZE }
  133. disableVideo = { isScreenShare || participant.isFakeParticipant }
  134. participantId = { participantId }
  135. style = { _styles.participantViewStyle }
  136. tintEnabled = { participantInLargeVideo && !disableTint }
  137. tintStyle = { _styles.activeThumbnailTint }
  138. zOrder = { 1 } />
  139. { renderDisplayName && <Container style = { styles.displayNameContainer }>
  140. <DisplayNameLabel participantId = { participantId } />
  141. </Container> }
  142. { renderModeratorIndicator
  143. && <View style = { styles.moderatorIndicatorContainer }>
  144. <ModeratorIndicator />
  145. </View>}
  146. { !participant.isFakeParticipant && <View
  147. style = { [
  148. styles.thumbnailTopIndicatorContainer,
  149. styles.thumbnailTopLeftIndicatorContainer
  150. ] }>
  151. <RaisedHandIndicator participantId = { participant.id } />
  152. { renderDominantSpeakerIndicator && <DominantSpeakerIndicator /> }
  153. </View> }
  154. { !participant.isFakeParticipant && <View
  155. style = { [
  156. styles.thumbnailTopIndicatorContainer,
  157. styles.thumbnailTopRightIndicatorContainer
  158. ] }>
  159. <ConnectionIndicator participantId = { participant.id } />
  160. </View> }
  161. { !participant.isFakeParticipant && <Container style = { styles.thumbnailIndicatorContainer }>
  162. { audioMuted
  163. && <AudioMutedIndicator /> }
  164. { videoMuted
  165. && <VideoMutedIndicator /> }
  166. { isScreenShare
  167. && <ScreenShareIndicator /> }
  168. </Container> }
  169. </Container>
  170. );
  171. }
  172. /**
  173. * Maps part of redux actions to component's props.
  174. *
  175. * @param {Function} dispatch - Redux's {@code dispatch} function.
  176. * @param {Props} ownProps - The own props of the component.
  177. * @returns {{
  178. * _onClick: Function,
  179. * _onShowRemoteVideoMenu: Function
  180. * }}
  181. */
  182. function _mapDispatchToProps(dispatch: Function, ownProps): Object {
  183. return {
  184. /**
  185. * Handles click/tap event on the thumbnail.
  186. *
  187. * @protected
  188. * @returns {void}
  189. */
  190. _onClick() {
  191. const { participant, tileView } = ownProps;
  192. if (tileView) {
  193. dispatch(toggleToolboxVisible());
  194. } else {
  195. dispatch(pinParticipant(participant.pinned ? null : participant.id));
  196. }
  197. },
  198. /**
  199. * Handles long press on the thumbnail.
  200. *
  201. * @returns {void}
  202. */
  203. _onThumbnailLongPress() {
  204. const { participant } = ownProps;
  205. if (participant.local) {
  206. dispatch(openDialog(ConnectionStatusComponent, {
  207. participantID: participant.id
  208. }));
  209. } else {
  210. dispatch(openDialog(RemoteVideoMenu, {
  211. participant
  212. }));
  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 {Object}
  223. */
  224. function _mapStateToProps(state, ownProps) {
  225. // We need read-only access to the state of features/large-video so that the
  226. // filmstrip doesn't render the video of the participant who is rendered on
  227. // the stage i.e. as a large video.
  228. const largeVideo = state['features/large-video'];
  229. const tracks = state['features/base/tracks'];
  230. const { participant } = ownProps;
  231. const id = participant.id;
  232. const audioTrack
  233. = getTrackByMediaTypeAndParticipant(tracks, MEDIA_TYPE.AUDIO, id);
  234. const videoTrack
  235. = getTrackByMediaTypeAndParticipant(tracks, MEDIA_TYPE.VIDEO, id);
  236. const participantCount = getParticipantCount(state);
  237. const renderDominantSpeakerIndicator = participant.dominantSpeaker && participantCount > 2;
  238. const _isEveryoneModerator = isEveryoneModerator(state);
  239. const renderModeratorIndicator = !_isEveryoneModerator && participant.role === PARTICIPANT_ROLE.MODERATOR;
  240. return {
  241. _audioMuted: audioTrack?.muted ?? true,
  242. _largeVideo: largeVideo,
  243. _renderDominantSpeakerIndicator: renderDominantSpeakerIndicator,
  244. _renderModeratorIndicator: renderModeratorIndicator,
  245. _styles: ColorSchemeRegistry.get(state, 'Thumbnail'),
  246. _videoTrack: videoTrack
  247. };
  248. }
  249. export default connect(_mapStateToProps, _mapDispatchToProps)(Thumbnail);