bigbluebutton-Github/bigbluebutton-html5/imports/ui/components/nav-bar/talking-indicator/component.jsx

160 lines
4.5 KiB
React
Raw Normal View History

import React, { PureComponent } from 'react';
import cx from 'classnames';
import _ from 'lodash';
2019-11-15 23:54:07 +08:00
import { defineMessages, injectIntl } from 'react-intl';
import Button from '/imports/ui/components/button/component';
import { styles } from './styles';
import Service from './service';
2019-11-15 23:54:07 +08:00
const intlMessages = defineMessages({
wasTalking: {
id: 'app.talkingIndicator.wasTalking',
description: 'aria label for user who is not talking but still visible',
},
isTalking: {
id: 'app.talkingIndicator.isTalking',
description: 'aria label for user currently talking',
},
ariaMuteDesc: {
id: 'app.talkingIndicator.ariaMuteDesc',
description: 'aria description for muting a user',
},
muteLabel: {
id: 'app.actionsBar.muteLabel',
description: 'indicator mute label for moderators',
},
moreThanMaxIndicatorsTalking: {
id: 'app.talkingIndicator.moreThanMaxIndicatorsTalking',
description: 'indicator label for all users who is talking but not visible',
},
moreThanMaxIndicatorsWereTalking: {
id: 'app.talkingIndicator.moreThanMaxIndicatorsWereTalking',
description: 'indicator label for all users who is not talking but not visible',
},
2019-11-15 23:54:07 +08:00
});
class TalkingIndicator extends PureComponent {
2019-11-15 23:54:07 +08:00
handleMuteUser(id) {
const { muteUser, amIModerator, isBreakoutRoom } = this.props;
// only allow moderator muting anyone in non-breakout
if (!amIModerator || isBreakoutRoom) return;
2019-11-15 23:54:07 +08:00
muteUser(id);
}
render() {
const {
2021-05-18 04:25:07 +08:00
intl,
talkers,
amIModerator,
sidebarNavigationIsOpen,
sidebarContentIsOpen,
moreThanMaxIndicators,
} = this.props;
if (!talkers) return null;
const talkingUserElements = Object.keys(talkers).map((id) => {
const {
talking,
color,
muted,
callerName,
} = talkers[`${id}`];
const style = {
[styles.talker]: true,
[styles.spoke]: !talking,
[styles.muted]: muted,
2021-05-18 04:25:07 +08:00
[styles.mobileHide]: sidebarNavigationIsOpen
&& sidebarContentIsOpen,
[styles.isViewer]: !amIModerator,
};
const ariaLabel = intl.formatMessage(talking
? intlMessages.isTalking : intlMessages.wasTalking, {
0: callerName,
2019-11-15 23:54:07 +08:00
});
let icon = talking ? 'unmute' : 'blank';
icon = muted ? 'mute' : icon;
return (
<Button
key={_.uniqueId(`${callerName}-`)}
className={cx(style)}
onClick={() => this.handleMuteUser(id)}
label={callerName}
tooltipLabel={!muted && amIModerator
? `${intl.formatMessage(intlMessages.muteLabel)} ${callerName}`
: null}
data-test={talking ? 'isTalking' : 'wasTalking'}
2019-11-15 23:54:07 +08:00
aria-label={ariaLabel}
aria-describedby={talking ? 'description' : null}
color="primary"
icon={icon}
size="sm"
style={{
backgroundColor: color,
border: `solid 2px ${color}`,
}}
>
{talking ? (
<div id="description" className={styles.hidden}>
{`${intl.formatMessage(intlMessages.ariaMuteDesc)}`}
</div>
) : null}
</Button>
);
});
const maxIndicator = () => {
if (!moreThanMaxIndicators) return null;
2021-10-08 22:57:26 +08:00
const nobodyTalking = Service.nobodyTalking(talkers);
const style = {
[styles.talker]: true,
2021-10-08 22:57:26 +08:00
[styles.spoke]: nobodyTalking,
// [styles.muted]: false,
[styles.mobileHide]: sidebarNavigationIsOpen
&& sidebarContentIsOpen,
};
const { moreThanMaxIndicatorsTalking, moreThanMaxIndicatorsWereTalking } = intlMessages;
2021-10-08 22:57:26 +08:00
const ariaLabel = intl.formatMessage(nobodyTalking
? moreThanMaxIndicatorsWereTalking : moreThanMaxIndicatorsTalking, {
0: Object.keys(talkers).length,
});
return (
<Button
key={_.uniqueId('_has__More_')}
className={cx(style)}
onClick={() => {}} // maybe add a dropdown to show the rest of the users
label="..."
tooltipLabel={ariaLabel}
aria-label={ariaLabel}
color="primary"
size="sm"
style={{
backgroundColor: '#4a148c',
border: 'solid 2px #4a148c',
cursor: 'default',
}}
/>
);
};
return (
<div className={styles.isTalkingWrapper}>
<div className={styles.speaking}>
{talkingUserElements}
{maxIndicator()}
</div>
</div>
);
}
}
2019-11-15 23:54:07 +08:00
export default injectIntl(TalkingIndicator);