2016-08-10 00:28:16 +08:00
|
|
|
import { Meteor } from 'meteor/meteor';
|
2018-01-08 12:44:42 +08:00
|
|
|
import { withTracker } from 'meteor/react-meteor-data';
|
2021-09-10 21:16:44 +08:00
|
|
|
import React, { useEffect } from 'react';
|
2016-08-10 00:28:16 +08:00
|
|
|
import { defineMessages, injectIntl } from 'react-intl';
|
2016-11-14 19:57:10 +08:00
|
|
|
import Auth from '/imports/ui/services/auth';
|
2024-05-01 03:14:22 +08:00
|
|
|
import Meetings from '/imports/api/meetings';
|
2023-10-10 20:41:47 +08:00
|
|
|
import { isEmpty } from 'radash';
|
2024-01-25 00:47:34 +08:00
|
|
|
import MeetingRemainingTime from '/imports/ui/components/common/remaining-time/meeting-duration/component';
|
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';
|
2021-07-13 00:24:53 +08:00
|
|
|
import { ACTIONS } from '../layout/enums';
|
2016-08-10 00:28:16 +08:00
|
|
|
|
|
|
|
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';
|
|
|
|
|
|
|
|
const intlMessages = defineMessages({
|
|
|
|
failedMessage: {
|
|
|
|
id: 'app.failedMessage',
|
2017-05-17 22:32:35 +08:00
|
|
|
description: 'Notification for connecting to server problems',
|
2016-08-10 00:28:16 +08:00
|
|
|
},
|
|
|
|
connectingMessage: {
|
|
|
|
id: 'app.connectingMessage',
|
2017-05-17 22:32:35 +08:00
|
|
|
description: 'Notification message for when client is connecting to server',
|
2016-08-10 00:28:16 +08:00
|
|
|
},
|
|
|
|
waitingMessage: {
|
|
|
|
id: 'app.waitingMessage',
|
2017-05-17 22:32:35 +08:00
|
|
|
description: 'Notification message for disconnection with reconnection counter',
|
2016-08-10 00:28:16 +08:00
|
|
|
},
|
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
|
|
|
calculatingBreakoutTimeRemaining: {
|
|
|
|
id: 'app.calculatingBreakoutTimeRemaining',
|
|
|
|
description: 'Message that tells that the remaining time is being calculated',
|
|
|
|
},
|
2020-06-18 05:08:36 +08:00
|
|
|
alertMeetingEndsUnderMinutes: {
|
|
|
|
id: 'app.meeting.alertMeetingEndsUnderMinutes',
|
|
|
|
description: 'Alert that tells that the meeting ends under x minutes',
|
2019-02-06 03:18:20 +08:00
|
|
|
},
|
2020-06-18 05:08:36 +08:00
|
|
|
alertBreakoutEndsUnderMinutes: {
|
|
|
|
id: 'app.meeting.alertBreakoutEndsUnderMinutes',
|
|
|
|
description: 'Alert that tells that the breakout ends under x minutes',
|
2019-02-06 03:18:20 +08:00
|
|
|
},
|
2016-08-10 00:28:16 +08:00
|
|
|
});
|
|
|
|
|
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-10 21:16:44 +08:00
|
|
|
|
2021-09-11 04:48:52 +08:00
|
|
|
const notificationsBar = layoutSelectInput((i) => i.notificationsBar);
|
|
|
|
const layoutContextDispatch = layoutDispatch();
|
2021-09-10 21:16:44 +08:00
|
|
|
|
2021-07-13 00:24:53 +08:00
|
|
|
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({
|
2021-07-13 00:24:53 +08:00
|
|
|
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;
|
2016-08-10 00:28:16 +08:00
|
|
|
}
|
|
|
|
|
2017-08-12 04:17:35 +08:00
|
|
|
return (
|
|
|
|
<NotificationsBar color={color}>
|
|
|
|
{message}
|
|
|
|
</NotificationsBar>
|
|
|
|
);
|
|
|
|
};
|
2016-08-10 00:28:16 +08:00
|
|
|
|
|
|
|
let retrySeconds = 0;
|
2017-06-03 03:25:02 +08:00
|
|
|
const retrySecondsDep = new Tracker.Dependency();
|
2016-11-23 23:32:04 +08:00
|
|
|
let retryInterval = null;
|
2016-08-10 00:28:16 +08:00
|
|
|
|
|
|
|
const getRetrySeconds = () => {
|
|
|
|
retrySecondsDep.depend();
|
|
|
|
return retrySeconds;
|
|
|
|
};
|
|
|
|
|
|
|
|
const setRetrySeconds = (sec = 0) => {
|
|
|
|
if (sec !== retrySeconds) {
|
|
|
|
retrySeconds = sec;
|
|
|
|
retrySecondsDep.changed();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-11-23 23:32:04 +08:00
|
|
|
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();
|
|
|
|
};
|
|
|
|
|
2018-01-08 12:44:42 +08:00
|
|
|
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 = {};
|
2016-08-10 00:28:16 +08:00
|
|
|
|
|
|
|
if (!connected) {
|
|
|
|
data.color = 'primary';
|
|
|
|
switch (status) {
|
2017-08-12 04:17:35 +08:00
|
|
|
case STATUS_FAILED: {
|
2016-08-10 00:28:16 +08:00
|
|
|
data.color = 'danger';
|
|
|
|
data.message = intl.formatMessage(intlMessages.failedMessage);
|
|
|
|
break;
|
2017-08-12 04:17:35 +08:00
|
|
|
}
|
|
|
|
case STATUS_CONNECTING: {
|
2016-08-10 00:28:16 +08:00
|
|
|
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);
|
2016-11-23 23:32:04 +08:00
|
|
|
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
|
|
|
</>
|
2016-08-10 00:28:16 +08:00
|
|
|
);
|
|
|
|
break;
|
2017-08-12 04:17:35 +08:00
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
2016-08-10 00:28:16 +08:00
|
|
|
}
|
2016-11-23 23:32:04 +08:00
|
|
|
|
|
|
|
return data;
|
2016-08-10 00:28:16 +08:00
|
|
|
}
|
|
|
|
|
2016-11-14 19:57:10 +08:00
|
|
|
const meetingId = Auth.meetingID;
|
|
|
|
|
2019-08-30 00:26:07 +08:00
|
|
|
const Meeting = Meetings.findOne({ meetingId },
|
2024-04-10 06:38:07 +08:00
|
|
|
{ fields: { isBreakout: 1, componentsFlags: 1 } });
|
2019-01-24 00:13:03 +08:00
|
|
|
|
2024-04-23 04:40:34 +08:00
|
|
|
if (Meeting.isBreakout) {
|
|
|
|
data.message = (
|
|
|
|
<MeetingRemainingTime />
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2024-04-09 21:53:03 +08:00
|
|
|
if (Meeting) {
|
2024-04-10 06:38:07 +08:00
|
|
|
const { isBreakout, componentsFlags } = Meeting;
|
2019-01-24 00:13:03 +08:00
|
|
|
|
2024-04-10 06:38:07 +08:00
|
|
|
if (componentsFlags.showRemainingTime && !isBreakout) {
|
2019-01-24 00:13:03 +08:00
|
|
|
data.message = (
|
2024-01-25 00:47:34 +08:00
|
|
|
<MeetingRemainingTime />
|
2019-01-24 00:13:03 +08:00
|
|
|
);
|
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';
|
2016-08-10 00:28:16 +08:00
|
|
|
return data;
|
2018-01-08 12:44:42 +08:00
|
|
|
})(NotificationsBarContainer));
|