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

377 lines
11 KiB
React
Raw Normal View History

2019-06-25 02:06:02 +08:00
import React, { PureComponent } from 'react';
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 { Session } from 'meteor/session';
2019-08-22 01:38:04 +08:00
import logger from '/imports/startup/client/logger';
2018-10-02 21:48:12 +08:00
import { styles } from './styles';
import Service from './service';
2018-10-24 01:18:09 +08:00
import BreakoutRoomContainer from './breakout-remaining-time/container';
import VideoService from '/imports/ui/components/video-provider/service';
import { screenshareHasEnded } from '/imports/ui/components/screenshare/service';
import UserListService from '/imports/ui/components/user-list/service';
import AudioManager from '/imports/ui/services/audio-manager';
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 room',
2018-10-02 21:48:12 +08:00
},
breakoutJoin: {
id: 'app.createBreakoutRoom.join',
description: 'label for join breakout room',
2018-10-02 21:48:12 +08:00
},
2018-10-24 01:18:09 +08:00
breakoutJoinAudio: {
id: 'app.createBreakoutRoom.joinAudio',
description: 'label for option to transfer audio',
2018-10-24 01:18:09 +08:00
},
breakoutReturnAudio: {
id: 'app.createBreakoutRoom.returnAudio',
description: 'label for option to return audio',
2018-10-24 01:18:09 +08:00
},
generatingURL: {
id: 'app.createBreakoutRoom.generatingURL',
description: 'label for generating breakout room url',
2018-10-24 01:18:09 +08:00
},
generatedURL: {
id: 'app.createBreakoutRoom.generatedURL',
description: 'label for generate breakout room url',
2018-10-02 21:48:12 +08:00
},
2018-10-24 03:29:19 +08:00
endAllBreakouts: {
id: 'app.createBreakoutRoom.endAllBreakouts',
description: 'Button label to end all breakout rooms',
},
alreadyConnected: {
id: 'app.createBreakoutRoom.alreadyConnected',
description: 'label for the user that is already connected to breakout room',
2018-10-24 03:29:19 +08:00
},
2018-10-02 21:48:12 +08:00
});
2019-06-25 02:06:02 +08:00
class BreakoutRoom extends PureComponent {
static sortById(a, b) {
if (a.userId > b.userId) {
return 1;
}
if (a.userId < b.userId) {
return -1;
}
return 0;
}
2018-10-02 21:48:12 +08:00
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,
setBreakoutAudioTransferStatus,
isMicrophoneUser,
isReconnecting,
} = this.props;
const {
waiting,
requestedBreakoutId,
joinedAudioOnly,
} = 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
}
}
if (joinedAudioOnly && (!isMicrophoneUser || isReconnecting)) {
this.clearJoinedAudioOnly();
setBreakoutAudioTransferStatus({
breakoutMeetingId: '',
status: AudioManager.BREAKOUT_AUDIO_TRANSFER_STATES.DISCONNECTED,
});
}
2018-10-24 01:18:09 +08:00
}
2018-10-24 01:18:09 +08:00
getBreakoutURL(breakoutId) {
Session.set('lastBreakoutOpened', breakoutId);
2018-10-24 01:18:09 +08:00
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;
}
clearJoinedAudioOnly() {
this.setState({ joinedAudioOnly: false });
}
2018-10-24 01:18:09 +08:00
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-09-28 06:59:55 +08:00
renderUserActions(breakoutId, joinedUsers, number) {
2018-10-24 01:18:09 +08:00
const {
isMicrophoneUser,
amIModerator,
2018-10-24 01:18:09 +08:00
intl,
isUserInBreakoutRoom,
exitAudio,
setBreakoutAudioTransferStatus,
getBreakoutAudioTransferStatus,
2018-10-24 01:18:09 +08:00
} = this.props;
const {
joinedAudioOnly,
breakoutId: _stateBreakoutId,
2018-10-24 01:18:09 +08:00
requestedBreakoutId,
waiting,
} = this.state;
const {
breakoutMeetingId: currentAudioTransferBreakoutId,
status,
} = getBreakoutAudioTransferStatus();
const isInBreakoutAudioTransfer = status
=== AudioManager.BREAKOUT_AUDIO_TRANSFER_STATES.CONNECTED;
const stateBreakoutId = _stateBreakoutId || currentAudioTransferBreakoutId;
const moderatorJoinedAudio = isMicrophoneUser && amIModerator;
2018-10-24 01:18:09 +08:00
const disable = waiting && requestedBreakoutId !== breakoutId;
const audioAction = joinedAudioOnly || isInBreakoutAudioTransfer
2019-08-22 01:38:04 +08:00
? () => {
setBreakoutAudioTransferStatus({
breakoutMeetingId: breakoutId,
status: AudioManager.BREAKOUT_AUDIO_TRANSFER_STATES.RETURNING,
});
2019-08-22 01:38:04 +08:00
this.returnBackToMeeeting(breakoutId);
return logger.debug({
logCode: 'breakoutroom_return_main_audio',
extraInfo: { logType: 'user_action' },
2019-08-22 01:38:04 +08:00
}, 'Returning to main audio (breakout room audio closed)');
}
: () => {
setBreakoutAudioTransferStatus({
breakoutMeetingId: breakoutId,
status: AudioManager.BREAKOUT_AUDIO_TRANSFER_STATES.CONNECTED,
});
2019-08-22 01:38:04 +08:00
this.transferUserToBreakoutRoom(breakoutId);
return logger.debug({
logCode: 'breakoutroom_join_audio_from_main_room',
extraInfo: { logType: 'user_action' },
2019-08-22 01:38:04 +08:00
}, 'joining breakout room audio (main room audio closed)');
};
2018-10-24 01:18:09 +08:00
return (
<div className={styles.breakoutActions}>
2019-09-28 06:59:55 +08:00
{isUserInBreakoutRoom(joinedUsers)
? (
<span className={styles.alreadyConnected}>
{intl.formatMessage(intlMessages.alreadyConnected)}
</span>
)
: (
<Button
label={intl.formatMessage(intlMessages.breakoutJoin)}
2020-02-22 02:06:05 +08:00
data-test="breakoutJoin"
aria-label={`${intl.formatMessage(intlMessages.breakoutJoin)} ${number}`}
onClick={() => {
this.getBreakoutURL(breakoutId);
// leave main room's audio, and stops video and screenshare when joining a breakout room
exitAudio();
logger.debug({
logCode: 'breakoutroom_join',
extraInfo: { logType: 'user_action' },
}, 'joining breakout room closed audio in the main room');
VideoService.storeDeviceIds();
VideoService.exitVideo();
if (UserListService.amIPresenter()) screenshareHasEnded();
}
}
disabled={disable}
className={styles.joinButton}
/>
)
}
2018-10-24 01:18:09 +08:00
{
moderatorJoinedAudio
? [
2018-10-24 01:18:09 +08:00
('|'),
(
<Button
label={
stateBreakoutId === breakoutId
&& (joinedAudioOnly || isInBreakoutAudioTransfer)
? intl.formatMessage(intlMessages.breakoutReturnAudio)
: intl.formatMessage(intlMessages.breakoutJoinAudio)
2018-10-24 01:18:09 +08:00
}
className={styles.button}
disabled={stateBreakoutId !== breakoutId && joinedAudioOnly}
2019-09-19 04:00:32 +08:00
key={`join-audio-${breakoutId}`}
2018-10-24 03:29:19 +08:00
onClick={audioAction}
2018-10-24 01:18:09 +08:00
/>
),
]
: null
}
</div>
);
}
2018-10-24 01:18:09 +08:00
renderBreakoutRooms() {
const {
breakoutRooms,
intl,
} = this.props;
const {
waiting,
requestedBreakoutId,
} = this.state;
const roomItems = breakoutRooms.map(breakout => (
<div
className={styles.breakoutItems}
key={`breakoutRoomItems-${breakout.breakoutId}`}
>
<div className={styles.content} key={`breakoutRoomList-${breakout.breakoutId}`}>
<span aria-hidden>
{intl.formatMessage(intlMessages.breakoutRoom, { 0: breakout.sequence })}
<span className={styles.usersAssignedNumberLabel}>
(
2019-09-28 06:59:55 +08:00
{breakout.joinedUsers.length}
)
</span>
2018-10-24 01:18:09 +08:00
</span>
{waiting && requestedBreakoutId === breakout.breakoutId ? (
<span>
{intl.formatMessage(intlMessages.generatingURL)}
<span className={styles.connectingAnimation} />
</span>
2019-09-28 06:59:55 +08:00
) : this.renderUserActions(
breakout.breakoutId,
breakout.joinedUsers,
breakout.sequence.toString(),
)}
</div>
<div className={styles.joinedUserNames}>
{breakout.joinedUsers
.sort(BreakoutRoom.sortById)
.filter((value, idx, arr) => !(value.userId === (arr[idx + 1] || {}).userId))
.sort(Service.sortUsersByName)
.map(u => u.name)
.join(', ')}
</div>
2018-10-24 01:18:09 +08:00
</div>
));
return (
<div className={styles.breakoutColumn}>
<div className={styles.breakoutScrollableList}>
{roomItems}
</div>
</div>
);
2018-10-24 01:18:09 +08:00
}
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 {
isMeteorConnected, intl, endAllBreakouts, amIModerator, 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()}
{
amIModerator
? (
2018-10-24 01:18:09 +08:00
<Button
color="primary"
2019-06-27 00:29:34 +08:00
disabled={!isMeteorConnected}
2018-10-24 01:18:09 +08:00
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);