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.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. // @flow
  2. import React, { useCallback } 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. getParticipantByIdOrUndefined
  15. } from '../../../base/participants';
  16. import { Container } from '../../../base/react';
  17. import { connect } from '../../../base/redux';
  18. import { StyleType } from '../../../base/styles';
  19. import { getTrackByMediaTypeAndParticipant } from '../../../base/tracks';
  20. import { ConnectionIndicator } from '../../../connection-indicator';
  21. import { DisplayNameLabel } from '../../../display-name';
  22. import { toggleToolboxVisible } from '../../../toolbox/actions.native';
  23. import { RemoteVideoMenu } from '../../../video-menu';
  24. import ConnectionStatusComponent from '../../../video-menu/components/native/ConnectionStatusComponent';
  25. import AudioMutedIndicator from './AudioMutedIndicator';
  26. import DominantSpeakerIndicator from './DominantSpeakerIndicator';
  27. import ModeratorIndicator from './ModeratorIndicator';
  28. import RaisedHandIndicator from './RaisedHandIndicator';
  29. import ScreenShareIndicator from './ScreenShareIndicator';
  30. import VideoMutedIndicator from './VideoMutedIndicator';
  31. import styles, { AVATAR_SIZE } from './styles';
  32. /**
  33. * Thumbnail component's property types.
  34. */
  35. type Props = {
  36. /**
  37. * Whether local audio (microphone) is muted or not.
  38. */
  39. _audioMuted: boolean,
  40. /**
  41. * The Redux representation of the state "features/large-video".
  42. */
  43. _largeVideo: Object,
  44. /**
  45. * The Redux representation of the participant to display.
  46. */
  47. _participant: Object,
  48. /**
  49. * Whether to show the dominant speaker indicator or not.
  50. */
  51. _renderDominantSpeakerIndicator: boolean,
  52. /**
  53. * Whether to show the moderator indicator or not.
  54. */
  55. _renderModeratorIndicator: boolean,
  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, 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 ID of the participant related to the thumbnail.
  76. */
  77. participantID: ?string,
  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. * If true, it tells the thumbnail that it needs to behave differently. E.g. react differently to a single tap.
  88. */
  89. tileView?: boolean
  90. };
  91. /**
  92. * React component for video thumbnail.
  93. *
  94. * @param {Props} props - Properties passed to this functional component.
  95. * @returns {Component} - A React component.
  96. */
  97. function Thumbnail(props: Props) {
  98. const {
  99. _audioMuted: audioMuted,
  100. _largeVideo: largeVideo,
  101. _renderDominantSpeakerIndicator: renderDominantSpeakerIndicator,
  102. _renderModeratorIndicator: renderModeratorIndicator,
  103. _participant: participant,
  104. _styles,
  105. _videoTrack: videoTrack,
  106. dispatch,
  107. disableTint,
  108. renderDisplayName,
  109. tileView
  110. } = props;
  111. const participantId = participant.id;
  112. const participantInLargeVideo
  113. = participantId === largeVideo.participantId;
  114. const videoMuted = !videoTrack || videoTrack.muted;
  115. const isScreenShare = videoTrack && videoTrack.videoType === VIDEO_TYPE.DESKTOP;
  116. const onClick = useCallback(() => {
  117. if (tileView) {
  118. dispatch(toggleToolboxVisible());
  119. } else {
  120. dispatch(pinParticipant(participant.pinned ? null : participant.id));
  121. }
  122. }, [ participant, tileView, dispatch ]);
  123. const onThumbnailLongPress = useCallback(() => {
  124. if (participant.local) {
  125. dispatch(openDialog(ConnectionStatusComponent, {
  126. participantID: participant.id
  127. }));
  128. } else {
  129. dispatch(openDialog(RemoteVideoMenu, {
  130. participant
  131. }));
  132. }
  133. }, [ participant, dispatch ]);
  134. return (
  135. <Container
  136. onClick = { onClick }
  137. onLongPress = { onThumbnailLongPress }
  138. style = { [
  139. styles.thumbnail,
  140. participant.pinned && !tileView
  141. ? _styles.thumbnailPinned : null,
  142. props.styleOverrides || null
  143. ] }
  144. touchFeedback = { false }>
  145. <ParticipantView
  146. avatarSize = { tileView ? AVATAR_SIZE * 1.5 : AVATAR_SIZE }
  147. disableVideo = { isScreenShare || participant.isFakeParticipant }
  148. participantId = { participantId }
  149. style = { _styles.participantViewStyle }
  150. tintEnabled = { participantInLargeVideo && !disableTint }
  151. tintStyle = { _styles.activeThumbnailTint }
  152. zOrder = { 1 } />
  153. { renderDisplayName && <Container style = { styles.displayNameContainer }>
  154. <DisplayNameLabel participantId = { participantId } />
  155. </Container> }
  156. { renderModeratorIndicator
  157. && <View style = { styles.moderatorIndicatorContainer }>
  158. <ModeratorIndicator />
  159. </View>}
  160. { !participant.isFakeParticipant && <View
  161. style = { [
  162. styles.thumbnailTopIndicatorContainer,
  163. styles.thumbnailTopLeftIndicatorContainer
  164. ] }>
  165. <RaisedHandIndicator participantId = { participant.id } />
  166. { renderDominantSpeakerIndicator && <DominantSpeakerIndicator /> }
  167. </View> }
  168. { !participant.isFakeParticipant && <View
  169. style = { [
  170. styles.thumbnailTopIndicatorContainer,
  171. styles.thumbnailTopRightIndicatorContainer
  172. ] }>
  173. <ConnectionIndicator participantId = { participant.id } />
  174. </View> }
  175. { !participant.isFakeParticipant && <Container style = { styles.thumbnailIndicatorContainer }>
  176. { audioMuted
  177. && <AudioMutedIndicator /> }
  178. { videoMuted
  179. && <VideoMutedIndicator /> }
  180. { isScreenShare
  181. && <ScreenShareIndicator /> }
  182. </Container> }
  183. </Container>
  184. );
  185. }
  186. /**
  187. * Function that maps parts of Redux state tree into component props.
  188. *
  189. * @param {Object} state - Redux state.
  190. * @param {Props} ownProps - Properties of component.
  191. * @returns {Object}
  192. */
  193. function _mapStateToProps(state, ownProps) {
  194. // We need read-only access to the state of features/large-video so that the
  195. // filmstrip doesn't render the video of the participant who is rendered on
  196. // the stage i.e. as a large video.
  197. const largeVideo = state['features/large-video'];
  198. const tracks = state['features/base/tracks'];
  199. const { participantID } = ownProps;
  200. const participant = getParticipantByIdOrUndefined(state, participantID);
  201. const id = participant?.id;
  202. const audioTrack
  203. = getTrackByMediaTypeAndParticipant(tracks, MEDIA_TYPE.AUDIO, id);
  204. const videoTrack
  205. = getTrackByMediaTypeAndParticipant(tracks, MEDIA_TYPE.VIDEO, id);
  206. const participantCount = getParticipantCount(state);
  207. const renderDominantSpeakerIndicator = participant && participant.dominantSpeaker && participantCount > 2;
  208. const _isEveryoneModerator = isEveryoneModerator(state);
  209. const renderModeratorIndicator = !_isEveryoneModerator
  210. && participant && participant.role === PARTICIPANT_ROLE.MODERATOR;
  211. return {
  212. _audioMuted: audioTrack?.muted ?? true,
  213. _largeVideo: largeVideo,
  214. _participant: participant,
  215. _renderDominantSpeakerIndicator: renderDominantSpeakerIndicator,
  216. _renderModeratorIndicator: renderModeratorIndicator,
  217. _styles: ColorSchemeRegistry.get(state, 'Thumbnail'),
  218. _videoTrack: videoTrack
  219. };
  220. }
  221. export default connect(_mapStateToProps)(Thumbnail);