2019-06-13 02:03:23 +08:00
|
|
|
import React, { Component } from 'react';
|
|
|
|
import { defineMessages, injectIntl } from 'react-intl';
|
|
|
|
import { notify } from '/imports/ui/services/notification';
|
|
|
|
import Button from '/imports/ui/components/button/component';
|
|
|
|
import { toast } from 'react-toastify';
|
|
|
|
import { styles } from './styles';
|
|
|
|
|
|
|
|
const intlMessages = defineMessages({
|
|
|
|
suggestLockTitle: {
|
|
|
|
id: 'app.video.suggestWebcamLock',
|
2019-06-14 22:01:54 +08:00
|
|
|
description: 'Label for notification title',
|
2019-06-13 02:03:23 +08:00
|
|
|
},
|
|
|
|
suggestLockReason: {
|
|
|
|
id: 'app.video.suggestWebcamLockReason',
|
2019-06-14 22:01:54 +08:00
|
|
|
description: 'Reason for activate the webcams\'s lock',
|
2019-06-13 02:03:23 +08:00
|
|
|
},
|
|
|
|
enable: {
|
|
|
|
id: 'app.video.enable',
|
2019-06-14 22:01:54 +08:00
|
|
|
description: 'Enable button label',
|
2019-06-13 02:03:23 +08:00
|
|
|
},
|
|
|
|
cancel: {
|
|
|
|
id: 'app.video.cancel',
|
2019-06-14 22:01:54 +08:00
|
|
|
description: 'Cancel button label',
|
2019-06-13 02:03:23 +08:00
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
const REPEAT_INTERVAL = 120000;
|
|
|
|
|
|
|
|
class LockViewersNotifyComponent extends Component {
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
this.interval = null;
|
|
|
|
this.intervalCallback = this.intervalCallback.bind(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidUpdate() {
|
|
|
|
const {
|
|
|
|
viewersInWebcam,
|
|
|
|
lockSettings,
|
|
|
|
limitOfViewersInWebcam,
|
|
|
|
webcamOnlyForModerator,
|
|
|
|
currentUserIsModerator,
|
|
|
|
limitOfViewersInWebcamIsEnable,
|
|
|
|
} = this.props;
|
|
|
|
const viwerersInWebcamGreaterThatLimit = (viewersInWebcam >= limitOfViewersInWebcam)
|
|
|
|
&& limitOfViewersInWebcamIsEnable;
|
|
|
|
const webcamForViewersIsLocked = lockSettings.disableCam || webcamOnlyForModerator;
|
|
|
|
|
|
|
|
if (viwerersInWebcamGreaterThatLimit
|
|
|
|
&& !webcamForViewersIsLocked
|
|
|
|
&& currentUserIsModerator
|
|
|
|
&& !this.interval) {
|
|
|
|
this.interval = setInterval(this.intervalCallback, REPEAT_INTERVAL);
|
|
|
|
this.intervalCallback();
|
|
|
|
}
|
|
|
|
if (webcamForViewersIsLocked || (!viwerersInWebcamGreaterThatLimit && this.interval)) {
|
|
|
|
clearInterval(this.interval);
|
|
|
|
this.interval = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
intervalCallback() {
|
|
|
|
const {
|
|
|
|
toggleWebcamsOnlyForModerator,
|
|
|
|
intl,
|
|
|
|
} = this.props;
|
|
|
|
const lockToastId = `suggestLock-${new Date().getTime()}`;
|
|
|
|
|
|
|
|
notify(
|
|
|
|
(
|
|
|
|
<React.Fragment>
|
2019-08-19 22:41:31 +08:00
|
|
|
<p className={styles.info}>{intl.formatMessage(intlMessages.suggestLockTitle)}</p>
|
2019-06-13 02:03:23 +08:00
|
|
|
<div className={styles.buttonWrapper}>
|
|
|
|
<Button
|
|
|
|
label={intl.formatMessage(intlMessages.enable)}
|
|
|
|
aria-label={intl.formatMessage(intlMessages.enable)}
|
|
|
|
onClick={toggleWebcamsOnlyForModerator}
|
|
|
|
className={styles.button}
|
|
|
|
/>
|
|
|
|
|
|
|
|
|
<Button
|
|
|
|
label={intl.formatMessage(intlMessages.cancel)}
|
|
|
|
aria-label={intl.formatMessage(intlMessages.cancel)}
|
|
|
|
onClick={() => toast.dismiss(lockToastId)}
|
|
|
|
className={styles.button}
|
|
|
|
/>
|
|
|
|
</div>
|
2019-08-19 22:41:31 +08:00
|
|
|
<p className={styles.info}>{intl.formatMessage(intlMessages.suggestLockReason)}</p>
|
2019-06-13 02:03:23 +08:00
|
|
|
</React.Fragment>
|
|
|
|
),
|
|
|
|
'info',
|
|
|
|
'rooms',
|
|
|
|
{
|
|
|
|
toastId: lockToastId,
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default injectIntl(LockViewersNotifyComponent);
|