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
|
|
|
|
|
|
|
const intlMessages = defineMessages({
|
2024-08-29 20:38:46 +08:00
|
|
|
connectionCode3001: {
|
|
|
|
id: 'app.notificationBar.connectionCode3001',
|
|
|
|
description: 'Closed connection alert',
|
2016-08-10 00:28:16 +08:00
|
|
|
},
|
2024-08-29 20:38:46 +08:00
|
|
|
connectionCode3002: {
|
|
|
|
id: 'app.notificationBar.connectionCode3002',
|
|
|
|
description: 'Impossible connection alert',
|
2016-08-10 00:28:16 +08:00
|
|
|
},
|
2024-08-29 20:38:46 +08:00
|
|
|
connectionCode3003: {
|
|
|
|
id: 'app.notificationBar.connectionCode3003',
|
|
|
|
description: 'Unresponsive server alert',
|
2016-08-10 00:28:16 +08:00
|
|
|
},
|
2024-08-29 20:38:46 +08:00
|
|
|
connectionCode3004: {
|
|
|
|
id: 'app.notificationBar.connectionCode3004',
|
|
|
|
description: 'Unstable connection alert',
|
2019-06-06 02:19:13 +08:00
|
|
|
},
|
2024-08-29 20:38:46 +08:00
|
|
|
connectionCode3005: {
|
|
|
|
id: 'app.notificationBar.connectionCode3005',
|
|
|
|
description: 'Slow data alert',
|
2024-07-05 04:26:09 +08:00
|
|
|
},
|
2016-08-10 00:28:16 +08:00
|
|
|
});
|
|
|
|
|
2024-08-29 20:38:46 +08:00
|
|
|
const STATUS_CRITICAL = 'critical';
|
|
|
|
const COLOR_PRIMARY = 'primary';
|
|
|
|
|
2024-06-11 04:20:41 +08:00
|
|
|
const NotificationsBarContainer = () => {
|
|
|
|
const data = {};
|
|
|
|
data.alert = true;
|
2024-08-29 20:38:46 +08:00
|
|
|
data.color = COLOR_PRIMARY;
|
2024-06-11 04:20:41 +08:00
|
|
|
const intl = useIntl();
|
|
|
|
const connected = useReactiveVar(connectionStatus.getConnectedStatusVar());
|
2024-07-05 04:26:09 +08:00
|
|
|
const serverIsResponding = useReactiveVar(connectionStatus.getServerIsRespondingVar());
|
|
|
|
const pingIsComing = useReactiveVar(connectionStatus.getPingIsComingVar());
|
|
|
|
const lastRttRequestSuccess = useReactiveVar(connectionStatus.getLastRttRequestSuccessVar());
|
2024-08-29 20:38:46 +08:00
|
|
|
const rttStatus = useReactiveVar(connectionStatus.getRttStatusVar());
|
|
|
|
const isCritical = rttStatus === STATUS_CRITICAL;
|
2024-06-11 04:20:41 +08:00
|
|
|
// if connection failed x attempts a error will be thrown
|
2024-08-29 20:38:46 +08:00
|
|
|
if (!connected) {
|
|
|
|
data.message = isCritical
|
|
|
|
? intl.formatMessage(intlMessages.connectionCode3002)
|
|
|
|
: intl.formatMessage(intlMessages.connectionCode3001);
|
|
|
|
} else if (connected && !serverIsResponding) {
|
|
|
|
data.message = isCritical
|
|
|
|
? intl.formatMessage(intlMessages.connectionCode3004)
|
|
|
|
: intl.formatMessage(intlMessages.connectionCode3003);
|
|
|
|
} else if (connected && serverIsResponding && !pingIsComing && lastRttRequestSuccess) {
|
|
|
|
data.message = intl.formatMessage(intlMessages.connectionCode3005);
|
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;
|