2018-11-23 22:14:48 +08:00
|
|
|
import React, { PureComponent } from 'react';
|
2017-06-04 10:40:14 +08:00
|
|
|
import PropTypes from 'prop-types';
|
2018-12-18 23:15:51 +08:00
|
|
|
import { Session } from 'meteor/session';
|
2017-03-10 03:50:21 +08:00
|
|
|
import _ from 'lodash';
|
2016-12-06 04:00:09 +08:00
|
|
|
import cx from 'classnames';
|
2018-11-27 20:44:22 +08:00
|
|
|
import Auth from '/imports/ui/services/auth';
|
2016-11-07 23:52:39 +08:00
|
|
|
import Icon from '/imports/ui/components/icon/component';
|
2018-07-07 01:46:07 +08:00
|
|
|
import BreakoutJoinConfirmation from '/imports/ui/components/breakout-join-confirmation/container';
|
2016-11-07 23:52:39 +08:00
|
|
|
import Dropdown from '/imports/ui/components/dropdown/component';
|
|
|
|
import DropdownTrigger from '/imports/ui/components/dropdown/trigger/component';
|
|
|
|
import DropdownContent from '/imports/ui/components/dropdown/content/component';
|
|
|
|
import DropdownList from '/imports/ui/components/dropdown/list/component';
|
|
|
|
import DropdownListItem from '/imports/ui/components/dropdown/list/item/component';
|
2017-05-03 23:06:28 +08:00
|
|
|
import { withModalMounter } from '/imports/ui/components/modal/service';
|
2018-11-01 02:51:56 +08:00
|
|
|
import withShortcutHelper from '/imports/ui/components/shortcut-help/service';
|
2019-01-04 02:14:35 +08:00
|
|
|
import getFromUserSettings from '/imports/ui/services/users-settings';
|
2017-03-29 23:22:26 +08:00
|
|
|
import { defineMessages, injectIntl } from 'react-intl';
|
2018-02-23 01:30:12 +08:00
|
|
|
import { styles } from './styles.scss';
|
|
|
|
import Button from '../button/component';
|
|
|
|
import RecordingIndicator from './recording-indicator/component';
|
|
|
|
import SettingsDropdownContainer from './settings-dropdown/container';
|
2017-03-29 23:22:26 +08:00
|
|
|
|
|
|
|
const intlMessages = defineMessages({
|
|
|
|
toggleUserListLabel: {
|
|
|
|
id: 'app.navBar.userListToggleBtnLabel',
|
2017-04-10 23:50:03 +08:00
|
|
|
description: 'Toggle button label',
|
2017-03-29 23:22:26 +08:00
|
|
|
},
|
2018-02-23 04:27:19 +08:00
|
|
|
toggleUserListAria: {
|
|
|
|
id: 'app.navBar.toggleUserList.ariaLabel',
|
|
|
|
description: 'description of the lists inside the userlist',
|
|
|
|
},
|
2017-04-18 01:00:15 +08:00
|
|
|
newMessages: {
|
2017-08-11 00:05:51 +08:00
|
|
|
id: 'app.navBar.toggleUserList.newMessages',
|
2017-04-26 22:08:47 +08:00
|
|
|
description: 'label for toggleUserList btn when showing red notification',
|
2017-04-18 01:00:15 +08:00
|
|
|
},
|
2018-02-16 21:47:55 +08:00
|
|
|
recordingSession: {
|
|
|
|
id: 'app.navBar.recording',
|
|
|
|
description: 'label for when the session is being recorded',
|
|
|
|
},
|
2018-02-24 00:26:33 +08:00
|
|
|
recordingIndicatorOn: {
|
|
|
|
id: 'app.navBar.recording.on',
|
|
|
|
description: 'label for indicator when the session is being recorded',
|
|
|
|
},
|
|
|
|
recordingIndicatorOff: {
|
|
|
|
id: 'app.navBar.recording.off',
|
|
|
|
description: 'label for indicator when the session is not being recorded',
|
|
|
|
},
|
2019-01-04 02:14:35 +08:00
|
|
|
startTitle: {
|
|
|
|
id: 'app.recording.startTitle',
|
|
|
|
description: 'start recording title',
|
|
|
|
},
|
|
|
|
stopTitle: {
|
|
|
|
id: 'app.recording.stopTitle',
|
|
|
|
description: 'stop recording title',
|
|
|
|
},
|
2017-03-29 23:22:26 +08:00
|
|
|
});
|
2016-04-29 03:02:51 +08:00
|
|
|
|
|
|
|
const propTypes = {
|
2018-11-01 02:51:56 +08:00
|
|
|
presentationTitle: PropTypes.string,
|
|
|
|
hasUnreadMessages: PropTypes.bool,
|
2019-01-05 05:32:59 +08:00
|
|
|
recordProps: PropTypes.shape({
|
|
|
|
time: PropTypes.number,
|
|
|
|
recording: PropTypes.bool,
|
|
|
|
}),
|
2018-11-01 02:51:56 +08:00
|
|
|
shortcuts: PropTypes.string,
|
2016-04-29 03:02:51 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
const defaultProps = {
|
2016-05-04 04:40:46 +08:00
|
|
|
presentationTitle: 'Default Room Title',
|
2016-04-29 03:02:51 +08:00
|
|
|
hasUnreadMessages: false,
|
2018-12-21 03:39:04 +08:00
|
|
|
recordProps: {
|
|
|
|
allowStartStopRecording: false,
|
|
|
|
autoStartRecording: false,
|
|
|
|
record: false,
|
|
|
|
recording: false,
|
|
|
|
},
|
2018-11-01 02:51:56 +08:00
|
|
|
shortcuts: '',
|
2016-04-29 03:02:51 +08:00
|
|
|
};
|
|
|
|
|
2018-12-18 23:15:51 +08:00
|
|
|
const openBreakoutJoinConfirmation = (breakout, breakoutName, mountModal) => mountModal(
|
|
|
|
<BreakoutJoinConfirmation
|
2018-07-07 01:46:07 +08:00
|
|
|
breakout={breakout}
|
2017-06-03 03:25:02 +08:00
|
|
|
breakoutName={breakoutName}
|
2018-12-18 23:15:51 +08:00
|
|
|
/>,
|
|
|
|
);
|
2016-11-07 23:52:39 +08:00
|
|
|
|
2018-12-06 01:42:31 +08:00
|
|
|
const closeBreakoutJoinConfirmation = mountModal => mountModal(null);
|
2017-10-13 05:05:37 +08:00
|
|
|
|
2018-11-23 22:14:48 +08:00
|
|
|
class NavBar extends PureComponent {
|
2019-01-16 21:08:20 +08:00
|
|
|
static handleToggleUserList() {
|
|
|
|
Session.set(
|
|
|
|
'openPanel',
|
|
|
|
Session.get('openPanel') !== ''
|
|
|
|
? ''
|
|
|
|
: 'userlist',
|
|
|
|
);
|
|
|
|
Session.set('idChatOpen', '');
|
|
|
|
}
|
|
|
|
|
2016-04-29 03:02:51 +08:00
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
2016-05-04 04:40:46 +08:00
|
|
|
|
2016-11-07 23:52:39 +08:00
|
|
|
this.state = {
|
|
|
|
isActionsOpen: false,
|
2016-11-14 19:57:10 +08:00
|
|
|
didSendBreakoutInvite: false,
|
2019-01-04 04:28:27 +08:00
|
|
|
time: (props.recordProps.time ? props.recordProps.time : 0),
|
2019-04-04 04:51:18 +08:00
|
|
|
amIModerator: props.amIModerator,
|
2016-11-07 23:52:39 +08:00
|
|
|
};
|
|
|
|
|
2019-01-04 02:14:35 +08:00
|
|
|
this.incrementTime = this.incrementTime.bind(this);
|
2016-05-04 04:40:46 +08:00
|
|
|
}
|
|
|
|
|
2019-01-04 02:14:35 +08:00
|
|
|
componentDidMount() {
|
2019-01-09 06:17:11 +08:00
|
|
|
const {
|
|
|
|
processOutsideToggleRecording,
|
|
|
|
connectRecordingObserver,
|
|
|
|
} = this.props;
|
|
|
|
|
2019-01-04 05:09:00 +08:00
|
|
|
if (Meteor.settings.public.allowOutsideCommands.toggleRecording
|
|
|
|
|| getFromUserSettings('outsideToggleRecording', false)) {
|
2019-01-09 06:17:11 +08:00
|
|
|
connectRecordingObserver();
|
|
|
|
window.addEventListener('message', processOutsideToggleRecording);
|
2019-01-04 02:14:35 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-05 00:25:56 +08:00
|
|
|
static getDerivedStateFromProps(nextProps) {
|
|
|
|
return { amIModerator: nextProps.amIModerator };
|
2019-04-04 04:51:18 +08:00
|
|
|
}
|
|
|
|
|
2017-10-23 23:47:14 +08:00
|
|
|
componentDidUpdate(oldProps) {
|
2017-10-11 06:08:51 +08:00
|
|
|
const {
|
|
|
|
breakouts,
|
|
|
|
isBreakoutRoom,
|
2018-10-16 04:03:17 +08:00
|
|
|
mountModal,
|
2019-01-04 04:28:27 +08:00
|
|
|
recordProps,
|
2019-02-18 20:44:14 +08:00
|
|
|
currentBreakoutUser,
|
|
|
|
getBreakoutByUser,
|
2017-10-11 06:08:51 +08:00
|
|
|
} = this.props;
|
|
|
|
|
2019-01-04 04:28:27 +08:00
|
|
|
if (!recordProps.recording) {
|
2019-01-04 02:14:35 +08:00
|
|
|
clearInterval(this.interval);
|
|
|
|
this.interval = null;
|
|
|
|
} else if (this.interval === null) {
|
|
|
|
this.interval = setInterval(this.incrementTime, 1000);
|
|
|
|
}
|
2019-01-04 04:50:43 +08:00
|
|
|
|
2018-12-18 23:15:51 +08:00
|
|
|
const {
|
|
|
|
didSendBreakoutInvite,
|
|
|
|
} = this.state;
|
2019-01-04 02:14:35 +08:00
|
|
|
|
2017-10-23 23:47:14 +08:00
|
|
|
const hadBreakouts = oldProps.breakouts.length;
|
|
|
|
const hasBreakouts = breakouts.length;
|
2017-10-24 00:15:55 +08:00
|
|
|
if (!hasBreakouts && hadBreakouts) {
|
2018-10-16 04:03:17 +08:00
|
|
|
closeBreakoutJoinConfirmation(mountModal);
|
2017-10-24 00:15:55 +08:00
|
|
|
}
|
|
|
|
|
2019-02-18 20:44:14 +08:00
|
|
|
if (hasBreakouts && currentBreakoutUser) {
|
|
|
|
const currentIsertedTime = currentBreakoutUser.insertedTime;
|
|
|
|
const oldCurrentUser = oldProps.currentBreakoutUser || {};
|
|
|
|
const oldInsertedTime = oldCurrentUser.insertedTime;
|
|
|
|
|
|
|
|
if (currentIsertedTime !== oldInsertedTime) {
|
|
|
|
const breakoutRoom = getBreakoutByUser(currentBreakoutUser);
|
|
|
|
this.inviteUserToBreakout(breakoutRoom);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-11 06:08:51 +08:00
|
|
|
breakouts.forEach((breakout) => {
|
2019-03-07 21:19:12 +08:00
|
|
|
const userOnMeeting = breakout.users.filter(u => u.userId === Auth.userID).length;
|
2019-03-15 00:45:20 +08:00
|
|
|
if (breakout.freeJoin
|
|
|
|
&& !didSendBreakoutInvite
|
|
|
|
&& !userOnMeeting
|
|
|
|
&& !isBreakoutRoom) {
|
2019-03-14 22:57:06 +08:00
|
|
|
this.inviteUserToBreakout(breakout);
|
2019-03-07 21:19:12 +08:00
|
|
|
this.setState({ didSendBreakoutInvite: true });
|
|
|
|
}
|
|
|
|
|
2017-10-11 06:08:51 +08:00
|
|
|
if (!breakout.users) {
|
|
|
|
return;
|
|
|
|
}
|
2017-10-23 23:47:14 +08:00
|
|
|
|
2018-11-27 20:44:22 +08:00
|
|
|
if (!userOnMeeting) return;
|
|
|
|
|
2019-04-04 04:51:18 +08:00
|
|
|
if ((!didSendBreakoutInvite && !isBreakoutRoom)) {
|
2018-07-07 01:46:07 +08:00
|
|
|
this.inviteUserToBreakout(breakout);
|
2017-10-11 06:08:51 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-12-18 23:15:51 +08:00
|
|
|
if (!breakouts.length && didSendBreakoutInvite) {
|
2017-10-23 23:47:14 +08:00
|
|
|
this.setState({ didSendBreakoutInvite: false });
|
2017-10-11 06:08:51 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-04 02:14:35 +08:00
|
|
|
componentWillUnmount() {
|
2019-01-04 05:09:00 +08:00
|
|
|
clearInterval(this.interval);
|
2019-01-04 02:14:35 +08:00
|
|
|
}
|
|
|
|
|
2018-07-07 01:46:07 +08:00
|
|
|
inviteUserToBreakout(breakout) {
|
2017-05-03 23:06:28 +08:00
|
|
|
const {
|
|
|
|
mountModal,
|
|
|
|
} = this.props;
|
|
|
|
|
2016-11-14 19:57:10 +08:00
|
|
|
this.setState({ didSendBreakoutInvite: true }, () => {
|
2018-07-07 01:46:07 +08:00
|
|
|
openBreakoutJoinConfirmation.call(this, breakout, breakout.name, mountModal);
|
2016-11-14 19:57:10 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-01-04 02:14:35 +08:00
|
|
|
incrementTime() {
|
2019-01-04 04:28:27 +08:00
|
|
|
const { recordProps } = this.props;
|
2019-01-04 04:50:43 +08:00
|
|
|
const { time } = this.state;
|
2019-01-04 02:14:35 +08:00
|
|
|
|
2019-01-04 04:50:43 +08:00
|
|
|
if (recordProps.time > time) {
|
2019-01-04 04:28:27 +08:00
|
|
|
this.setState({ time: recordProps.time + 1 });
|
2019-01-04 02:14:35 +08:00
|
|
|
} else {
|
2019-01-04 04:50:43 +08:00
|
|
|
this.setState({ time: time + 1 });
|
2019-01-04 02:14:35 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-07 23:52:39 +08:00
|
|
|
renderPresentationTitle() {
|
2016-11-29 03:48:02 +08:00
|
|
|
const {
|
2017-03-15 05:06:52 +08:00
|
|
|
breakouts,
|
2017-03-16 01:43:03 +08:00
|
|
|
isBreakoutRoom,
|
2017-03-15 05:06:52 +08:00
|
|
|
presentationTitle,
|
2016-11-29 03:48:02 +08:00
|
|
|
} = this.props;
|
|
|
|
|
2018-12-18 23:15:51 +08:00
|
|
|
const {
|
|
|
|
isActionsOpen,
|
|
|
|
} = this.state;
|
|
|
|
|
2017-04-26 22:57:40 +08:00
|
|
|
if (isBreakoutRoom || !breakouts.length) {
|
2016-11-07 23:52:39 +08:00
|
|
|
return (
|
|
|
|
<h1 className={styles.presentationTitle}>{presentationTitle}</h1>
|
|
|
|
);
|
|
|
|
}
|
2018-07-07 01:46:07 +08:00
|
|
|
const breakoutItems = breakouts.map(breakout => this.renderBreakoutItem(breakout));
|
2016-11-07 23:52:39 +08:00
|
|
|
|
|
|
|
return (
|
2018-12-18 23:15:51 +08:00
|
|
|
<Dropdown isOpen={isActionsOpen}>
|
2016-12-06 03:16:52 +08:00
|
|
|
<DropdownTrigger>
|
2016-12-06 03:26:08 +08:00
|
|
|
<h1 className={cx(styles.presentationTitle, styles.dropdownBreakout)}>
|
2018-12-06 01:42:31 +08:00
|
|
|
{presentationTitle}
|
|
|
|
{' '}
|
|
|
|
<Icon iconName="down-arrow" />
|
2016-11-07 23:52:39 +08:00
|
|
|
</h1>
|
|
|
|
</DropdownTrigger>
|
|
|
|
<DropdownContent
|
2017-06-03 03:25:02 +08:00
|
|
|
placement="bottom"
|
|
|
|
>
|
2016-11-07 23:52:39 +08:00
|
|
|
<DropdownList>
|
2018-07-07 01:46:07 +08:00
|
|
|
{breakoutItems}
|
2016-11-07 23:52:39 +08:00
|
|
|
</DropdownList>
|
|
|
|
</DropdownContent>
|
|
|
|
</Dropdown>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
renderBreakoutItem(breakout) {
|
2016-11-29 03:48:02 +08:00
|
|
|
const {
|
2017-05-03 23:06:28 +08:00
|
|
|
mountModal,
|
2016-11-29 03:48:02 +08:00
|
|
|
} = this.props;
|
|
|
|
|
2016-11-07 23:52:39 +08:00
|
|
|
const breakoutName = breakout.name;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<DropdownListItem
|
|
|
|
key={_.uniqueId('action-header')}
|
|
|
|
label={breakoutName}
|
2018-12-18 23:15:51 +08:00
|
|
|
onClick={
|
|
|
|
openBreakoutJoinConfirmation.bind(this, breakout, breakoutName, mountModal)
|
|
|
|
}
|
2016-12-09 00:20:47 +08:00
|
|
|
/>
|
2016-11-07 23:52:39 +08:00
|
|
|
);
|
|
|
|
}
|
2018-05-02 08:02:45 +08:00
|
|
|
|
2017-10-11 06:08:51 +08:00
|
|
|
render() {
|
2018-05-02 08:02:45 +08:00
|
|
|
const {
|
2018-11-01 02:51:56 +08:00
|
|
|
hasUnreadMessages,
|
2018-12-21 03:39:04 +08:00
|
|
|
recordProps,
|
2018-11-01 02:51:56 +08:00
|
|
|
isExpanded,
|
|
|
|
intl,
|
|
|
|
shortcuts: TOGGLE_USERLIST_AK,
|
2019-01-04 02:14:35 +08:00
|
|
|
mountModal,
|
2018-05-02 08:02:45 +08:00
|
|
|
} = this.props;
|
2017-10-11 06:08:51 +08:00
|
|
|
|
2018-12-21 03:39:04 +08:00
|
|
|
const recordingMessage = recordProps.recording ? 'recordingIndicatorOn' : 'recordingIndicatorOff';
|
2018-02-24 00:26:33 +08:00
|
|
|
|
2019-04-04 04:51:18 +08:00
|
|
|
const { time, amIModerator } = this.state;
|
2019-01-04 04:50:43 +08:00
|
|
|
|
2019-01-04 02:14:35 +08:00
|
|
|
if (!this.interval) {
|
|
|
|
this.interval = setInterval(this.incrementTime, 1000);
|
|
|
|
}
|
|
|
|
|
2017-10-11 06:08:51 +08:00
|
|
|
const toggleBtnClasses = {};
|
|
|
|
toggleBtnClasses[styles.btn] = true;
|
|
|
|
toggleBtnClasses[styles.btnWithNotificationDot] = hasUnreadMessages;
|
|
|
|
|
2018-10-16 01:49:17 +08:00
|
|
|
let ariaLabel = intl.formatMessage(intlMessages.toggleUserListAria);
|
|
|
|
ariaLabel += hasUnreadMessages ? (` ${intl.formatMessage(intlMessages.newMessages)}`) : '';
|
|
|
|
|
2017-10-11 06:08:51 +08:00
|
|
|
return (
|
|
|
|
<div className={styles.navbar}>
|
|
|
|
<div className={styles.left}>
|
|
|
|
<Button
|
2018-01-09 10:43:34 +08:00
|
|
|
data-test="userListToggleButton"
|
2019-01-16 21:08:20 +08:00
|
|
|
onClick={NavBar.handleToggleUserList}
|
2017-10-11 06:08:51 +08:00
|
|
|
ghost
|
|
|
|
circle
|
|
|
|
hideLabel
|
|
|
|
label={intl.formatMessage(intlMessages.toggleUserListLabel)}
|
2018-10-16 01:49:17 +08:00
|
|
|
aria-label={ariaLabel}
|
2018-02-23 01:30:12 +08:00
|
|
|
icon="user"
|
2017-10-11 06:08:51 +08:00
|
|
|
className={cx(toggleBtnClasses)}
|
|
|
|
aria-expanded={isExpanded}
|
2018-05-02 08:02:45 +08:00
|
|
|
accessKey={TOGGLE_USERLIST_AK}
|
2017-10-11 06:08:51 +08:00
|
|
|
/>
|
|
|
|
</div>
|
2018-02-23 01:30:12 +08:00
|
|
|
<div className={styles.center}>
|
2017-10-11 06:08:51 +08:00
|
|
|
{this.renderPresentationTitle()}
|
2018-12-21 03:39:04 +08:00
|
|
|
{recordProps.record
|
2019-01-28 21:33:50 +08:00
|
|
|
? <span className={styles.presentationTitleSeparator} aria-hidden>|</span>
|
2018-12-06 01:42:31 +08:00
|
|
|
: null}
|
2018-02-24 00:26:33 +08:00
|
|
|
<RecordingIndicator
|
2018-12-21 03:39:04 +08:00
|
|
|
{...recordProps}
|
2018-02-24 00:26:33 +08:00
|
|
|
title={intl.formatMessage(intlMessages[recordingMessage])}
|
2019-01-04 05:09:00 +08:00
|
|
|
buttonTitle={(!recordProps.recording ? intl.formatMessage(intlMessages.startTitle)
|
|
|
|
: intl.formatMessage(intlMessages.stopTitle))}
|
2019-01-04 02:14:35 +08:00
|
|
|
mountModal={mountModal}
|
2019-01-04 05:09:00 +08:00
|
|
|
time={time}
|
2019-04-04 04:51:18 +08:00
|
|
|
amIModerator={amIModerator}
|
2018-02-24 00:26:33 +08:00
|
|
|
/>
|
2017-10-11 06:08:51 +08:00
|
|
|
</div>
|
|
|
|
<div className={styles.right}>
|
2019-04-04 04:51:18 +08:00
|
|
|
<SettingsDropdownContainer amIModerator={amIModerator} />
|
2017-10-11 06:08:51 +08:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
2016-04-29 03:02:51 +08:00
|
|
|
}
|
|
|
|
|
2016-05-04 22:48:53 +08:00
|
|
|
NavBar.propTypes = propTypes;
|
|
|
|
NavBar.defaultProps = defaultProps;
|
2018-11-01 02:51:56 +08:00
|
|
|
export default withShortcutHelper(withModalMounter(injectIntl(NavBar)), 'toggleUserList');
|