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';
|
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';
|
2024-06-11 04:20:41 +08:00
|
|
|
import { useReactiveVar } from '@apollo/client';
|
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-11 04:20:41 +08:00
|
|
|
import connectionStatus from '../../core/graphql/singletons/connectionStatus';
|
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 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
|
|
|
},
|
2024-06-11 04:20:41 +08:00
|
|
|
reconnectingMessage: {
|
|
|
|
id: 'app.reconnectingMessage',
|
|
|
|
description: 'Notification message for disconnection',
|
2019-06-06 02:19:13 +08:00
|
|
|
},
|
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-11 04:20:41 +08:00
|
|
|
const NotificationsBarContainer = () => {
|
|
|
|
const data = {};
|
|
|
|
data.alert = true;
|
|
|
|
data.color = 'primary';
|
|
|
|
const intl = useIntl();
|
|
|
|
const connected = useReactiveVar(connectionStatus.getConnectedStatusVar());
|
|
|
|
// if connection failed x attempts a error will be thrown
|
|
|
|
if (!connected) {
|
|
|
|
data.color = 'primary';
|
|
|
|
data.message = (
|
|
|
|
<>
|
|
|
|
{intl.formatMessage(intlMessages.reconnectingMessage)}
|
|
|
|
</>
|
|
|
|
);
|
2016-08-10 00:28:16 +08:00
|
|
|
}
|
|
|
|
|
2024-06-05 01:09:48 +08:00
|
|
|
const { data: meeting } = useMeeting((m) => ({
|
|
|
|
isBreakout: m.isBreakout,
|
|
|
|
componentsFlags: m.componentsFlags,
|
|
|
|
}));
|
2016-08-10 00:28:16 +08:00
|
|
|
|
2024-06-11 04:20:41 +08:00
|
|
|
if (meeting?.isBreakout) {
|
|
|
|
data.message = (
|
|
|
|
<MeetingRemainingTime />
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (meeting) {
|
|
|
|
const { isBreakout, componentsFlags } = meeting;
|
2016-11-23 23:32:04 +08:00
|
|
|
|
2024-06-11 04:20:41 +08:00
|
|
|
if (componentsFlags.showRemainingTime && !isBreakout) {
|
|
|
|
data.message = (
|
2024-06-05 01:09:48 +08:00
|
|
|
<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(() => {
|
2024-06-11 04:20:41 +08:00
|
|
|
const localHasNotification = !!data.message;
|
2024-06-05 01:09:48 +08:00
|
|
|
|
|
|
|
if (localHasNotification !== hasNotification) {
|
|
|
|
layoutContextDispatch({
|
|
|
|
type: ACTIONS.SET_HAS_NOTIFICATIONS_BAR,
|
|
|
|
value: localHasNotification,
|
|
|
|
});
|
2016-11-15 00:12:54 +08:00
|
|
|
}
|
2024-06-11 04:20:41 +08:00
|
|
|
}, [data.message, hasNotification]);
|
2024-06-05 01:09:48 +08:00
|
|
|
|
2024-06-11 04:20:41 +08:00
|
|
|
if (isEmpty(data.message)) {
|
2024-06-05 01:09:48 +08:00
|
|
|
return null;
|
2016-11-14 19:57:10 +08:00
|
|
|
}
|
|
|
|
|
2024-06-05 01:09:48 +08:00
|
|
|
return (
|
2024-06-11 04:20:41 +08:00
|
|
|
<NotificationsBar color={data.color}>
|
|
|
|
{data.message}
|
2024-06-05 01:09:48 +08:00
|
|
|
</NotificationsBar>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2024-06-11 04:20:41 +08:00
|
|
|
export default NotificationsBarContainer;
|