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';
|
2024-06-05 01:09:48 +08:00
|
|
|
import { defineMessages, useIntl } from 'react-intl';
|
|
|
|
import { makeVar, useReactiveVar } from '@apollo/client';
|
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';
|
2024-06-05 01:09:48 +08:00
|
|
|
import useMeeting from '../../core/hooks/useMeeting';
|
2016-08-10 00:28:16 +08:00
|
|
|
|
|
|
|
// 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
|
|
|
});
|
|
|
|
|
2024-06-05 01:09:48 +08:00
|
|
|
const retrySecondsVar = makeVar(0);
|
2016-11-23 23:32:04 +08:00
|
|
|
let retryInterval = null;
|
2016-08-10 00:28:16 +08:00
|
|
|
|
2024-06-05 01:09:48 +08:00
|
|
|
const getRetrySeconds = () => retrySecondsVar();
|
2016-08-10 00:28:16 +08:00
|
|
|
|
|
|
|
const setRetrySeconds = (sec = 0) => {
|
2024-06-05 01:09:48 +08:00
|
|
|
if (sec !== retrySecondsVar()) {
|
|
|
|
retrySecondsVar(sec);
|
2016-08-10 00:28:16 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
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();
|
|
|
|
};
|
|
|
|
|
2024-06-05 01:09:48 +08:00
|
|
|
const NotificationsBarContainer = (props) => {
|
|
|
|
const {
|
|
|
|
connected,
|
|
|
|
status,
|
|
|
|
retryTime,
|
|
|
|
} = props;
|
|
|
|
let message;
|
|
|
|
let color;
|
|
|
|
|
|
|
|
useReactiveVar(retrySecondsVar);
|
|
|
|
const intl = useIntl();
|
|
|
|
const { data: meeting } = useMeeting((m) => ({
|
|
|
|
isBreakout: m.isBreakout,
|
|
|
|
componentsFlags: m.componentsFlags,
|
|
|
|
}));
|
2016-08-10 00:28:16 +08:00
|
|
|
|
|
|
|
if (!connected) {
|
|
|
|
switch (status) {
|
2017-08-12 04:17:35 +08:00
|
|
|
case STATUS_FAILED: {
|
2024-06-05 01:09:48 +08:00
|
|
|
color = 'danger';
|
|
|
|
message = intl.formatMessage(intlMessages.failedMessage);
|
2016-08-10 00:28:16 +08:00
|
|
|
break;
|
2017-08-12 04:17:35 +08:00
|
|
|
}
|
|
|
|
case STATUS_CONNECTING: {
|
2024-06-05 01:09:48 +08:00
|
|
|
message = intl.formatMessage(intlMessages.connectingMessage);
|
2016-08-10 00:28:16 +08:00
|
|
|
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);
|
2024-06-05 01:09:48 +08:00
|
|
|
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:
|
2024-06-05 01:09:48 +08:00
|
|
|
color = 'primary';
|
2017-08-12 04:17:35 +08:00
|
|
|
break;
|
2016-08-10 00:28:16 +08:00
|
|
|
}
|
2024-06-05 01:09:48 +08:00
|
|
|
} else {
|
|
|
|
color = 'primary';
|
2016-11-23 23:32:04 +08:00
|
|
|
|
2024-06-05 01:09:48 +08:00
|
|
|
if (meeting?.isBreakout) {
|
|
|
|
message = (
|
|
|
|
<MeetingRemainingTime />
|
|
|
|
);
|
|
|
|
}
|
2016-11-14 19:57:10 +08:00
|
|
|
|
2024-06-05 01:09:48 +08:00
|
|
|
if (meeting) {
|
|
|
|
const { isBreakout, componentsFlags } = meeting;
|
2019-01-24 00:13:03 +08:00
|
|
|
|
2024-06-05 01:09:48 +08:00
|
|
|
if (componentsFlags?.showRemainingTime && !isBreakout) {
|
|
|
|
message = (
|
|
|
|
<MeetingRemainingTime />
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2024-04-23 04:40:34 +08:00
|
|
|
}
|
|
|
|
|
2024-06-05 01:09:48 +08:00
|
|
|
const notificationsBar = layoutSelectInput((i) => i.notificationsBar);
|
|
|
|
const layoutContextDispatch = layoutDispatch();
|
|
|
|
|
|
|
|
const { hasNotification } = notificationsBar;
|
2019-01-24 00:13:03 +08:00
|
|
|
|
2024-06-05 01:09:48 +08:00
|
|
|
useEffect(() => {
|
|
|
|
const localHasNotification = !!message;
|
|
|
|
|
|
|
|
if (localHasNotification !== hasNotification) {
|
|
|
|
layoutContextDispatch({
|
|
|
|
type: ACTIONS.SET_HAS_NOTIFICATIONS_BAR,
|
|
|
|
value: localHasNotification,
|
|
|
|
});
|
2016-11-15 00:12:54 +08:00
|
|
|
}
|
2024-06-05 01:09:48 +08:00
|
|
|
}, [message, hasNotification]);
|
|
|
|
|
|
|
|
if (isEmpty(message)) {
|
|
|
|
return null;
|
2016-11-14 19:57:10 +08:00
|
|
|
}
|
|
|
|
|
2024-06-05 01:09:48 +08:00
|
|
|
return (
|
|
|
|
<NotificationsBar color={color}>
|
|
|
|
{message}
|
|
|
|
</NotificationsBar>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default withTracker(() => Meteor.status())(NotificationsBarContainer);
|