2022-08-25 11:35:19 +00:00
|
|
|
/* eslint-disable lines-around-comment */
|
2021-10-22 13:23:52 +00:00
|
|
|
import { makeStyles } from '@material-ui/styles';
|
2022-08-25 11:35:19 +00:00
|
|
|
import React, { ReactElement, useCallback } from 'react';
|
|
|
|
import { WithTranslation } from 'react-i18next';
|
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-08-25 11:35:19 +00:00
|
|
|
// @ts-ignore
|
2021-09-14 15:31:30 +00:00
|
|
|
import { ListItem } from '../../../base/components';
|
2022-08-25 11:35:19 +00:00
|
|
|
// @ts-ignore
|
2021-09-15 08:28:44 +00:00
|
|
|
import { translate } from '../../../base/i18n';
|
2021-04-21 13:48:05 +00:00
|
|
|
import {
|
2021-08-18 12:10:16 +00:00
|
|
|
ACTION_TRIGGER,
|
|
|
|
AudioStateIcons,
|
|
|
|
MEDIA_STATE,
|
|
|
|
type ActionTrigger,
|
|
|
|
type MediaState,
|
|
|
|
VideoStateIcons
|
2022-08-25 11:35:19 +00:00
|
|
|
// @ts-ignore
|
2021-08-18 12:10:16 +00:00
|
|
|
} from '../../constants';
|
2021-04-21 13:48:05 +00:00
|
|
|
|
2022-08-25 11:35:19 +00:00
|
|
|
// @ts-ignore
|
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
|
|
|
*/
|
2021-09-14 15:31:30 +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
|
|
|
*/
|
2021-09-14 15:31:30 +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-08-25 11:35:19 +00:00
|
|
|
children?: ReactElement,
|
2021-04-21 13:48:05 +00:00
|
|
|
|
2021-09-28 08:46:20 +00:00
|
|
|
/**
|
|
|
|
* Whether or not to disable the moderator indicator.
|
|
|
|
*/
|
|
|
|
disableModeratorIndicator: boolean,
|
|
|
|
|
2021-07-09 12:36:19 +00:00
|
|
|
/**
|
|
|
|
* The name of the participant. Used for showing lobby names.
|
|
|
|
*/
|
|
|
|
displayName: string,
|
|
|
|
|
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
|
|
|
*/
|
|
|
|
isHighlighted?: boolean,
|
|
|
|
|
2021-09-15 08:28:44 +00:00
|
|
|
/**
|
|
|
|
* Whether or not the participant is a moderator.
|
|
|
|
*/
|
|
|
|
isModerator: boolean,
|
|
|
|
|
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
|
|
|
*/
|
2021-09-14 15:31:30 +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-08-25 11:35:19 +00:00
|
|
|
onLeave?: Function,
|
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-08-25 11:35:19 +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.
|
|
|
|
*/
|
|
|
|
overflowDrawer?: boolean,
|
|
|
|
|
2021-04-21 13:48:05 +00:00
|
|
|
/**
|
2021-07-09 12:36:19 +00:00
|
|
|
* The ID of the participant.
|
|
|
|
*/
|
|
|
|
participantID: string,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* True if the participant have raised hand.
|
2021-04-21 13:48:05 +00:00
|
|
|
*/
|
2021-09-14 15:31:30 +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
|
|
|
*/
|
2021-09-14 15:31:30 +00:00
|
|
|
videoMediaState?: MediaState,
|
2021-07-09 12:36:19 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The translated "you" text.
|
|
|
|
*/
|
2021-09-14 15:31:30 +00:00
|
|
|
youText?: string
|
2021-04-21 13:48:05 +00:00
|
|
|
}
|
|
|
|
|
2022-08-25 11:35:19 +00:00
|
|
|
const useStyles = makeStyles((theme: any) => {
|
2021-10-22 13:23:52 +00:00
|
|
|
return {
|
|
|
|
nameContainer: {
|
|
|
|
display: 'flex',
|
|
|
|
flex: 1,
|
|
|
|
overflow: 'hidden'
|
|
|
|
},
|
|
|
|
|
|
|
|
name: {
|
|
|
|
overflow: 'hidden',
|
|
|
|
textOverflow: 'ellipsis',
|
|
|
|
whiteSpace: 'nowrap'
|
|
|
|
},
|
|
|
|
|
|
|
|
moderatorLabel: {
|
|
|
|
...theme.typography.labelRegular,
|
|
|
|
lineHeight: `${theme.typography.labelRegular.lineHeight}px`,
|
|
|
|
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(
|
2021-09-14 15:31:30 +00:00
|
|
|
() => openDrawerForParticipant && 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
|
|
|
|
2021-10-22 13:23:52 +00:00
|
|
|
const styles = useStyles();
|
|
|
|
|
|
|
|
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);
|