2018-10-24 01:18:09 +08:00
|
|
|
import React from 'react';
|
|
|
|
import { withTracker } from 'meteor/react-meteor-data';
|
|
|
|
import { defineMessages, injectIntl } from 'react-intl';
|
2022-02-16 01:57:50 +08:00
|
|
|
import injectNotify from '/imports/ui/components/common/toast/inject-notify/component';
|
2018-10-24 01:18:09 +08:00
|
|
|
import humanizeSeconds from '/imports/utils/humanizeSeconds';
|
|
|
|
import _ from 'lodash';
|
2023-02-16 21:29:51 +08:00
|
|
|
import MeetingRemainingTimeComponent from './component';
|
2022-10-19 19:36:25 +08:00
|
|
|
import BreakoutService from '/imports/ui/components/breakout-room/service';
|
2022-03-01 21:13:23 +08:00
|
|
|
import { Text, Time } from './styles';
|
2023-02-14 21:55:58 +08:00
|
|
|
import { meetingIsBreakout } from '/imports/ui/components/app/service';
|
2018-10-24 01:18:09 +08:00
|
|
|
|
|
|
|
const intlMessages = defineMessages({
|
|
|
|
failedMessage: {
|
|
|
|
id: 'app.failedMessage',
|
|
|
|
description: 'Notification for connecting to server problems',
|
|
|
|
},
|
|
|
|
connectingMessage: {
|
|
|
|
id: 'app.connectingMessage',
|
|
|
|
description: 'Notification message for when client is connecting to server',
|
|
|
|
},
|
|
|
|
waitingMessage: {
|
|
|
|
id: 'app.waitingMessage',
|
|
|
|
description: 'Notification message for disconnection with reconnection counter',
|
|
|
|
},
|
|
|
|
breakoutTimeRemaining: {
|
|
|
|
id: 'app.breakoutTimeRemainingMessage',
|
|
|
|
description: 'Message that tells how much time is remaining for the breakout room',
|
|
|
|
},
|
|
|
|
breakoutWillClose: {
|
|
|
|
id: 'app.breakoutWillCloseMessage',
|
|
|
|
description: 'Message that tells time has ended and breakout will close',
|
|
|
|
},
|
|
|
|
calculatingBreakoutTimeRemaining: {
|
|
|
|
id: 'app.calculatingBreakoutTimeRemaining',
|
|
|
|
description: 'Message that tells that the remaining time is being calculated',
|
|
|
|
},
|
2022-04-29 21:05:29 +08:00
|
|
|
alertBreakoutEndsUnderMinutes: {
|
|
|
|
id: 'app.meeting.alertBreakoutEndsUnderMinutes',
|
|
|
|
description: 'Alert that tells that the breakout ends under x minutes',
|
|
|
|
},
|
2023-02-14 21:55:58 +08:00
|
|
|
alertMeetingEndsUnderMinutes: {
|
|
|
|
id: 'app.meeting.alertMeetingEndsUnderMinutes',
|
|
|
|
description: 'Alert that tells that the meeting ends under x minutes',
|
|
|
|
},
|
2018-10-24 01:18:09 +08:00
|
|
|
});
|
|
|
|
|
2019-05-08 02:15:34 +08:00
|
|
|
let timeRemaining = 0;
|
2021-02-26 21:44:35 +08:00
|
|
|
let prevTimeRemaining = 0;
|
2022-04-29 21:05:29 +08:00
|
|
|
let lastAlertTime = null;
|
|
|
|
|
|
|
|
const METEOR_SETTINGS_APP = Meteor.settings.public.app;
|
|
|
|
const REMAINING_TIME_ALERT_THRESHOLD_ARRAY = METEOR_SETTINGS_APP.remainingTimeAlertThresholdArray;
|
2021-02-26 21:44:35 +08:00
|
|
|
|
2019-05-08 02:15:34 +08:00
|
|
|
const timeRemainingDep = new Tracker.Dependency();
|
|
|
|
let timeRemainingInterval = null;
|
|
|
|
|
2018-11-02 00:53:27 +08:00
|
|
|
class breakoutRemainingTimeContainer extends React.Component {
|
|
|
|
componentWillUnmount() {
|
|
|
|
clearInterval(timeRemainingInterval);
|
|
|
|
timeRemainingInterval = null;
|
|
|
|
timeRemaining = null;
|
2018-10-24 01:18:09 +08:00
|
|
|
}
|
2018-11-02 00:53:27 +08:00
|
|
|
|
|
|
|
render() {
|
2022-03-01 21:13:23 +08:00
|
|
|
const { message, bold } = this.props;
|
2019-05-08 02:15:34 +08:00
|
|
|
if (_.isEmpty(message)) {
|
2018-11-02 00:53:27 +08:00
|
|
|
return null;
|
|
|
|
}
|
2022-03-01 21:13:23 +08:00
|
|
|
if (bold) {
|
2022-07-20 23:22:46 +08:00
|
|
|
const words = message.split(' ');
|
|
|
|
const time = words.pop();
|
|
|
|
const text = words.join(' ');
|
2022-03-01 21:13:23 +08:00
|
|
|
return (
|
2023-02-16 21:29:51 +08:00
|
|
|
<MeetingRemainingTimeComponent>
|
2022-07-20 23:22:46 +08:00
|
|
|
<Text>{text}</Text>
|
2022-03-01 21:13:23 +08:00
|
|
|
<br />
|
2022-09-30 19:17:15 +08:00
|
|
|
<Time data-test="breakoutRemainingTime">{time}</Time>
|
2023-02-16 21:29:51 +08:00
|
|
|
</MeetingRemainingTimeComponent>
|
2022-03-01 21:13:23 +08:00
|
|
|
);
|
|
|
|
}
|
2018-11-02 00:53:27 +08:00
|
|
|
return (
|
2023-02-16 21:29:51 +08:00
|
|
|
<MeetingRemainingTimeComponent>
|
2019-05-08 02:15:34 +08:00
|
|
|
{message}
|
2023-02-16 21:29:51 +08:00
|
|
|
</MeetingRemainingTimeComponent>
|
2018-11-02 00:53:27 +08:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2018-10-24 01:18:09 +08:00
|
|
|
|
|
|
|
const getTimeRemaining = () => {
|
|
|
|
timeRemainingDep.depend();
|
|
|
|
return timeRemaining;
|
|
|
|
};
|
|
|
|
|
2019-05-29 04:29:04 +08:00
|
|
|
const setTimeRemaining = (sec) => {
|
2018-10-24 01:18:09 +08:00
|
|
|
if (sec !== timeRemaining) {
|
|
|
|
timeRemaining = sec;
|
|
|
|
timeRemainingDep.changed();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
const startCounter = (sec, set, get, interval) => {
|
|
|
|
clearInterval(interval);
|
2019-05-29 04:29:04 +08:00
|
|
|
if (!sec) return;
|
2018-10-24 01:18:09 +08:00
|
|
|
set(sec);
|
2019-05-29 04:29:04 +08:00
|
|
|
return setInterval(() => set(get() - 1), 1000);
|
2018-10-24 01:18:09 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2019-02-06 03:18:20 +08:00
|
|
|
export default injectNotify(injectIntl(withTracker(({
|
|
|
|
breakoutRoom,
|
|
|
|
intl,
|
|
|
|
notify,
|
|
|
|
messageDuration,
|
|
|
|
timeEndedMessage,
|
2022-03-01 21:13:23 +08:00
|
|
|
fromBreakoutPanel,
|
2022-04-29 21:18:25 +08:00
|
|
|
displayAlerts,
|
2019-01-24 00:13:03 +08:00
|
|
|
}) => {
|
2018-10-24 01:18:09 +08:00
|
|
|
const data = {};
|
|
|
|
if (breakoutRoom) {
|
|
|
|
const roomRemainingTime = breakoutRoom.timeRemaining;
|
2021-02-26 21:44:35 +08:00
|
|
|
const localRemainingTime = getTimeRemaining();
|
|
|
|
const shouldResync = prevTimeRemaining !== roomRemainingTime && roomRemainingTime !== localRemainingTime;
|
|
|
|
|
|
|
|
if ((!timeRemainingInterval || shouldResync) && roomRemainingTime) {
|
|
|
|
prevTimeRemaining = roomRemainingTime;
|
2018-10-24 01:18:09 +08:00
|
|
|
|
|
|
|
timeRemainingInterval = startCounter(
|
|
|
|
roomRemainingTime,
|
|
|
|
setTimeRemaining,
|
|
|
|
getTimeRemaining,
|
|
|
|
timeRemainingInterval,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
} else if (timeRemainingInterval) {
|
|
|
|
clearInterval(timeRemainingInterval);
|
|
|
|
}
|
|
|
|
|
2019-05-29 04:29:04 +08:00
|
|
|
if (timeRemaining >= 0 && timeRemainingInterval) {
|
2018-10-24 01:18:09 +08:00
|
|
|
if (timeRemaining > 0) {
|
|
|
|
const time = getTimeRemaining();
|
2022-04-29 21:05:29 +08:00
|
|
|
const alertsInSeconds = REMAINING_TIME_ALERT_THRESHOLD_ARRAY.map((item) => item * 60);
|
|
|
|
|
2022-04-29 21:18:25 +08:00
|
|
|
if (alertsInSeconds.includes(time) && time !== lastAlertTime && displayAlerts) {
|
2022-04-29 21:05:29 +08:00
|
|
|
const timeInMinutes = time / 60;
|
2023-02-14 21:55:58 +08:00
|
|
|
const message = meetingIsBreakout()
|
|
|
|
? intlMessages.alertBreakoutEndsUnderMinutes
|
|
|
|
: intlMessages.alertMeetingEndsUnderMinutes;
|
|
|
|
const msg = { id: `${message.id}${timeInMinutes === 1 ? 'Singular' : 'Plural'}` };
|
|
|
|
const alertMessage = intl.formatMessage(msg, { 0: timeInMinutes });
|
2022-04-29 21:05:29 +08:00
|
|
|
|
|
|
|
lastAlertTime = time;
|
2020-06-18 05:08:36 +08:00
|
|
|
notify(alertMessage, 'info', 'rooms');
|
|
|
|
}
|
2018-10-24 01:18:09 +08:00
|
|
|
data.message = intl.formatMessage(messageDuration, { 0: humanizeSeconds(time) });
|
2022-03-01 21:13:23 +08:00
|
|
|
if (fromBreakoutPanel) data.bold = true;
|
2018-10-24 01:18:09 +08:00
|
|
|
} else {
|
|
|
|
clearInterval(timeRemainingInterval);
|
2022-11-23 04:07:43 +08:00
|
|
|
BreakoutService.setCapturedContentUploading();
|
2019-01-24 00:13:03 +08:00
|
|
|
data.message = intl.formatMessage(timeEndedMessage || intlMessages.breakoutWillClose);
|
2018-10-24 01:18:09 +08:00
|
|
|
}
|
|
|
|
} else if (breakoutRoom) {
|
|
|
|
data.message = intl.formatMessage(intlMessages.calculatingBreakoutTimeRemaining);
|
|
|
|
}
|
|
|
|
return data;
|
2019-02-06 03:18:20 +08:00
|
|
|
})(breakoutRemainingTimeContainer)));
|