import React, { PureComponent } from 'react'; import { defineMessages, injectIntl } from 'react-intl'; import _ from 'lodash'; import Button from '/imports/ui/components/button/component'; import { Session } from 'meteor/session'; import { styles } from './styles'; import BreakoutRoomContainer from './breakout-remaining-time/container'; const intlMessages = defineMessages({ breakoutTitle: { id: 'app.createBreakoutRoom.title', description: 'breakout title', }, breakoutAriaTitle: { id: 'app.createBreakoutRoom.ariaTitle', description: 'breakout aria title', }, 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', }, 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', description: 'breakout duration time', }, endAllBreakouts: { id: 'app.createBreakoutRoom.endAllBreakouts', description: 'breakout duration time', }, }); class BreakoutRoom extends PureComponent { constructor(props) { super(props); 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); if (!breakoutUser) return; if (breakoutUser.redirectToHtml5JoinURL !== '') { window.open(breakoutUser.redirectToHtml5JoinURL, '_blank'); _.delay(() => this.setState({ waiting: false }), 1000); } } } getBreakoutURL(breakoutId) { Session.set('lastBreakoutOpened', breakoutId); const { requestJoinURL, breakoutRoomUser } = this.props; const { waiting } = this.state; const hasUser = breakoutRoomUser(breakoutId); if (!hasUser && !waiting) { this.setState( { waiting: true, requestedBreakoutId: breakoutId, }, () => requestJoinURL(breakoutId), ); } if (hasUser) { window.open(hasUser.redirectToHtml5JoinURL, '_blank'); this.setState({ waiting: false }); } return null; } transferUserToBreakoutRoom(breakoutId) { const { transferToBreakout } = this.props; transferToBreakout(breakoutId); this.setState({ joinedAudioOnly: true, breakoutId }); } returnBackToMeeeting(breakoutId) { const { transferUserToMeeting, meetingId } = this.props; transferUserToMeeting(breakoutId, meetingId); this.setState({ joinedAudioOnly: false, breakoutId }); } renderUserActions(breakoutId, number) { const { isMicrophoneUser, isModerator, intl, } = this.props; const { joinedAudioOnly, breakoutId: stateBreakoutId, requestedBreakoutId, waiting, } = this.state; const moderatorJoinedAudio = isMicrophoneUser && isModerator; const disable = waiting && requestedBreakoutId !== breakoutId; const audioAction = joinedAudioOnly ? () => this.returnBackToMeeeting(breakoutId) : () => this.transferUserToBreakoutRoom(breakoutId); return (
); } renderBreakoutRooms() { const { breakoutRooms, intl, getUsersByBreakoutId, } = this.props; const { waiting, requestedBreakoutId, } = this.state; const roomItems = breakoutRooms.map(breakout => (
{intl.formatMessage(intlMessages.breakoutRoom, breakout.sequence.toString())} ( {getUsersByBreakoutId(breakout.breakoutId).count()} ) {waiting && requestedBreakoutId === breakout.breakoutId ? ( {intl.formatMessage(intlMessages.generatingURL)} ) : this.renderUserActions(breakout.breakoutId, breakout.sequence.toString())}
)); return roomItems; } renderDuration() { const { breakoutRooms } = this.props; return ( ); } render() { const { isMeteorConnected, intl, endAllBreakouts, isModerator, closeBreakoutPanel, } = this.props; return (
); } } export default injectIntl(BreakoutRoom);