您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

Thumbnail.js 9.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  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. // It seems that on leave the Thumbnail for the left participant can be re-rendered.
  120. // This will happen when mapStateToProps is executed before the remoteParticipants list in redux is updated.
  121. if (typeof participant === 'undefined') {
  122. return null;
  123. }
  124. const participantId = participant.id;
  125. const participantInLargeVideo
  126. = participantId === largeVideo.participantId;
  127. const videoMuted = !videoTrack || videoTrack.muted;
  128. const isScreenShare = videoTrack && videoTrack.videoType === VIDEO_TYPE.DESKTOP;
  129. const onClick = useCallback(() => {
  130. if (tileView) {
  131. dispatch(toggleToolboxVisible());
  132. } else {
  133. dispatch(pinParticipant(participant.pinned ? null : participant.id));
  134. }
  135. }, [ participant, tileView, dispatch ]);
  136. const onThumbnailLongPress = useCallback(() => {
  137. if (participant.local) {
  138. dispatch(openDialog(ConnectionStatusComponent, {
  139. participantID: participant.id
  140. }));
  141. } else if (participant.isFakeParticipant) {
  142. if (_localVideoOwner) {
  143. dispatch(openDialog(SharedVideoMenu, {
  144. participant
  145. }));
  146. }
  147. } else {
  148. dispatch(openDialog(RemoteVideoMenu, {
  149. participant
  150. }));
  151. }
  152. }, [ participant, dispatch ]);
  153. return (
  154. <Container
  155. onClick = { onClick }
  156. onLongPress = { onThumbnailLongPress }
  157. style = { [
  158. styles.thumbnail,
  159. participant.pinned && !tileView
  160. ? _styles.thumbnailPinned : null,
  161. props.styleOverrides || null
  162. ] }
  163. touchFeedback = { false }>
  164. <ParticipantView
  165. avatarSize = { tileView ? AVATAR_SIZE * 1.5 : AVATAR_SIZE }
  166. disableVideo = { isScreenShare || participant.isFakeParticipant }
  167. participantId = { participantId }
  168. style = { _styles.participantViewStyle }
  169. tintEnabled = { participantInLargeVideo && !disableTint }
  170. tintStyle = { _styles.activeThumbnailTint }
  171. zOrder = { 1 } />
  172. { renderDisplayName && <Container style = { styles.displayNameContainer }>
  173. <DisplayNameLabel participantId = { participantId } />
  174. </Container> }
  175. { renderModeratorIndicator
  176. && <View style = { styles.moderatorIndicatorContainer }>
  177. <ModeratorIndicator />
  178. </View>}
  179. { !participant.isFakeParticipant && <View
  180. style = { [
  181. styles.thumbnailTopIndicatorContainer,
  182. styles.thumbnailTopLeftIndicatorContainer
  183. ] }>
  184. <RaisedHandIndicator participantId = { participant.id } />
  185. { renderDominantSpeakerIndicator && <DominantSpeakerIndicator /> }
  186. </View> }
  187. { !participant.isFakeParticipant && <View
  188. style = { [
  189. styles.thumbnailTopIndicatorContainer,
  190. styles.thumbnailTopRightIndicatorContainer
  191. ] }>
  192. <ConnectionIndicator participantId = { participant.id } />
  193. </View> }
  194. { !participant.isFakeParticipant && <Container style = { styles.thumbnailIndicatorContainer }>
  195. { audioMuted
  196. && <AudioMutedIndicator /> }
  197. { videoMuted
  198. && <VideoMutedIndicator /> }
  199. { isScreenShare
  200. && <ScreenShareIndicator /> }
  201. </Container> }
  202. </Container>
  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 { ownerId } = state['features/shared-video'];
  218. const tracks = state['features/base/tracks'];
  219. const { participantID } = ownProps;
  220. const participant = getParticipantByIdOrUndefined(state, participantID);
  221. const localParticipantId = getLocalParticipant(state).id;
  222. const id = participant?.id;
  223. const audioTrack
  224. = getTrackByMediaTypeAndParticipant(tracks, MEDIA_TYPE.AUDIO, id);
  225. const videoTrack
  226. = getTrackByMediaTypeAndParticipant(tracks, MEDIA_TYPE.VIDEO, id);
  227. const participantCount = getParticipantCount(state);
  228. const renderDominantSpeakerIndicator = participant && participant.dominantSpeaker && participantCount > 2;
  229. const _isEveryoneModerator = isEveryoneModerator(state);
  230. const renderModeratorIndicator = !_isEveryoneModerator
  231. && participant && participant.role === PARTICIPANT_ROLE.MODERATOR;
  232. return {
  233. _audioMuted: audioTrack?.muted ?? true,
  234. _largeVideo: largeVideo,
  235. _localVideoOwner: Boolean(ownerId === localParticipantId),
  236. _participant: participant,
  237. _renderDominantSpeakerIndicator: renderDominantSpeakerIndicator,
  238. _renderModeratorIndicator: renderModeratorIndicator,
  239. _styles: ColorSchemeRegistry.get(state, 'Thumbnail'),
  240. _videoTrack: videoTrack
  241. };
  242. }
  243. export default connect(_mapStateToProps)(Thumbnail);