2021-04-21 13:48:05 +00:00
|
|
|
// @flow
|
|
|
|
|
|
|
|
import React, { type Node } from 'react';
|
|
|
|
|
2021-07-12 15:14:38 +00:00
|
|
|
import { Avatar } from '../../../base/avatar';
|
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
|
|
|
|
} from '../../constants';
|
2021-04-21 13:48:05 +00:00
|
|
|
|
|
|
|
import { RaisedHandIndicator } from './RaisedHandIndicator';
|
|
|
|
import {
|
|
|
|
ParticipantActionsHover,
|
|
|
|
ParticipantActionsPermanent,
|
|
|
|
ParticipantContainer,
|
|
|
|
ParticipantContent,
|
|
|
|
ParticipantName,
|
|
|
|
ParticipantNameContainer,
|
|
|
|
ParticipantStates
|
|
|
|
} from './styled';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Participant actions component mapping depending on trigger type.
|
|
|
|
*/
|
|
|
|
const Actions = {
|
2021-06-23 11:23:44 +00:00
|
|
|
[ACTION_TRIGGER.HOVER]: ParticipantActionsHover,
|
|
|
|
[ACTION_TRIGGER.PERMANENT]: ParticipantActionsPermanent
|
2021-04-21 13:48:05 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
type Props = {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Type of trigger for the participant actions
|
|
|
|
*/
|
|
|
|
actionsTrigger: ActionTrigger,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Media state for audio
|
|
|
|
*/
|
2021-06-23 11:23:44 +00:00
|
|
|
audioMediaState: MediaState,
|
2021-04-21 13:48:05 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* React children
|
|
|
|
*/
|
|
|
|
children: Node,
|
|
|
|
|
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
|
|
|
/**
|
|
|
|
* Is this item highlighted/raised
|
|
|
|
*/
|
|
|
|
isHighlighted?: 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-07-09 12:36:19 +00:00
|
|
|
local: boolean,
|
2021-05-17 08:10:17 +00:00
|
|
|
|
2021-04-21 13:48:05 +00:00
|
|
|
/**
|
|
|
|
* Callback for when the mouse leaves this component
|
|
|
|
*/
|
|
|
|
onLeave?: Function,
|
|
|
|
|
|
|
|
/**
|
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-07-09 12:36:19 +00:00
|
|
|
raisedHand: boolean,
|
2021-04-21 13:48:05 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Media state for video
|
|
|
|
*/
|
2021-07-09 12:36:19 +00:00
|
|
|
videoMuteState: MediaState,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The translated "you" text.
|
|
|
|
*/
|
|
|
|
youText: string
|
2021-04-21 13:48:05 +00:00
|
|
|
}
|
|
|
|
|
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}
|
|
|
|
*/
|
|
|
|
export default function ParticipantItem({
|
2021-04-21 13:48:05 +00:00
|
|
|
children,
|
|
|
|
isHighlighted,
|
|
|
|
onLeave,
|
2021-06-23 11:23:44 +00:00
|
|
|
actionsTrigger = ACTION_TRIGGER.HOVER,
|
|
|
|
audioMediaState = MEDIA_STATE.NONE,
|
|
|
|
videoMuteState = MEDIA_STATE.NONE,
|
2021-07-09 12:36:19 +00:00
|
|
|
displayName,
|
|
|
|
participantID,
|
|
|
|
local,
|
|
|
|
raisedHand,
|
|
|
|
youText
|
|
|
|
}: Props) {
|
2021-04-21 13:48:05 +00:00
|
|
|
const ParticipantActions = Actions[actionsTrigger];
|
|
|
|
|
|
|
|
return (
|
|
|
|
<ParticipantContainer
|
2021-08-15 05:27:18 +00:00
|
|
|
id = { `participant-item-${participantID}` }
|
2021-04-21 13:48:05 +00:00
|
|
|
isHighlighted = { isHighlighted }
|
2021-08-19 08:32:36 +00:00
|
|
|
local = { local }
|
2021-04-21 13:48:05 +00:00
|
|
|
onMouseLeave = { onLeave }
|
|
|
|
trigger = { actionsTrigger }>
|
|
|
|
<Avatar
|
|
|
|
className = 'participant-avatar'
|
2021-07-09 12:36:19 +00:00
|
|
|
participantId = { participantID }
|
2021-04-21 13:48:05 +00:00
|
|
|
size = { 32 } />
|
|
|
|
<ParticipantContent>
|
|
|
|
<ParticipantNameContainer>
|
|
|
|
<ParticipantName>
|
2021-05-17 08:10:17 +00:00
|
|
|
{ displayName }
|
2021-04-21 13:48:05 +00:00
|
|
|
</ParticipantName>
|
2021-07-09 12:36:19 +00:00
|
|
|
{ local ? <span> ({ youText })</span> : null }
|
2021-04-21 13:48:05 +00:00
|
|
|
</ParticipantNameContainer>
|
2021-07-09 12:36:19 +00:00
|
|
|
{ !local && <ParticipantActions children = { children } /> }
|
2021-04-21 13:48:05 +00:00
|
|
|
<ParticipantStates>
|
2021-07-09 12:36:19 +00:00
|
|
|
{ raisedHand && <RaisedHandIndicator /> }
|
|
|
|
{ VideoStateIcons[videoMuteState] }
|
|
|
|
{ AudioStateIcons[audioMediaState] }
|
2021-04-21 13:48:05 +00:00
|
|
|
</ParticipantStates>
|
|
|
|
</ParticipantContent>
|
|
|
|
</ParticipantContainer>
|
|
|
|
);
|
2021-07-09 12:36:19 +00:00
|
|
|
}
|