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

239 lines
6.5 KiB
React
Raw Normal View History

import React, { Component } from 'react';
import { defineMessages, injectIntl } from 'react-intl';
import ModalFullscreen from '/imports/ui/components/common/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 Styled from './styles';
import { Session } from 'meteor/session';
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,
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,
2024-01-27 00:21:58 +08:00
sendUserUnshareWebcam: PropTypes.func.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,
setIsOpen,
2018-07-07 01:38:14 +08:00
breakoutURL,
isFreeJoin,
2019-07-26 22:35:20 +08:00
voiceUserJoined,
requestJoinURL,
2021-11-24 00:41:37 +08:00
amIPresenter,
2024-01-27 00:21:58 +08:00
sendUserUnshareWebcam,
} = 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();
2024-01-27 00:21:58 +08:00
VideoService.exitVideo(sendUserUnshareWebcam);
2021-11-24 00:41:37 +08:00
if (amIPresenter) screenshareHasEnded();
if (url === '') {
logger.error({
logCode: 'breakoutjoinconfirmation_redirecting_to_url',
extraInfo: { breakoutURL, isFreeJoin },
}, 'joining breakout room but redirected to about://blank');
}
Session.set('lastBreakoutIdOpened', selectValue);
2018-07-07 01:38:14 +08:00
window.open(url);
setIsOpen(false);
}
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 (
<Styled.SelectParent>
2018-07-07 01:38:14 +08:00
{`${intl.formatMessage(intlMessages.freeJoinMessage)}`}
<Styled.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
2023-02-10 03:43:49 +08:00
data-test="roomOption"
key={breakoutId}
value={breakoutId}
>
{name}
</option>
))
}
</Styled.Select>
{ waiting ? <span data-test="labelGeneratingURL">{intl.formatMessage(intlMessages.generatingURL)}</span> : null}
</Styled.SelectParent>
2018-07-07 01:38:14 +08:00
);
}
render() {
const { intl, breakoutName, isFreeJoin, setIsOpen,
isOpen, priority,
} = this.props;
const { waiting } = this.state;
return (
<ModalFullscreen
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={{
callback: () => setIsOpen(false),
label: intl.formatMessage(intlMessages.dismissLabel),
description: intl.formatMessage(intlMessages.dismissDesc),
2017-06-03 03:25:02 +08:00
}}
{...{
setIsOpen,
isOpen,
priority,
}}
2017-06-03 03:25:02 +08:00
>
2018-07-07 01:38:14 +08:00
{ isFreeJoin ? this.renderSelectMeeting() : `${intl.formatMessage(intlMessages.message)} ${breakoutName}?`}
</ModalFullscreen>
);
}
2017-06-03 03:25:02 +08:00
}
export default injectIntl(BreakoutJoinConfirmation);
BreakoutJoinConfirmation.propTypes = propTypes;