2017-07-28 21:43:39 +08:00
|
|
|
import React from 'react';
|
2017-06-04 10:40:14 +08:00
|
|
|
import PropTypes from 'prop-types';
|
2021-10-29 19:23:50 +08:00
|
|
|
import Settings from '/imports/ui/services/settings';
|
|
|
|
import Styled from './styles';
|
|
|
|
import browserInfo from '/imports/utils/browserInfo';
|
2016-06-01 04:25:42 +08:00
|
|
|
|
2016-06-02 21:00:57 +08:00
|
|
|
const propTypes = {
|
2022-03-17 01:53:41 +08:00
|
|
|
children: PropTypes.node,
|
|
|
|
moderator: PropTypes.bool,
|
2019-03-23 02:10:47 +08:00
|
|
|
presenter: PropTypes.bool,
|
|
|
|
talking: PropTypes.bool,
|
|
|
|
muted: PropTypes.bool,
|
|
|
|
listenOnly: PropTypes.bool,
|
|
|
|
voice: PropTypes.bool,
|
|
|
|
noVoice: PropTypes.bool,
|
2017-07-28 21:43:39 +08:00
|
|
|
color: PropTypes.string,
|
2020-09-15 07:13:47 +08:00
|
|
|
emoji: PropTypes.bool,
|
|
|
|
avatar: PropTypes.string,
|
2022-03-17 01:53:41 +08:00
|
|
|
isSkeleton: PropTypes.bool,
|
2016-06-02 21:00:57 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
const defaultProps = {
|
2022-03-17 01:53:41 +08:00
|
|
|
children: <></>,
|
|
|
|
moderator: false,
|
2017-07-28 21:43:39 +08:00
|
|
|
presenter: false,
|
|
|
|
talking: false,
|
|
|
|
muted: false,
|
|
|
|
listenOnly: false,
|
|
|
|
voice: false,
|
2019-03-23 02:10:47 +08:00
|
|
|
noVoice: false,
|
2017-07-28 21:43:39 +08:00
|
|
|
color: '#000',
|
2020-09-15 07:13:47 +08:00
|
|
|
emoji: false,
|
|
|
|
avatar: '',
|
2022-03-17 01:53:41 +08:00
|
|
|
isSkeleton: false,
|
2016-06-02 21:00:57 +08:00
|
|
|
};
|
|
|
|
|
2021-10-29 19:23:50 +08:00
|
|
|
const { animations } = Settings.application;
|
|
|
|
const { isChrome, isFirefox, isEdge } = browserInfo;
|
|
|
|
|
2017-07-28 21:43:39 +08:00
|
|
|
const UserAvatar = ({
|
|
|
|
children,
|
|
|
|
moderator,
|
|
|
|
presenter,
|
|
|
|
talking,
|
|
|
|
muted,
|
|
|
|
listenOnly,
|
|
|
|
color,
|
|
|
|
voice,
|
2020-09-15 07:13:47 +08:00
|
|
|
emoji,
|
|
|
|
avatar,
|
2019-03-23 02:10:47 +08:00
|
|
|
noVoice,
|
2020-08-18 01:03:23 +08:00
|
|
|
whiteboardAccess,
|
2022-03-17 01:53:41 +08:00
|
|
|
isSkeleton,
|
2017-07-28 21:43:39 +08:00
|
|
|
}) => (
|
2022-03-17 01:53:41 +08:00
|
|
|
<>
|
|
|
|
{isSkeleton && (<Styled.Skeleton>{children}</Styled.Skeleton>)}
|
2018-08-04 00:31:58 +08:00
|
|
|
|
2022-03-17 01:53:41 +08:00
|
|
|
{!isSkeleton && (
|
|
|
|
<Styled.Avatar
|
|
|
|
aria-hidden="true"
|
|
|
|
data-test={moderator ? 'moderatorAvatar' : 'viewerAvatar'}
|
|
|
|
moderator={moderator}
|
|
|
|
presenter={presenter}
|
|
|
|
whiteboardAccess={whiteboardAccess && !presenter}
|
|
|
|
muted={muted}
|
|
|
|
listenOnly={listenOnly}
|
|
|
|
voice={voice}
|
|
|
|
noVoice={noVoice && !listenOnly}
|
|
|
|
isChrome={isChrome}
|
|
|
|
isFirefox={isFirefox}
|
|
|
|
isEdge={isEdge}
|
|
|
|
style={{
|
|
|
|
backgroundColor: color,
|
|
|
|
color, // We need the same color on both for the border
|
|
|
|
}}
|
|
|
|
>
|
2018-08-04 00:31:58 +08:00
|
|
|
|
2022-03-17 01:53:41 +08:00
|
|
|
<Styled.Talking talking={talking && !muted && avatar.length === 0} animations={animations} />
|
|
|
|
|
|
|
|
{avatar.length !== 0 && !emoji
|
|
|
|
? (
|
|
|
|
<Styled.Image>
|
|
|
|
<Styled.Img
|
|
|
|
moderator={moderator}
|
|
|
|
src={avatar}
|
|
|
|
/>
|
|
|
|
</Styled.Image>
|
|
|
|
) : (
|
|
|
|
<Styled.Content>
|
|
|
|
{children}
|
|
|
|
</Styled.Content>
|
|
|
|
)}
|
|
|
|
</Styled.Avatar>
|
|
|
|
)}
|
|
|
|
</>
|
2019-03-23 02:10:47 +08:00
|
|
|
);
|
2016-06-02 21:00:57 +08:00
|
|
|
|
|
|
|
UserAvatar.propTypes = propTypes;
|
|
|
|
UserAvatar.defaultProps = defaultProps;
|
2017-07-28 21:43:39 +08:00
|
|
|
|
|
|
|
export default UserAvatar;
|