import React, { useMemo } from 'react';
import {
Pressable,
StyleSheet,
Text,
View,
ActivityIndicator,
} from 'react-native';
import {
BadNetwork,
MicOff,
PinVertical,
ScreenShareIndicator,
VideoSlash,
} from '../../../icons';
import {
useCall,
useI18n,
useIsAudioConnecting,
useIsVideoConnecting,
} from '@stream-io/video-react-bindings';
import { ComponentTestIds } from '../../../constants/TestIds';
import { type ParticipantViewProps } from './ParticipantView';
import { Z_INDEX } from '../../../constants';
import { hasAudio, hasPausedTrack, hasVideo } from '@stream-io/video-client';
import { useTheme } from '../../../contexts/ThemeContext';
import SpeechIndicator from './SpeechIndicator';
/**
* Props for the ParticipantLabel component.
*/
export type ParticipantLabelProps = Pick<
ParticipantViewProps,
'trackType' | 'participant'
>;
/**
* This component is used to display the participant label that contains the participant name, video/audio mute/unmute status.
*/
export const ParticipantLabel = ({
participant,
trackType,
}: ParticipantLabelProps) => {
const {
theme: {
colors,
typefaces,
variants: { iconSizes },
participantLabel: {
container,
userNameLabel,
audioMutedIconContainer,
videoMutedIconContainer,
pinIconContainer,
screenShareIconContainer,
},
},
} = useTheme();
const styles = useStyles();
const { name, userId, pin, sessionId, isLocalParticipant } = participant;
const call = useCall();
const { t } = useI18n();
const participantName = name ?? userId;
const participantLabel = isLocalParticipant ? t('You') : participantName;
const isAudioMuted = !hasAudio(participant);
const isVideoMuted = !hasVideo(participant);
const isTrackPaused = trackType && hasPausedTrack(participant, trackType);
const isAudioConnecting = useIsAudioConnecting(participant);
const isVideoConnecting = useIsVideoConnecting(participant);
if (trackType === 'screenShareTrack') {
const screenShareText = isLocalParticipant
? t('You are sharing your screen')
: t('{{ userName }} is sharing their screen', {
userName: participantName,
});
return (
{screenShareText}
);
}
return (
{(isAudioConnecting || isVideoConnecting) && (
)}
{participantLabel}
{isAudioMuted && (
)}
{isVideoMuted && (
)}
{isTrackPaused && (
)}
{pin && (
call?.unpin(sessionId) : undefined}
>
)}
);
};
const useStyles = () => {
const { theme } = useTheme();
return useMemo(
() =>
StyleSheet.create({
indicatorWrapper: {
marginLeft: theme.variants.spacingSizes.sm,
},
wrapper: {
flexDirection: 'row',
},
container: {
flexDirection: 'row',
alignItems: 'center',
padding: theme.variants.spacingSizes.sm,
maxHeight: 30,
borderTopRightRadius: 5,
marginBottom: -2,
flexShrink: 1,
zIndex: Z_INDEX.IN_FRONT,
},
userNameLabel: {
flexShrink: 1,
marginTop: 3,
fontSize: 13,
fontWeight: '400',
color: theme.colors.textPrimary,
},
connectingIndicator: {
marginRight: theme.variants.spacingSizes.sm,
justifyContent: 'center',
},
screenShareIconContainer: {
marginRight: theme.variants.spacingSizes.sm,
justifyContent: 'center',
},
audioMutedIconContainer: {
marginLeft: theme.variants.spacingSizes.xs,
justifyContent: 'center',
},
videoMutedIconContainer: {
marginLeft: theme.variants.spacingSizes.xs,
justifyContent: 'center',
},
trackPausedIconContainer: {
marginLeft: theme.variants.spacingSizes.xs,
justifyContent: 'center',
},
pinIconContainer: {
marginLeft: theme.variants.spacingSizes.xs,
justifyContent: 'center',
},
}),
[theme],
);
};