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

228 lines
6.3 KiB
React
Raw Normal View History

import React, { Component } from 'react';
import { defineMessages, injectIntl } from 'react-intl';
import { withModalMounter } from '/imports/ui/components/modal/service';
import Modal from '/imports/ui/components/modal/fullscreen/component';
import logger from '/imports/startup/client/logger';
import PropTypes from 'prop-types';
2017-10-06 20:50:01 +08:00
import AudioService from '../audio/service';
import VideoService from '../video-provider/service';
import { screenshareHasEnded } from '/imports/ui/components/screenshare/service';
import UserListService from '/imports/ui/components/user-list/service';
2018-07-07 01:38:14 +08:00
import { styles } from './styles';
const intlMessages = defineMessages({
title: {
2016-11-14 19:57:10 +08:00
id: 'app.breakoutJoinConfirmation.title',
2017-04-10 23:50:03 +08:00
description: 'Join breakout room title',
},
message: {
id: 'app.breakoutJoinConfirmation.message',
description: 'Join breakout confirm message',
},
2018-07-07 01:38:14 +08:00
freeJoinMessage: {
id: 'app.breakoutJoinConfirmation.freeJoinMessage',
description: 'Join breakout confirm message',
2018-07-07 01:38:14 +08:00
},
confirmLabel: {
2019-05-25 01:29:36 +08:00
id: 'app.createBreakoutRoom.join',
2017-04-10 23:50:03 +08:00
description: 'Join confirmation button label',
},
confirmDesc: {
id: 'app.breakoutJoinConfirmation.confirmDesc',
2017-04-11 21:52:30 +08:00
description: 'adds context to confirm option',
},
dismissLabel: {
id: 'app.breakoutJoinConfirmation.dismissLabel',
2017-04-10 23:50:03 +08:00
description: 'Cancel button label',
},
dismissDesc: {
id: 'app.breakoutJoinConfirmation.dismissDesc',
2017-04-11 21:52:30 +08:00
description: 'adds context to dismiss option',
},
generatingURL: {
id: 'app.createBreakoutRoom.generatingURLMessage',
description: 'label for generating breakout room url',
},
});
const propTypes = {
intl: PropTypes.object.isRequired,
breakout: PropTypes.objectOf(Object).isRequired,
getURL: PropTypes.func.isRequired,
mountModal: PropTypes.func.isRequired,
breakoutURL: PropTypes.string.isRequired,
isFreeJoin: PropTypes.bool.isRequired,
2019-07-26 22:35:20 +08:00
voiceUserJoined: PropTypes.bool.isRequired,
requestJoinURL: PropTypes.func.isRequired,
breakouts: PropTypes.arrayOf(Object).isRequired,
breakoutName: PropTypes.string.isRequired,
};
let interval = null;
class BreakoutJoinConfirmation extends Component {
constructor(props) {
super(props);
2018-07-07 01:38:14 +08:00
this.state = {
selectValue: props.breakout.breakoutId,
waiting: true,
2018-07-07 01:38:14 +08:00
};
this.handleJoinBreakoutConfirmation = this.handleJoinBreakoutConfirmation.bind(this);
2018-07-07 01:38:14 +08:00
this.renderSelectMeeting = this.renderSelectMeeting.bind(this);
this.handleSelectChange = this.handleSelectChange.bind(this);
}
2019-10-25 01:01:39 +08:00
componentDidMount() {
const {
isFreeJoin,
} = this.props;
const {
selectValue,
} = this.state;
if (isFreeJoin) {
this.fetchJoinURL(selectValue);
} else {
this.setState({ waiting: false });
2019-10-25 01:01:39 +08:00
}
}
componentWillUnmount() {
if (interval) clearInterval(interval);
}
handleJoinBreakoutConfirmation() {
const {
2018-07-07 01:38:14 +08:00
getURL,
mountModal,
2018-07-07 01:38:14 +08:00
breakoutURL,
isFreeJoin,
2019-07-26 22:35:20 +08:00
voiceUserJoined,
requestJoinURL,
} = this.props;
const { selectValue } = this.state;
if (!getURL(selectValue)) {
requestJoinURL(selectValue);
}
const urlFromSelectedRoom = getURL(selectValue);
const url = isFreeJoin ? urlFromSelectedRoom : breakoutURL;
// leave main room's audio, and stops video and screenshare when joining a breakout room
2019-07-26 22:35:20 +08:00
if (voiceUserJoined) {
AudioService.exitAudio();
logger.info({
logCode: 'breakoutjoinconfirmation_ended_audio',
extraInfo: { logType: 'user_action' },
}, 'joining breakout room closed audio in the main room');
}
VideoService.storeDeviceIds();
VideoService.exitVideo();
if (UserListService.amIPresenter()) screenshareHasEnded();
if (url === '') {
logger.error({
logCode: 'breakoutjoinconfirmation_redirecting_to_url',
extraInfo: { breakoutURL, isFreeJoin },
}, 'joining breakout room but redirected to about://blank');
}
2018-07-07 01:38:14 +08:00
window.open(url);
mountModal(null);
}
2018-07-13 00:19:54 +08:00
async fetchJoinURL(selectValue) {
2019-10-25 01:01:39 +08:00
const {
requestJoinURL,
getURL,
} = this.props;
this.setState({ selectValue });
if (!getURL(selectValue)) {
requestJoinURL(selectValue);
this.setState({ waiting: true });
await new Promise((resolve) => {
interval = setInterval(() => {
const url = getURL(selectValue);
if (url !== "") {
resolve();
clearInterval(interval);
this.setState({ waiting: false });
}
}, 1000)
})
} else {
this.setState({ waiting: false });
2019-10-25 01:01:39 +08:00
}
2018-07-07 01:38:14 +08:00
}
handleSelectChange(e) {
const { value } = e.target;
this.fetchJoinURL(value);
}
2018-07-07 01:38:14 +08:00
renderSelectMeeting() {
const { breakouts, intl } = this.props;
const { selectValue, waiting, } = this.state;
2018-07-07 01:38:14 +08:00
return (
<div className={styles.selectParent}>
{`${intl.formatMessage(intlMessages.freeJoinMessage)}`}
<select
className={styles.select}
value={selectValue}
2018-07-07 01:38:14 +08:00
onChange={this.handleSelectChange}
disabled={waiting}
2018-07-07 01:38:14 +08:00
>
{
breakouts.map(({ name, breakoutId }) => (
<option
key={breakoutId}
value={breakoutId}
>
{name}
</option>
))
}
2018-07-07 01:38:14 +08:00
</select>
{ waiting ? <span data-test="labelGeneratingURL">{intl.formatMessage(intlMessages.generatingURL)}</span> : null}
2018-07-07 01:38:14 +08:00
</div>
);
}
render() {
2018-07-07 01:38:14 +08:00
const { intl, breakoutName, isFreeJoin } = this.props;
const { waiting } = this.state;
return (
<Modal
title={intl.formatMessage(intlMessages.title)}
confirm={{
callback: this.handleJoinBreakoutConfirmation,
2019-05-25 01:29:36 +08:00
label: intl.formatMessage(intlMessages.confirmLabel),
description: intl.formatMessage(intlMessages.confirmDesc),
icon: 'popout_window',
disabled: waiting,
}}
dismiss={{
label: intl.formatMessage(intlMessages.dismissLabel),
description: intl.formatMessage(intlMessages.dismissDesc),
2017-06-03 03:25:02 +08:00
}}
>
2018-07-07 01:38:14 +08:00
{ isFreeJoin ? this.renderSelectMeeting() : `${intl.formatMessage(intlMessages.message)} ${breakoutName}?`}
</Modal>
);
}
2017-06-03 03:25:02 +08:00
}
export default withModalMounter(injectIntl(BreakoutJoinConfirmation));
BreakoutJoinConfirmation.propTypes = propTypes;