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

95 lines
2.4 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';
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',
},
});
class TalkingIndicator extends PureComponent {
2019-11-15 23:54:07 +08:00
handleMuteUser(id) {
const { muteUser, amIModerator } = this.props;
if (!amIModerator) return;
muteUser(id);
}
render() {
2019-11-26 03:24:12 +08:00
const { intl, talkers, openPanel } = this.props;
if (!talkers) return null;
const talkingUserElements = Object.keys(talkers).map((id) => {
const {
talking,
color,
voiceUserId,
muted,
callerName,
} = talkers[`${id}`];
const style = {
[styles.talker]: true,
[styles.spoke]: !talking,
[styles.muted]: muted,
2019-11-26 03:24:12 +08:00
[styles.mobileHide]: openPanel !== '',
};
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(voiceUserId)}
label={callerName}
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>
);
});
return (
<div className={styles.isTalkingWrapper}>
<div className={styles.speaking}>
{talkingUserElements}
</div>
</div>
);
}
}
2019-11-15 23:54:07 +08:00
export default injectIntl(TalkingIndicator);