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';
|
2019-06-06 02:19:13 +08:00
|
|
|
import React, { Fragment } from 'react';
|
2016-08-10 00:28:16 +08:00
|
|
|
import { defineMessages, injectIntl } from 'react-intl';
|
2017-03-10 03:50:21 +08:00
|
|
|
import _ from 'lodash';
|
2016-11-14 19:57:10 +08:00
|
|
|
import Auth from '/imports/ui/services/auth';
|
2019-09-09 22:48:50 +08:00
|
|
|
import Meetings, { MeetingTimeRemaining } from '/imports/api/meetings';
|
2019-03-12 08:34:34 +08:00
|
|
|
import Users from '/imports/api/users';
|
2019-01-24 00:13:03 +08:00
|
|
|
import BreakoutRemainingTime from '/imports/ui/components/breakout-room/breakout-remaining-time/container';
|
2019-03-12 08:34:34 +08:00
|
|
|
import SlowConnection from '/imports/ui/components/slow-connection/component';
|
2020-04-10 01:01:46 +08:00
|
|
|
import ConnectionStatusService from '/imports/ui/components/connection-status/service';
|
2019-06-06 02:19:13 +08:00
|
|
|
import { styles } from './styles.scss';
|
2016-08-10 00:28:16 +08:00
|
|
|
|
2019-06-07 21:49:50 +08:00
|
|
|
import breakoutService from '/imports/ui/components/breakout-room/service';
|
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';
|
|
|
|
|
2019-03-12 08:34:34 +08:00
|
|
|
const METEOR_SETTINGS_APP = Meteor.settings.public.app;
|
|
|
|
|
|
|
|
const SLOW_CONNECTIONS_TYPES = METEOR_SETTINGS_APP.effectiveConnection;
|
2019-06-13 04:27:49 +08:00
|
|
|
const ENABLE_NETWORK_MONITORING = Meteor.settings.public.networkMonitoring.enableNetworkMonitoring;
|
2019-03-12 08:34:34 +08:00
|
|
|
|
|
|
|
const HELP_LINK = METEOR_SETTINGS_APP.helpLink;
|
|
|
|
|
2020-01-28 21:07:21 +08:00
|
|
|
const STATS = Meteor.settings.public.stats;
|
|
|
|
|
2016-08-10 00:28:16 +08:00
|
|
|
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
|
|
|
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',
|
|
|
|
},
|
2019-01-24 00:13:03 +08:00
|
|
|
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',
|
|
|
|
},
|
2019-02-06 03:18:20 +08:00
|
|
|
alertMeetingEndsUnderOneMinute: {
|
|
|
|
id: 'app.meeting.alertMeetingEndsUnderOneMinute',
|
|
|
|
description: 'Alert that tells that the meeting end under a minute',
|
|
|
|
},
|
|
|
|
alertBreakoutEndsUnderOneMinute: {
|
|
|
|
id: 'app.meeting.alertBreakoutEndsUnderOneMinute',
|
|
|
|
description: 'Alert that tells that the breakout end under a minute',
|
|
|
|
},
|
2019-03-12 08:34:34 +08:00
|
|
|
slowEffectiveConnectionDetected: {
|
|
|
|
id: 'app.network.connection.effective.slow',
|
|
|
|
description: 'Alert for detected slow connections',
|
|
|
|
},
|
|
|
|
slowEffectiveConnectionHelpLink: {
|
|
|
|
id: 'app.network.connection.effective.slow.help',
|
|
|
|
description: 'Help link for slow connections',
|
|
|
|
},
|
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;
|
|
|
|
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
|
|
|
|
2020-04-10 01:01:46 +08:00
|
|
|
let audioStats = '';
|
2020-01-28 21:07:21 +08:00
|
|
|
const audioStatsDep = new Tracker.Dependency();
|
2020-04-13 03:02:28 +08:00
|
|
|
let statsTimeout = null;
|
2020-01-28 21:07:21 +08:00
|
|
|
|
|
|
|
const getAudioStats = () => {
|
|
|
|
audioStatsDep.depend();
|
|
|
|
return audioStats;
|
|
|
|
};
|
|
|
|
|
2020-04-10 01:01:46 +08:00
|
|
|
const setAudioStats = (level = '') => {
|
|
|
|
if (audioStats !== level) {
|
|
|
|
audioStats = level;
|
2020-01-28 21:07:21 +08:00
|
|
|
audioStatsDep.changed();
|
2020-04-10 01:01:46 +08:00
|
|
|
ConnectionStatusService.addConnectionStatus(level);
|
2020-01-28 21:07:21 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const handleAudioStatsEvent = (event) => {
|
|
|
|
const { detail } = event;
|
|
|
|
if (detail) {
|
|
|
|
const { loss, jitter } = detail;
|
|
|
|
let active = false;
|
|
|
|
// From higher to lower
|
|
|
|
for (let i = STATS.level.length - 1; i >= 0; i--) {
|
|
|
|
if (loss > STATS.loss[i] || jitter > STATS.jitter[i]) {
|
|
|
|
active = true;
|
|
|
|
setAudioStats(STATS.level[i]);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2020-04-13 03:02:28 +08:00
|
|
|
if (active) {
|
|
|
|
if (statsTimeout !== null) clearTimeout(statsTimeout);
|
|
|
|
statsTimeout = setTimeout(() => {
|
2020-05-14 21:36:19 +08:00
|
|
|
setAudioStats();
|
2020-04-13 03:02:28 +08:00
|
|
|
}, STATS.length * STATS.interval);
|
2020-05-14 21:36:19 +08:00
|
|
|
}
|
2020-01-28 21:07:21 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
if (STATS.enabled) {
|
|
|
|
// TODO: Check if we need to remove this event listener at any moment
|
|
|
|
window.addEventListener('audiostats', handleAudioStatsEvent);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2019-08-30 00:26:07 +08:00
|
|
|
const user = Users.findOne({ userId: Auth.userID }, { fields: { effectiveConnectionType: 1 } });
|
2019-03-12 08:34:34 +08:00
|
|
|
|
|
|
|
if (user) {
|
|
|
|
const { effectiveConnectionType } = user;
|
2019-06-13 04:27:49 +08:00
|
|
|
if (ENABLE_NETWORK_MONITORING && SLOW_CONNECTIONS_TYPES.includes(effectiveConnectionType)) {
|
2019-03-12 08:34:34 +08:00
|
|
|
data.message = (
|
2019-03-25 20:13:58 +08:00
|
|
|
<SlowConnection effectiveConnectionType={effectiveConnectionType}>
|
2019-03-12 08:34:34 +08:00
|
|
|
{intl.formatMessage(intlMessages.slowEffectiveConnectionDetected)}
|
|
|
|
<a href={HELP_LINK} target="_blank" rel="noopener noreferrer">
|
|
|
|
{intl.formatMessage(intlMessages.slowEffectiveConnectionHelpLink)}
|
|
|
|
</a>
|
|
|
|
</SlowConnection>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-28 21:07:21 +08:00
|
|
|
if (STATS.enabled) {
|
|
|
|
const stats = getAudioStats();
|
|
|
|
if (stats) {
|
|
|
|
if (SLOW_CONNECTIONS_TYPES.includes(stats)) {
|
|
|
|
data.message = (
|
|
|
|
<SlowConnection effectiveConnectionType={stats}>
|
|
|
|
{intl.formatMessage(intlMessages.slowEffectiveConnectionDetected)}{' '}
|
2020-03-03 00:37:23 +08:00
|
|
|
<a href={STATS.help} target="_blank" rel="noopener noreferrer">
|
2020-01-28 21:07:21 +08:00
|
|
|
{intl.formatMessage(intlMessages.slowEffectiveConnectionHelpLink)}
|
|
|
|
</a>
|
|
|
|
</SlowConnection>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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 = (
|
|
|
|
<Fragment>
|
|
|
|
{intl.formatMessage(intlMessages.waitingMessage, { 0: getRetrySeconds() })}
|
|
|
|
<button className={styles.retryButton} type="button" onClick={reconnect}>
|
|
|
|
{intl.formatMessage(intlMessages.retryNow)}
|
|
|
|
</button>
|
|
|
|
</Fragment>
|
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-06-07 21:49:50 +08:00
|
|
|
const breakouts = breakoutService.getBreakouts();
|
2016-11-15 00:12:54 +08:00
|
|
|
|
2017-08-12 04:17:35 +08:00
|
|
|
if (breakouts.length > 0) {
|
|
|
|
const currentBreakout = breakouts.find(b => b.breakoutId === meetingId);
|
|
|
|
|
2016-11-14 19:57:10 +08:00
|
|
|
if (currentBreakout) {
|
2019-01-24 00:13:03 +08:00
|
|
|
data.message = (
|
|
|
|
<BreakoutRemainingTime
|
|
|
|
breakoutRoom={currentBreakout}
|
|
|
|
messageDuration={intlMessages.breakoutTimeRemaining}
|
|
|
|
timeEndedMessage={intlMessages.breakoutWillClose}
|
2019-03-16 04:07:14 +08:00
|
|
|
alertMessageUnderOneMinute={
|
|
|
|
intl.formatMessage(intlMessages.alertBreakoutEndsUnderOneMinute)
|
|
|
|
}
|
2019-01-24 00:13:03 +08:00
|
|
|
/>
|
|
|
|
);
|
2016-11-14 19:57:10 +08:00
|
|
|
}
|
2019-01-24 00:13:03 +08:00
|
|
|
}
|
2016-11-14 19:57:10 +08:00
|
|
|
|
2019-09-09 22:48:50 +08:00
|
|
|
const meetingTimeRemaining = MeetingTimeRemaining.findOne({ meetingId });
|
2019-08-30 00:26:07 +08:00
|
|
|
const Meeting = Meetings.findOne({ meetingId },
|
2019-09-09 22:29:59 +08:00
|
|
|
{ fields: { 'meetingProp.isBreakout': 1 } });
|
2019-01-24 00:13:03 +08:00
|
|
|
|
2019-09-09 22:48:50 +08:00
|
|
|
if (meetingTimeRemaining && Meeting) {
|
|
|
|
const { timeRemaining } = meetingTimeRemaining;
|
2019-01-24 00:13:03 +08:00
|
|
|
const { isBreakout } = Meeting.meetingProp;
|
|
|
|
const underThirtyMin = timeRemaining && timeRemaining <= (30 * 60);
|
|
|
|
|
|
|
|
if (underThirtyMin && !isBreakout) {
|
|
|
|
data.message = (
|
|
|
|
<BreakoutRemainingTime
|
2019-09-09 22:48:50 +08:00
|
|
|
breakoutRoom={meetingTimeRemaining}
|
2019-01-24 00:13:03 +08:00
|
|
|
messageDuration={intlMessages.meetingTimeRemaining}
|
|
|
|
timeEndedMessage={intlMessages.meetingWillClose}
|
2019-03-16 04:07:14 +08:00
|
|
|
alertMessageUnderOneMinute={
|
|
|
|
intl.formatMessage(intlMessages.alertMeetingEndsUnderOneMinute)
|
|
|
|
}
|
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));
|