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

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