2022-08-25 11:35:19 +00:00
|
|
|
/* eslint-disable lines-around-comment */
|
2022-09-13 07:36:00 +00:00
|
|
|
|
|
|
|
import { Theme } from '@mui/material';
|
2022-08-25 11:35:19 +00:00
|
|
|
import React, { ReactElement, useCallback } from 'react';
|
|
|
|
import { WithTranslation } from 'react-i18next';
|
2022-09-13 07:36:00 +00:00
|
|
|
import { makeStyles } from 'tss-react/mui';
|
2021-04-21 13:48:05 +00:00
|
|
|
|
2022-08-25 11:35:19 +00:00
|
|
|
// @ts-ignore
|
2021-07-12 15:14:38 +00:00
|
|
|
import { Avatar } from '../../../base/avatar';
|
2022-09-06 17:32:20 +00:00
|
|
|
import ListItem from '../../../base/components/participants-pane-list/ListItem';
|
|
|
|
import { translate } from '../../../base/i18n/functions';
|
2022-09-13 07:36:00 +00:00
|
|
|
import { withPixelLineHeight } from '../../../base/styles/functions.web';
|
2021-04-21 13:48:05 +00:00
|
|
|
import {
|
2021-08-18 12:10:16 +00:00
|
|
|
ACTION_TRIGGER,
|
|
|
|
AudioStateIcons,
|
|
|
|
MEDIA_STATE,
|
|
|
|
type ActionTrigger,
|
2022-09-13 07:36:00 +00:00
|
|
|
VideoStateIcons,
|
|
|
|
MediaState
|
2021-08-18 12:10:16 +00:00
|
|
|
} from '../../constants';
|
2021-04-21 13:48:05 +00:00
|
|
|
|
|
|
|
import { RaisedHandIndicator } from './RaisedHandIndicator';
|
|
|
|
|
2022-08-25 11:35:19 +00:00
|
|
|
interface Props extends WithTranslation {
|
2021-04-21 13:48:05 +00:00
|
|
|
|
|
|
|
/**
|
2021-11-04 21:10:43 +00:00
|
|
|
* Type of trigger for the participant actions.
|
2021-04-21 13:48:05 +00:00
|
|
|
*/
|
2022-09-08 09:52:36 +00:00
|
|
|
actionsTrigger?: ActionTrigger;
|
2021-04-21 13:48:05 +00:00
|
|
|
|
|
|
|
/**
|
2021-11-04 21:10:43 +00:00
|
|
|
* Media state for audio.
|
2021-04-21 13:48:05 +00:00
|
|
|
*/
|
2022-09-08 09:52:36 +00:00
|
|
|
audioMediaState?: MediaState;
|
2021-04-21 13:48:05 +00:00
|
|
|
|
|
|
|
/**
|
2021-11-04 21:10:43 +00:00
|
|
|
* React children.
|
2021-04-21 13:48:05 +00:00
|
|
|
*/
|
2022-09-08 09:52:36 +00:00
|
|
|
children?: ReactElement | boolean;
|
2021-04-21 13:48:05 +00:00
|
|
|
|
2021-09-28 08:46:20 +00:00
|
|
|
/**
|
|
|
|
* Whether or not to disable the moderator indicator.
|
|
|
|
*/
|
2022-09-08 09:52:36 +00:00
|
|
|
disableModeratorIndicator?: boolean;
|
2021-09-28 08:46:20 +00:00
|
|
|
|
2021-07-09 12:36:19 +00:00
|
|
|
/**
|
|
|
|
* The name of the participant. Used for showing lobby names.
|
|
|
|
*/
|
2022-09-08 09:52:36 +00:00
|
|
|
displayName?: string;
|
2021-07-09 12:36:19 +00:00
|
|
|
|
2021-04-21 13:48:05 +00:00
|
|
|
/**
|
2021-11-04 21:10:43 +00:00
|
|
|
* Is this item highlighted/raised.
|
2021-04-21 13:48:05 +00:00
|
|
|
*/
|
2022-09-08 09:52:36 +00:00
|
|
|
isHighlighted?: boolean;
|
2021-04-21 13:48:05 +00:00
|
|
|
|
2021-09-15 08:28:44 +00:00
|
|
|
/**
|
|
|
|
* Whether or not the participant is a moderator.
|
|
|
|
*/
|
2022-09-08 09:52:36 +00:00
|
|
|
isModerator?: boolean;
|
2021-09-15 08:28:44 +00:00
|
|
|
|
2021-05-17 08:10:17 +00:00
|
|
|
/**
|
2021-07-09 12:36:19 +00:00
|
|
|
* True if the participant is local.
|
2021-05-17 08:10:17 +00:00
|
|
|
*/
|
2022-09-08 09:52:36 +00:00
|
|
|
local?: boolean;
|
2021-09-10 11:05:16 +00:00
|
|
|
|
|
|
|
/**
|
2022-08-25 11:35:19 +00:00
|
|
|
* Callback for when the mouse leaves this component.
|
2021-09-10 11:05:16 +00:00
|
|
|
*/
|
2022-09-08 09:52:36 +00:00
|
|
|
onLeave?: (e?: React.MouseEvent) => void;
|
2021-05-17 08:10:17 +00:00
|
|
|
|
2021-04-21 13:48:05 +00:00
|
|
|
/**
|
2022-08-25 11:35:19 +00:00
|
|
|
* Opens a drawer with participant actions.
|
2021-04-21 13:48:05 +00:00
|
|
|
*/
|
2022-09-08 09:52:36 +00:00
|
|
|
openDrawerForParticipant?: Function;
|
2021-04-21 13:48:05 +00:00
|
|
|
|
2021-09-10 11:05:16 +00:00
|
|
|
/**
|
|
|
|
* If an overflow drawer can be opened.
|
|
|
|
*/
|
2022-09-08 09:52:36 +00:00
|
|
|
overflowDrawer?: boolean;
|
2021-09-10 11:05:16 +00:00
|
|
|
|
2021-04-21 13:48:05 +00:00
|
|
|
/**
|
2021-07-09 12:36:19 +00:00
|
|
|
* The ID of the participant.
|
|
|
|
*/
|
2022-09-08 09:52:36 +00:00
|
|
|
participantID: string;
|
2021-07-09 12:36:19 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* True if the participant have raised hand.
|
2021-04-21 13:48:05 +00:00
|
|
|
*/
|
2022-09-08 09:52:36 +00:00
|
|
|
raisedHand?: boolean;
|
2021-04-21 13:48:05 +00:00
|
|
|
|
|
|
|
/**
|
2021-11-04 21:10:43 +00:00
|
|
|
* Media state for video.
|
2021-04-21 13:48:05 +00:00
|
|
|
*/
|
2022-09-08 09:52:36 +00:00
|
|
|
videoMediaState?: MediaState;
|
2021-07-09 12:36:19 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The translated "you" text.
|
|
|
|
*/
|
2022-09-08 09:52:36 +00:00
|
|
|
youText?: string;
|
2021-04-21 13:48:05 +00:00
|
|
|
}
|
|
|
|
|
2022-09-13 07:36:00 +00:00
|
|
|
const useStyles = makeStyles()((theme: Theme) => {
|
2021-10-22 13:23:52 +00:00
|
|
|
return {
|
|
|
|
nameContainer: {
|
|
|
|
display: 'flex',
|
|
|
|
flex: 1,
|
|
|
|
overflow: 'hidden'
|
|
|
|
},
|
|
|
|
|
|
|
|
name: {
|
|
|
|
overflow: 'hidden',
|
|
|
|
textOverflow: 'ellipsis',
|
|
|
|
whiteSpace: 'nowrap'
|
|
|
|
},
|
|
|
|
|
|
|
|
moderatorLabel: {
|
2022-09-13 07:36:00 +00:00
|
|
|
...withPixelLineHeight(theme.typography.labelRegular),
|
2021-10-22 13:23:52 +00:00
|
|
|
color: theme.palette.text03
|
|
|
|
}
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
2021-07-09 12:36:19 +00:00
|
|
|
/**
|
|
|
|
* A component representing a participant entry in ParticipantPane and Lobby.
|
|
|
|
*
|
|
|
|
* @param {Props} props - The props of the component.
|
|
|
|
* @returns {ReactNode}
|
|
|
|
*/
|
2021-09-15 08:28:44 +00:00
|
|
|
function ParticipantItem({
|
2021-06-23 11:23:44 +00:00
|
|
|
actionsTrigger = ACTION_TRIGGER.HOVER,
|
|
|
|
audioMediaState = MEDIA_STATE.NONE,
|
2021-09-28 08:46:20 +00:00
|
|
|
children,
|
|
|
|
disableModeratorIndicator,
|
2021-07-09 12:36:19 +00:00
|
|
|
displayName,
|
2021-09-28 08:46:20 +00:00
|
|
|
isHighlighted,
|
|
|
|
isModerator,
|
2021-07-09 12:36:19 +00:00
|
|
|
local,
|
2021-09-28 08:46:20 +00:00
|
|
|
onLeave,
|
2021-09-10 11:05:16 +00:00
|
|
|
openDrawerForParticipant,
|
|
|
|
overflowDrawer,
|
2021-09-28 08:46:20 +00:00
|
|
|
participantID,
|
2021-07-09 12:36:19 +00:00
|
|
|
raisedHand,
|
2021-09-15 08:28:44 +00:00
|
|
|
t,
|
2021-09-28 08:46:20 +00:00
|
|
|
videoMediaState = MEDIA_STATE.NONE,
|
2021-07-09 12:36:19 +00:00
|
|
|
youText
|
|
|
|
}: Props) {
|
2021-09-10 11:05:16 +00:00
|
|
|
const onClick = useCallback(
|
2022-09-08 09:52:36 +00:00
|
|
|
() => openDrawerForParticipant?.({
|
2021-09-10 11:05:16 +00:00
|
|
|
participantID,
|
|
|
|
displayName
|
2022-08-25 11:35:19 +00:00
|
|
|
}), []);
|
2021-04-21 13:48:05 +00:00
|
|
|
|
2022-09-13 07:36:00 +00:00
|
|
|
const { classes: styles } = useStyles();
|
2021-10-22 13:23:52 +00:00
|
|
|
|
|
|
|
const icon = (
|
|
|
|
<Avatar
|
|
|
|
className = 'participant-avatar'
|
2021-09-14 15:31:30 +00:00
|
|
|
displayName = { displayName }
|
2021-10-22 13:23:52 +00:00
|
|
|
participantId = { participantID }
|
|
|
|
size = { 32 } />
|
|
|
|
);
|
|
|
|
|
|
|
|
const text = (
|
|
|
|
<>
|
|
|
|
<div className = { styles.nameContainer }>
|
|
|
|
<div className = { styles.name }>
|
|
|
|
{displayName}
|
|
|
|
</div>
|
|
|
|
{local ? <span> ({youText})</span> : null}
|
|
|
|
</div>
|
|
|
|
{isModerator && !disableModeratorIndicator && <div className = { styles.moderatorLabel }>
|
|
|
|
{t('videothumbnail.moderator')}
|
|
|
|
</div>}
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
|
|
|
|
const indicators = (
|
|
|
|
<>
|
|
|
|
{raisedHand && <RaisedHandIndicator />}
|
|
|
|
{VideoStateIcons[videoMediaState]}
|
|
|
|
{AudioStateIcons[audioMediaState]}
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
|
2021-04-21 13:48:05 +00:00
|
|
|
return (
|
2021-10-22 13:23:52 +00:00
|
|
|
<ListItem
|
|
|
|
actions = { children }
|
|
|
|
hideActions = { local }
|
|
|
|
icon = { icon }
|
2021-08-15 05:27:18 +00:00
|
|
|
id = { `participant-item-${participantID}` }
|
2021-10-22 13:23:52 +00:00
|
|
|
indicators = { indicators }
|
2021-04-21 13:48:05 +00:00
|
|
|
isHighlighted = { isHighlighted }
|
2021-09-10 11:05:16 +00:00
|
|
|
onClick = { !local && overflowDrawer ? onClick : undefined }
|
2021-04-21 13:48:05 +00:00
|
|
|
onMouseLeave = { onLeave }
|
2021-10-22 13:23:52 +00:00
|
|
|
textChildren = { text }
|
|
|
|
trigger = { actionsTrigger } />
|
2021-04-21 13:48:05 +00:00
|
|
|
);
|
2021-07-09 12:36:19 +00:00
|
|
|
}
|
2021-09-15 08:28:44 +00:00
|
|
|
|
|
|
|
export default translate(ParticipantItem);
|