jiti-meet/react/features/filmstrip/components/native/Thumbnail.js

285 lines
9.1 KiB
JavaScript
Raw Normal View History

// @flow
import React from 'react';
2019-03-29 13:26:49 +00:00
import { View } from 'react-native';
2019-03-19 15:42:25 +00:00
import type { Dispatch } from 'redux';
import { ColorSchemeRegistry } from '../../../base/color-scheme';
2018-12-19 18:40:17 +00:00
import { openDialog } from '../../../base/dialog';
import { MEDIA_TYPE, VIDEO_TYPE } from '../../../base/media';
import {
PARTICIPANT_ROLE,
ParticipantView,
getParticipantCount,
isEveryoneModerator,
pinParticipant
} from '../../../base/participants';
import { Container } from '../../../base/react';
2019-03-21 16:38:29 +00:00
import { connect } from '../../../base/redux';
import { StyleType } from '../../../base/styles';
import { getTrackByMediaTypeAndParticipant } from '../../../base/tracks';
2019-04-15 16:23:28 +00:00
import { ConnectionIndicator } from '../../../connection-indicator';
import { DisplayNameLabel } from '../../../display-name';
2018-12-19 18:40:17 +00:00
import { RemoteVideoMenu } from '../../../remote-video-menu';
2020-12-22 09:12:52 +00:00
import ConnectionStatusComponent from '../../../remote-video-menu/components/native/ConnectionStatusComponent';
2020-07-24 12:14:33 +00:00
import { toggleToolboxVisible } from '../../../toolbox/actions.native';
2018-12-19 18:40:17 +00:00
import AudioMutedIndicator from './AudioMutedIndicator';
import DominantSpeakerIndicator from './DominantSpeakerIndicator';
import ModeratorIndicator from './ModeratorIndicator';
2019-03-27 10:23:41 +00:00
import RaisedHandIndicator from './RaisedHandIndicator';
import ScreenShareIndicator from './ScreenShareIndicator';
import VideoMutedIndicator from './VideoMutedIndicator';
2020-05-20 10:57:03 +00:00
import styles, { AVATAR_SIZE } from './styles';
/**
* Thumbnail component's property types.
*/
type Props = {
/**
* Whether local audio (microphone) is muted or not.
*/
_audioMuted: boolean,
/**
* The Redux representation of the state "features/large-video".
*/
_largeVideo: Object,
2019-01-05 16:49:21 +00:00
/**
* Handles click/tap event on the thumbnail.
*/
_onClick: ?Function,
/**
* Handles long press on the thumbnail.
*/
2020-12-22 09:12:52 +00:00
_onThumbnailLongPress: ?Function,
2019-01-05 16:49:21 +00:00
/**
* Whether to show the dominant speaker indicator or not.
*/
2019-09-13 09:51:49 +00:00
_renderDominantSpeakerIndicator: boolean,
/**
* Whether to show the moderator indicator or not.
*/
_renderModeratorIndicator: boolean,
/**
* The color-schemed stylesheet of the feature.
*/
_styles: StyleType,
/**
* The Redux representation of the participant's video track.
*/
_videoTrack: Object,
/**
* If true, there will be no color overlay (tint) on the thumbnail
* indicating the participant associated with the thumbnail is displayed on
* large video. By default there will be a tint.
*/
disableTint?: boolean,
/**
* Invoked to trigger state changes in Redux.
*/
2019-03-19 15:42:25 +00:00
dispatch: Dispatch<any>,
/**
* The Redux representation of the participant to display.
*/
participant: Object,
/**
* Whether to display or hide the display name of the participant in the thumbnail.
*/
renderDisplayName: ?boolean,
/**
* Optional styling to add or override on the Thumbnail component root.
*/
styleOverrides?: Object,
/**
* If true, it tells the thumbnail that it needs to behave differently. E.g. react differently to a single tap.
*/
tileView?: boolean
};
/**
* React component for video thumbnail.
*
* @param {Props} props - Properties passed to this functional component.
* @returns {Component} - A React component.
*/
function Thumbnail(props: Props) {
const {
_audioMuted: audioMuted,
_largeVideo: largeVideo,
_onClick,
2020-12-22 09:12:52 +00:00
_onThumbnailLongPress,
_renderDominantSpeakerIndicator: renderDominantSpeakerIndicator,
_renderModeratorIndicator: renderModeratorIndicator,
_styles,
_videoTrack: videoTrack,
disableTint,
participant,
renderDisplayName,
tileView
} = props;
const participantId = participant.id;
const participantInLargeVideo
= participantId === largeVideo.participantId;
const videoMuted = !videoTrack || videoTrack.muted;
const isScreenShare = videoTrack && videoTrack.videoType === VIDEO_TYPE.DESKTOP;
return (
<Container
onClick = { _onClick }
2020-12-22 09:12:52 +00:00
onLongPress = { _onThumbnailLongPress }
style = { [
styles.thumbnail,
participant.pinned && !tileView
? _styles.thumbnailPinned : null,
2019-09-16 11:15:17 +00:00
props.styleOverrides || null
] }
touchFeedback = { false }>
<ParticipantView
avatarSize = { tileView ? AVATAR_SIZE * 1.5 : AVATAR_SIZE }
2020-06-12 10:15:16 +00:00
disableVideo = { isScreenShare || participant.isFakeParticipant }
participantId = { participantId }
style = { _styles.participantViewStyle }
tintEnabled = { participantInLargeVideo && !disableTint }
tintStyle = { _styles.activeThumbnailTint }
zOrder = { 1 } />
{ renderDisplayName && <Container style = { styles.displayNameContainer }>
<DisplayNameLabel participantId = { participantId } />
</Container> }
{ renderModeratorIndicator
&& <View style = { styles.moderatorIndicatorContainer }>
<ModeratorIndicator />
2020-06-12 10:15:16 +00:00
</View>}
2020-06-12 10:15:16 +00:00
{ !participant.isFakeParticipant && <View
style = { [
styles.thumbnailTopIndicatorContainer,
styles.thumbnailTopLeftIndicatorContainer
] }>
<RaisedHandIndicator participantId = { participant.id } />
{ renderDominantSpeakerIndicator && <DominantSpeakerIndicator /> }
2020-06-12 10:15:16 +00:00
</View> }
2020-06-12 10:15:16 +00:00
{ !participant.isFakeParticipant && <View
style = { [
styles.thumbnailTopIndicatorContainer,
styles.thumbnailTopRightIndicatorContainer
] }>
<ConnectionIndicator participantId = { participant.id } />
2020-06-12 10:15:16 +00:00
</View> }
2020-06-12 10:15:16 +00:00
{ !participant.isFakeParticipant && <Container style = { styles.thumbnailIndicatorContainer }>
{ audioMuted
&& <AudioMutedIndicator /> }
{ videoMuted
&& <VideoMutedIndicator /> }
{ isScreenShare
&& <ScreenShareIndicator /> }
2020-06-12 10:15:16 +00:00
</Container> }
</Container>
);
2019-01-05 16:49:21 +00:00
}
2019-01-05 16:49:21 +00:00
/**
* Maps part of redux actions to component's props.
*
* @param {Function} dispatch - Redux's {@code dispatch} function.
* @param {Props} ownProps - The own props of the component.
* @returns {{
* _onClick: Function,
* _onShowRemoteVideoMenu: Function
* }}
*/
function _mapDispatchToProps(dispatch: Function, ownProps): Object {
return {
/**
* Handles click/tap event on the thumbnail.
*
* @protected
* @returns {void}
*/
_onClick() {
const { participant, tileView } = ownProps;
2019-01-05 16:49:21 +00:00
if (tileView) {
dispatch(toggleToolboxVisible());
} else {
dispatch(pinParticipant(participant.pinned ? null : participant.id));
}
2019-01-05 16:49:21 +00:00
},
/**
* Handles long press on the thumbnail.
*
* @returns {void}
*/
2020-12-22 09:12:52 +00:00
_onThumbnailLongPress() {
2019-01-05 16:49:21 +00:00
const { participant } = ownProps;
2020-12-22 09:12:52 +00:00
if (participant.local) {
dispatch(openDialog(ConnectionStatusComponent, {
participantID: participant.id
}));
} else {
dispatch(openDialog(RemoteVideoMenu, {
participant
}));
}
2019-01-05 16:49:21 +00:00
}
};
}
/**
* Function that maps parts of Redux state tree into component props.
*
* @param {Object} state - Redux state.
2019-01-05 16:49:21 +00:00
* @param {Props} ownProps - Properties of component.
* @returns {Object}
*/
function _mapStateToProps(state, ownProps) {
2017-01-17 14:44:50 +00:00
// We need read-only access to the state of features/large-video so that the
// filmstrip doesn't render the video of the participant who is rendered on
// the stage i.e. as a large video.
2017-01-17 14:44:50 +00:00
const largeVideo = state['features/large-video'];
const tracks = state['features/base/tracks'];
2019-09-13 09:51:49 +00:00
const { participant } = ownProps;
const id = participant.id;
const audioTrack
= getTrackByMediaTypeAndParticipant(tracks, MEDIA_TYPE.AUDIO, id);
const videoTrack
= getTrackByMediaTypeAndParticipant(tracks, MEDIA_TYPE.VIDEO, id);
const participantCount = getParticipantCount(state);
2019-09-13 09:51:49 +00:00
const renderDominantSpeakerIndicator = participant.dominantSpeaker && participantCount > 2;
const _isEveryoneModerator = isEveryoneModerator(state);
const renderModeratorIndicator = !_isEveryoneModerator && participant.role === PARTICIPANT_ROLE.MODERATOR;
return {
_audioMuted: audioTrack?.muted ?? true,
_largeVideo: largeVideo,
2019-09-13 09:51:49 +00:00
_renderDominantSpeakerIndicator: renderDominantSpeakerIndicator,
_renderModeratorIndicator: renderModeratorIndicator,
_styles: ColorSchemeRegistry.get(state, 'Thumbnail'),
_videoTrack: videoTrack
};
}
2019-01-05 16:49:21 +00:00
export default connect(_mapStateToProps, _mapDispatchToProps)(Thumbnail);