2016-08-10 00:28:16 +08:00
|
|
|
import { Meteor } from 'meteor/meteor';
|
|
|
|
import { createContainer } from 'meteor/react-meteor-data';
|
|
|
|
import React, { Component, PropTypes } from 'react';
|
|
|
|
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 NavBarService from '../nav-bar/service';
|
|
|
|
import Auth from '/imports/ui/services/auth';
|
2016-11-29 03:48:02 +08:00
|
|
|
import { humanizeSeconds } from '/imports/utils/humanizeSeconds';
|
2016-08-10 00:28:16 +08:00
|
|
|
|
|
|
|
import NotificationsBar from './component';
|
|
|
|
|
|
|
|
// the connection is up and running
|
|
|
|
const STATUS_CONNECTED = 'connected';
|
|
|
|
|
|
|
|
// 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';
|
|
|
|
|
|
|
|
// user has disconnected the connection
|
|
|
|
const STATUS_OFFLINE = 'offline';
|
|
|
|
|
|
|
|
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
|
|
|
},
|
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',
|
|
|
|
},
|
2016-08-10 00:28:16 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
class NotificationsBarContainer extends Component {
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
if (_.isEmpty(this.props.message)) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
const { message, color } = this.props;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<NotificationsBar color={color}>
|
|
|
|
{message}
|
|
|
|
</NotificationsBar>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
let retrySeconds = 0;
|
2016-11-23 23:32:04 +08:00
|
|
|
let timeRemaining = 0;
|
2016-08-10 00:28:16 +08:00
|
|
|
const retrySecondsDep = new Tracker.Dependency;
|
2016-11-23 23:32:04 +08:00
|
|
|
const timeRemainingDep = new Tracker.Dependency;
|
|
|
|
let retryInterval = null;
|
|
|
|
let timeRemainingInterval = null;
|
2016-08-10 00:28:16 +08:00
|
|
|
|
|
|
|
const getRetrySeconds = () => {
|
|
|
|
retrySecondsDep.depend();
|
|
|
|
return retrySeconds;
|
|
|
|
};
|
|
|
|
|
2016-11-23 23:32:04 +08:00
|
|
|
const getTimeRemaining = () => {
|
|
|
|
timeRemainingDep.depend();
|
|
|
|
return timeRemaining;
|
|
|
|
};
|
|
|
|
|
2016-08-10 00:28:16 +08:00
|
|
|
const setRetrySeconds = (sec = 0) => {
|
|
|
|
if (sec !== retrySeconds) {
|
|
|
|
retrySeconds = sec;
|
|
|
|
retrySecondsDep.changed();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-11-14 19:57:10 +08:00
|
|
|
const setTimeRemaining = (sec = 0) => {
|
|
|
|
if (sec !== timeRemaining) {
|
|
|
|
timeRemaining = sec;
|
2016-11-23 23:32:04 +08:00
|
|
|
changeDocumentTitle(sec);
|
|
|
|
timeRemainingDep.changed();
|
|
|
|
}
|
|
|
|
};
|
2016-11-22 23:46:08 +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
|
|
|
|
2016-11-23 23:32:04 +08:00
|
|
|
const changeDocumentTitle = (sec) => {
|
|
|
|
if (sec >= 0) {
|
|
|
|
const affix = `(${humanizeSeconds(sec)}`;
|
|
|
|
const splitTitle = document.title.split(') ');
|
|
|
|
const title = splitTitle[1] || splitTitle[0];
|
|
|
|
document.title = [affix, title].join(') ');
|
2016-11-14 19:57:10 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-08-10 00:28:16 +08:00
|
|
|
export default injectIntl(createContainer(({ intl }) => {
|
|
|
|
const { status, connected, retryCount, retryTime } = Meteor.status();
|
|
|
|
let data = {};
|
|
|
|
|
|
|
|
if (!connected) {
|
|
|
|
data.color = 'primary';
|
|
|
|
switch (status) {
|
|
|
|
case STATUS_OFFLINE:
|
|
|
|
case STATUS_FAILED:
|
|
|
|
data.color = 'danger';
|
|
|
|
data.message = intl.formatMessage(intlMessages.failedMessage);
|
|
|
|
break;
|
|
|
|
case STATUS_CONNECTING:
|
|
|
|
data.message = intl.formatMessage(intlMessages.connectingMessage);
|
|
|
|
break;
|
|
|
|
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);
|
2016-08-10 00:28:16 +08:00
|
|
|
data.message = intl.formatMessage(
|
|
|
|
intlMessages.waitingMessage,
|
2017-05-17 08:00:16 +08:00
|
|
|
{ 0: getRetrySeconds() }
|
2016-08-10 00:28:16 +08:00
|
|
|
);
|
|
|
|
break;
|
|
|
|
}
|
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;
|
|
|
|
const breakouts = NavBarService.getBreakouts();
|
2016-11-15 00:12:54 +08:00
|
|
|
|
2016-11-14 19:57:10 +08:00
|
|
|
if (breakouts) {
|
2016-11-29 03:48:02 +08:00
|
|
|
const currentBreakout = breakouts.find(b => b.breakoutMeetingId === meetingId);
|
2016-11-14 19:57:10 +08:00
|
|
|
if (currentBreakout) {
|
|
|
|
roomRemainingTime = currentBreakout.timeRemaining;
|
|
|
|
if (!timeRemainingInterval && roomRemainingTime) {
|
2016-11-23 23:32:04 +08:00
|
|
|
timeRemainingInterval = startCounter(roomRemainingTime,
|
|
|
|
setTimeRemaining,
|
|
|
|
getTimeRemaining,
|
|
|
|
timeRemainingInterval);
|
2016-11-14 19:57:10 +08:00
|
|
|
}
|
2016-11-22 23:46:08 +08:00
|
|
|
} else if (timeRemainingInterval) {
|
|
|
|
clearInterval(timeRemainingInterval);
|
2016-11-14 19:57:10 +08:00
|
|
|
}
|
|
|
|
|
2016-11-30 00:57:13 +08:00
|
|
|
const timeRemaining = getTimeRemaining();
|
|
|
|
if (timeRemaining) {
|
|
|
|
if (timeRemaining > 0) {
|
2016-11-29 03:48:02 +08:00
|
|
|
data.message = intl.formatMessage(
|
|
|
|
intlMessages.breakoutTimeRemaining,
|
2016-11-30 00:57:13 +08:00
|
|
|
{ time: humanizeSeconds(timeRemaining) }
|
2016-11-29 03:48:02 +08:00
|
|
|
);
|
|
|
|
} else {
|
|
|
|
clearInterval(timeRemainingInterval);
|
|
|
|
data.message = intl.formatMessage(intlMessages.breakoutWillClose);
|
|
|
|
}
|
2016-11-30 00:57:13 +08:00
|
|
|
} else if (!timeRemaining && currentBreakout) {
|
2016-11-29 03:48:02 +08:00
|
|
|
data.message = intl.formatMessage(intlMessages.calculatingBreakoutTimeRemaining);
|
2016-11-15 00:12:54 +08:00
|
|
|
}
|
2016-11-14 19:57:10 +08:00
|
|
|
}
|
|
|
|
|
2016-11-15 00:12:54 +08:00
|
|
|
data.color = 'primary';
|
2016-08-10 00:28:16 +08:00
|
|
|
return data;
|
|
|
|
}, NotificationsBarContainer));
|