bigbluebutton-Github/bigbluebutton-html5/imports/ui/components/breakout-room/component.jsx

258 lines
7.1 KiB
React
Raw Normal View History

2018-10-02 21:48:12 +08:00
import React, { Component } from 'react';
2018-10-26 23:16:29 +08:00
2018-10-02 21:48:12 +08:00
import { defineMessages, injectIntl } from 'react-intl';
2018-10-24 01:18:09 +08:00
import _ from 'lodash';
2018-10-02 21:48:12 +08:00
import Button from '/imports/ui/components/button/component';
import { styles } from './styles';
2018-10-24 01:18:09 +08:00
import BreakoutRoomContainer from './breakout-remaining-time/container';
2018-10-02 21:48:12 +08:00
const intlMessages = defineMessages({
breakoutTitle: {
id: 'app.createBreakoutRoom.title',
description: 'breakout title',
},
2019-01-28 21:33:50 +08:00
breakoutAriaTitle: {
id: 'app.createBreakoutRoom.ariaTitle',
description: 'breakout aria title',
},
2018-10-02 21:48:12 +08:00
breakoutDuration: {
id: 'app.createBreakoutRoom.duration',
description: 'breakout duration time',
},
breakoutRoom: {
id: 'app.createBreakoutRoom.room',
description: 'breakout duration time',
},
breakoutJoin: {
id: 'app.createBreakoutRoom.join',
description: 'breakout duration time',
},
2018-10-24 01:18:09 +08:00
breakoutJoinAudio: {
id: 'app.createBreakoutRoom.joinAudio',
description: 'breakout duration time',
},
breakoutReturnAudio: {
id: 'app.createBreakoutRoom.returnAudio',
description: 'breakout duration time',
},
generatingURL: {
id: 'app.createBreakoutRoom.generatingURL',
description: 'breakout duration time',
},
generatedURL: {
id: 'app.createBreakoutRoom.generatedURL',
2018-10-02 21:48:12 +08:00
description: 'breakout duration time',
},
2018-10-24 03:29:19 +08:00
endAllBreakouts: {
id: 'app.createBreakoutRoom.endAllBreakouts',
description: 'breakout duration time',
},
2018-10-02 21:48:12 +08:00
});
class BreakoutRoom extends Component {
constructor(props) {
super(props);
2018-10-24 01:18:09 +08:00
this.renderBreakoutRooms = this.renderBreakoutRooms.bind(this);
this.getBreakoutURL = this.getBreakoutURL.bind(this);
this.renderDuration = this.renderDuration.bind(this);
this.transferUserToBreakoutRoom = this.transferUserToBreakoutRoom.bind(this);
this.renderUserActions = this.renderUserActions.bind(this);
this.returnBackToMeeeting = this.returnBackToMeeeting.bind(this);
this.state = {
requestedBreakoutId: '',
waiting: false,
joinedAudioOnly: false,
breakoutId: '',
};
}
componentDidUpdate() {
const {
breakoutRoomUser,
breakoutRooms,
closeBreakoutPanel,
} = this.props;
const {
waiting,
requestedBreakoutId,
} = this.state;
if (breakoutRooms.length <= 0) closeBreakoutPanel();
if (waiting) {
const breakoutUser = breakoutRoomUser(requestedBreakoutId);
2018-10-24 01:18:09 +08:00
if (!breakoutUser) return;
if (breakoutUser.redirectToHtml5JoinURL !== '') {
window.open(breakoutUser.redirectToHtml5JoinURL, '_blank');
_.delay(() => this.setState({ waiting: false }), 1000);
2018-10-24 01:18:09 +08:00
}
}
}
2018-10-24 01:18:09 +08:00
getBreakoutURL(breakoutId) {
const { requestJoinURL, breakoutRoomUser } = this.props;
const { waiting } = this.state;
2018-10-24 01:18:09 +08:00
const hasUser = breakoutRoomUser(breakoutId);
if (!hasUser && !waiting) {
2018-10-24 03:29:19 +08:00
this.setState(
{
waiting: true,
requestedBreakoutId: breakoutId,
},
2018-10-24 03:29:19 +08:00
() => requestJoinURL(breakoutId),
);
2018-10-24 01:18:09 +08:00
}
if (hasUser) {
window.open(hasUser.redirectToHtml5JoinURL, '_blank');
this.setState({ waiting: false });
2018-10-24 01:18:09 +08:00
}
return null;
}
transferUserToBreakoutRoom(breakoutId) {
const { transferToBreakout } = this.props;
transferToBreakout(breakoutId);
2018-10-24 01:18:09 +08:00
this.setState({ joinedAudioOnly: true, breakoutId });
}
2018-10-24 01:18:09 +08:00
returnBackToMeeeting(breakoutId) {
const { transferUserToMeeting, meetingId } = this.props;
transferUserToMeeting(breakoutId, meetingId);
this.setState({ joinedAudioOnly: false, breakoutId });
}
2019-01-28 21:33:50 +08:00
renderUserActions(breakoutId, number) {
2018-10-24 01:18:09 +08:00
const {
isMicrophoneUser,
isModerator,
2018-10-24 01:18:09 +08:00
intl,
} = this.props;
const {
joinedAudioOnly,
breakoutId: stateBreakoutId,
requestedBreakoutId,
waiting,
} = this.state;
const moderatorJoinedAudio = isMicrophoneUser && isModerator;
2018-10-24 01:18:09 +08:00
const disable = waiting && requestedBreakoutId !== breakoutId;
const audioAction = joinedAudioOnly
? () => this.returnBackToMeeeting(breakoutId)
: () => this.transferUserToBreakoutRoom(breakoutId);
2018-10-24 01:18:09 +08:00
return (
<div className={styles.breakoutActions}>
<Button
label={intl.formatMessage(intlMessages.breakoutJoin)}
aria-label={`${intl.formatMessage(intlMessages.breakoutJoin)} ${number}`}
2018-10-24 01:18:09 +08:00
onClick={() => this.getBreakoutURL(breakoutId)}
disabled={disable}
className={styles.joinButton}
/>
{
moderatorJoinedAudio
? [
2018-10-24 01:18:09 +08:00
('|'),
(
<Button
label={
moderatorJoinedAudio
&& stateBreakoutId === breakoutId
&& joinedAudioOnly
? intl.formatMessage(intlMessages.breakoutReturnAudio)
: intl.formatMessage(intlMessages.breakoutJoinAudio)
2018-10-24 01:18:09 +08:00
}
className={styles.button}
2018-10-24 03:29:19 +08:00
onClick={audioAction}
2018-10-24 01:18:09 +08:00
/>
),
]
: null
}
</div>
);
}
renderBreakoutRooms() {
const {
breakoutRooms,
intl,
2019-04-24 20:50:45 +08:00
getUsersByBreakoutId,
2018-10-24 01:18:09 +08:00
} = this.props;
const {
waiting,
requestedBreakoutId,
} = this.state;
const roomItems = breakoutRooms.map(breakout => (
<div className={styles.content} key={`breakoutRoomList-${breakout.breakoutId}`}>
<span aria-hidden>
{intl.formatMessage(intlMessages.breakoutRoom, breakout.sequence.toString())}
<span className={styles.usersAssignedNumberLabel}>
(
2019-04-24 20:50:45 +08:00
{getUsersByBreakoutId(breakout.breakoutId).count()}
)
</span>
</span>
{waiting && requestedBreakoutId === breakout.breakoutId ? (
2018-10-24 01:18:09 +08:00
<span>
2018-10-24 03:29:19 +08:00
{intl.formatMessage(intlMessages.generatingURL)}
<span className={styles.connectingAnimation} />
2018-10-24 01:18:09 +08:00
</span>
) : this.renderUserActions(breakout.breakoutId, breakout.sequence.toString())}
2018-10-24 01:18:09 +08:00
</div>
));
return roomItems;
}
renderDuration() {
const { breakoutRooms } = this.props;
return (
<span className={styles.duration}>
2018-10-24 03:29:19 +08:00
<BreakoutRoomContainer
messageDuration={intlMessages.breakoutDuration}
breakoutRoom={breakoutRooms[0]}
/>
2018-10-24 01:18:09 +08:00
</span>
);
2018-10-02 21:48:12 +08:00
}
2018-10-24 01:18:09 +08:00
2018-10-02 21:48:12 +08:00
render() {
2018-10-24 01:18:09 +08:00
const {
intl, endAllBreakouts, isModerator, closeBreakoutPanel,
2018-10-24 01:18:09 +08:00
} = this.props;
2018-10-02 21:48:12 +08:00
return (
<div className={styles.panel}>
2019-01-28 21:33:50 +08:00
<Button
icon="left_arrow"
label={intl.formatMessage(intlMessages.breakoutTitle)}
aria-label={intl.formatMessage(intlMessages.breakoutAriaTitle)}
className={styles.header}
onClick={closeBreakoutPanel}
/>
2018-10-24 01:18:09 +08:00
{this.renderBreakoutRooms()}
{this.renderDuration()}
{
isModerator
? (
2018-10-24 01:18:09 +08:00
<Button
color="primary"
size="lg"
2018-10-24 03:29:19 +08:00
label={intl.formatMessage(intlMessages.endAllBreakouts)}
2018-10-24 01:18:09 +08:00
className={styles.endButton}
onClick={endAllBreakouts}
/>
) : null
}
2018-10-02 21:48:12 +08:00
</div>
);
}
}
export default injectIntl(BreakoutRoom);