bigbluebutton-Github/bigbluebutton-html5/imports/ui/components/notifications-bar/container.jsx

214 lines
6.3 KiB
React
Raw Normal View History

import { Meteor } from 'meteor/meteor';
import { withTracker } from 'meteor/react-meteor-data';
import React, { useEffect } from 'react';
import { defineMessages, injectIntl } from 'react-intl';
2016-11-14 19:57:10 +08:00
import Auth from '/imports/ui/services/auth';
import { MeetingTimeRemaining } from '/imports/api/meetings';
import Meetings from '/imports/api/meetings';
import MeetingRemainingTime from './meeting-remaining-time/container';
2021-10-27 21:46:08 +08:00
import Styled from './styles';
2021-09-11 04:48:52 +08:00
import { layoutSelectInput, layoutDispatch } from '../layout/context';
import { ACTIONS } from '../layout/enums';
2023-02-23 21:27:16 +08:00
import { isEmpty } from 'radash';
import breakoutService from '/imports/ui/components/breakout-room/service';
import NotificationsBar from './component';
// disconnected and trying to open a new connection
const STATUS_CONNECTING = 'connecting';
// permanently failed to connect; e.g., the client and server support different versions of DDP
const STATUS_FAILED = 'failed';
// failed to connect and waiting to try to reconnect
const STATUS_WAITING = 'waiting';
2019-03-12 08:34:34 +08:00
const METEOR_SETTINGS_APP = Meteor.settings.public.app;
2020-06-17 22:34:02 +08:00
const REMAINING_TIME_THRESHOLD = METEOR_SETTINGS_APP.remainingTimeThreshold;
const intlMessages = defineMessages({
failedMessage: {
id: 'app.failedMessage',
2017-05-17 22:32:35 +08:00
description: 'Notification for connecting to server problems',
},
connectingMessage: {
id: 'app.connectingMessage',
2017-05-17 22:32:35 +08:00
description: 'Notification message for when client is connecting to server',
},
waitingMessage: {
id: 'app.waitingMessage',
2017-05-17 22:32:35 +08:00
description: 'Notification message for disconnection with reconnection counter',
},
2019-06-06 02:19:13 +08:00
retryNow: {
id: 'app.retryNow',
description: 'Retry now text for reconnection counter',
},
2016-11-15 00:12:54 +08:00
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',
},
meetingTimeRemaining: {
id: 'app.meeting.meetingTimeRemaining',
description: 'Message that tells how much time is remaining for the meeting',
},
meetingWillClose: {
id: 'app.meeting.meetingTimeHasEnded',
description: 'Message that tells time has ended and meeting will close',
},
alertMeetingEndsUnderMinutes: {
id: 'app.meeting.alertMeetingEndsUnderMinutes',
description: 'Alert that tells that the meeting ends under x minutes',
},
alertBreakoutEndsUnderMinutes: {
id: 'app.meeting.alertBreakoutEndsUnderMinutes',
description: 'Alert that tells that the breakout ends under x minutes',
},
});
2017-08-12 04:17:35 +08:00
const NotificationsBarContainer = (props) => {
2019-03-16 04:07:14 +08:00
const { message, color } = props;
2021-09-11 04:48:52 +08:00
const notificationsBar = layoutSelectInput((i) => i.notificationsBar);
const layoutContextDispatch = layoutDispatch();
const { hasNotification } = notificationsBar;
useEffect(() => {
const localHasNotification = !!message;
2021-08-09 22:24:02 +08:00
if (localHasNotification !== hasNotification) {
2021-08-05 19:03:24 +08:00
layoutContextDispatch({
type: ACTIONS.SET_HAS_NOTIFICATIONS_BAR,
value: localHasNotification,
});
}
}, [message, hasNotification]);
2023-02-23 21:27:16 +08:00
if (isEmpty(message)) {
2017-08-12 04:17:35 +08:00
return null;
}
2017-08-12 04:17:35 +08:00
return (
<NotificationsBar color={color}>
{message}
</NotificationsBar>
);
};
let retrySeconds = 0;
2017-06-03 03:25:02 +08:00
const retrySecondsDep = new Tracker.Dependency();
let retryInterval = null;
const getRetrySeconds = () => {
retrySecondsDep.depend();
return retrySeconds;
};
const setRetrySeconds = (sec = 0) => {
if (sec !== retrySeconds) {
retrySeconds = sec;
retrySecondsDep.changed();
}
};
const startCounter = (sec, set, get, interval) => {
clearInterval(interval);
set(sec);
return setInterval(() => {
set(get() - 1);
}, 1000);
};
2016-11-22 23:46:08 +08:00
2019-06-06 02:19:13 +08:00
const reconnect = () => {
Meteor.reconnect();
};
export default injectIntl(withTracker(({ intl }) => {
2017-08-12 04:17:35 +08:00
const { status, connected, retryTime } = Meteor.status();
2017-06-03 03:25:02 +08:00
const data = {};
if (!connected) {
data.color = 'primary';
switch (status) {
2017-08-12 04:17:35 +08:00
case STATUS_FAILED: {
data.color = 'danger';
data.message = intl.formatMessage(intlMessages.failedMessage);
break;
2017-08-12 04:17:35 +08:00
}
case STATUS_CONNECTING: {
data.message = intl.formatMessage(intlMessages.connectingMessage);
break;
2017-08-12 04:17:35 +08:00
}
case STATUS_WAITING: {
2016-11-15 00:12:54 +08:00
const sec = Math.round((retryTime - (new Date()).getTime()) / 1000);
retryInterval = startCounter(sec, setRetrySeconds, getRetrySeconds, retryInterval);
2019-06-06 02:19:13 +08:00
data.message = (
2021-08-09 22:24:02 +08:00
<>
2019-06-06 02:19:13 +08:00
{intl.formatMessage(intlMessages.waitingMessage, { 0: getRetrySeconds() })}
2021-10-27 21:46:08 +08:00
<Styled.RetryButton type="button" onClick={reconnect}>
2019-06-06 02:19:13 +08:00
{intl.formatMessage(intlMessages.retryNow)}
2021-10-27 21:46:08 +08:00
</Styled.RetryButton>
2021-08-09 22:24:02 +08:00
</>
);
break;
2017-08-12 04:17:35 +08:00
}
default:
break;
}
return data;
}
2016-11-14 19:57:10 +08:00
const meetingId = Auth.meetingID;
const breakouts = breakoutService.getBreakouts();
2016-11-15 00:12:54 +08:00
2017-08-12 04:17:35 +08:00
if (breakouts.length > 0) {
2021-08-09 22:24:02 +08:00
const currentBreakout = breakouts.find((b) => b.breakoutId === meetingId);
2017-08-12 04:17:35 +08:00
2016-11-14 19:57:10 +08:00
if (currentBreakout) {
data.message = (
<MeetingRemainingTime
breakoutRoom={currentBreakout}
messageDuration={intlMessages.breakoutTimeRemaining}
timeEndedMessage={intlMessages.breakoutWillClose}
displayAlerts={true}
/>
);
2016-11-14 19:57:10 +08:00
}
}
2016-11-14 19:57:10 +08:00
2019-09-09 22:48:50 +08:00
const meetingTimeRemaining = MeetingTimeRemaining.findOne({ meetingId });
const Meeting = Meetings.findOne({ meetingId },
{ fields: { 'meetingProp.isBreakout': 1 } });
2019-09-09 22:48:50 +08:00
if (meetingTimeRemaining && Meeting) {
const { timeRemaining } = meetingTimeRemaining;
const { isBreakout } = Meeting.meetingProp;
2020-06-17 22:34:02 +08:00
const underThirtyMin = timeRemaining && timeRemaining <= (REMAINING_TIME_THRESHOLD * 60);
if (underThirtyMin && !isBreakout) {
data.message = (
<MeetingRemainingTime
2019-09-09 22:48:50 +08:00
breakoutRoom={meetingTimeRemaining}
messageDuration={intlMessages.meetingTimeRemaining}
timeEndedMessage={intlMessages.meetingWillClose}
displayAlerts={true}
/>
);
2016-11-15 00:12:54 +08:00
}
2016-11-14 19:57:10 +08:00
}
2019-03-16 04:07:14 +08:00
data.alert = true;
2016-11-15 00:12:54 +08:00
data.color = 'primary';
return data;
})(NotificationsBarContainer));