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 { toast } from 'react-toastify';
|
2021-11-03 20:58:13 +08:00
|
|
|
import Styled from './styles';
|
2019-06-13 02:03:23 +08:00
|
|
|
|
|
|
|
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(
|
|
|
|
(
|
2021-11-03 20:58:13 +08:00
|
|
|
<>
|
|
|
|
<Styled.Info>{intl.formatMessage(intlMessages.suggestLockTitle)}</Styled.Info>
|
|
|
|
<Styled.ButtonWrapper>
|
|
|
|
<Styled.ManyUsersButton
|
2019-06-13 02:03:23 +08:00
|
|
|
label={intl.formatMessage(intlMessages.enable)}
|
|
|
|
aria-label={intl.formatMessage(intlMessages.enable)}
|
|
|
|
onClick={toggleWebcamsOnlyForModerator}
|
|
|
|
/>
|
|
|
|
|
|
2021-11-03 20:58:13 +08:00
|
|
|
<Styled.ManyUsersButton
|
2019-06-13 02:03:23 +08:00
|
|
|
label={intl.formatMessage(intlMessages.cancel)}
|
|
|
|
aria-label={intl.formatMessage(intlMessages.cancel)}
|
|
|
|
onClick={() => toast.dismiss(lockToastId)}
|
|
|
|
/>
|
2021-11-03 20:58:13 +08:00
|
|
|
</Styled.ButtonWrapper>
|
|
|
|
<Styled.Info>{intl.formatMessage(intlMessages.suggestLockReason)}</Styled.Info>
|
|
|
|
</>
|
2019-06-13 02:03:23 +08:00
|
|
|
),
|
|
|
|
'info',
|
|
|
|
'rooms',
|
|
|
|
{
|
|
|
|
toastId: lockToastId,
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default injectIntl(LockViewersNotifyComponent);
|