2024-04-20 04:34:43 +08:00
|
|
|
import React, { Component } from 'react';
|
2024-05-02 03:48:12 +08:00
|
|
|
import { IntlShape, defineMessages, injectIntl } from 'react-intl';
|
2024-04-20 04:34:43 +08:00
|
|
|
import { notify } from '/imports/ui/services/notification';
|
|
|
|
import { toast } from 'react-toastify';
|
|
|
|
import Styled from './styles';
|
|
|
|
|
|
|
|
const intlMessages = defineMessages({
|
|
|
|
suggestLockTitle: {
|
|
|
|
id: 'app.video.suggestWebcamLock',
|
|
|
|
description: 'Label for notification title',
|
|
|
|
},
|
|
|
|
suggestLockReason: {
|
|
|
|
id: 'app.video.suggestWebcamLockReason',
|
|
|
|
description: 'Reason for activate the webcams\'s lock',
|
|
|
|
},
|
|
|
|
enable: {
|
|
|
|
id: 'app.video.enable',
|
|
|
|
description: 'Enable button label',
|
|
|
|
},
|
|
|
|
cancel: {
|
|
|
|
id: 'app.video.cancel',
|
|
|
|
description: 'Cancel button label',
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
const REPEAT_INTERVAL = 120000;
|
|
|
|
|
2024-05-02 03:48:12 +08:00
|
|
|
interface LockViewersNotifyComponentProps {
|
|
|
|
toggleWebcamsOnlyForModerator: () => void;
|
|
|
|
currentUserIsModerator: boolean;
|
|
|
|
viewersInWebcam: number;
|
|
|
|
limitOfViewersInWebcam: number;
|
|
|
|
limitOfViewersInWebcamIsEnable: boolean;
|
2024-06-12 21:16:18 +08:00
|
|
|
lockSettingsDisableCam: boolean;
|
2024-05-02 03:48:12 +08:00
|
|
|
webcamOnlyForModerator: boolean;
|
|
|
|
intl: IntlShape;
|
|
|
|
}
|
|
|
|
|
|
|
|
class LockViewersNotifyComponent extends Component<LockViewersNotifyComponentProps, object> {
|
2024-07-03 04:11:16 +08:00
|
|
|
private interval: number | null;
|
2024-05-02 03:48:12 +08:00
|
|
|
|
|
|
|
constructor(props: LockViewersNotifyComponentProps) {
|
2024-04-20 04:34:43 +08:00
|
|
|
super(props);
|
|
|
|
this.interval = null;
|
|
|
|
this.intervalCallback = this.intervalCallback.bind(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidUpdate() {
|
|
|
|
const {
|
|
|
|
viewersInWebcam,
|
2024-06-12 21:16:18 +08:00
|
|
|
lockSettingsDisableCam,
|
2024-04-20 04:34:43 +08:00
|
|
|
limitOfViewersInWebcam,
|
|
|
|
webcamOnlyForModerator,
|
|
|
|
currentUserIsModerator,
|
|
|
|
limitOfViewersInWebcamIsEnable,
|
|
|
|
} = this.props;
|
|
|
|
const viwerersInWebcamGreaterThatLimit = (viewersInWebcam >= limitOfViewersInWebcam)
|
|
|
|
&& limitOfViewersInWebcamIsEnable;
|
2024-06-12 21:16:18 +08:00
|
|
|
const webcamForViewersIsLocked = lockSettingsDisableCam || webcamOnlyForModerator;
|
2024-04-20 04:34:43 +08:00
|
|
|
|
|
|
|
if (viwerersInWebcamGreaterThatLimit
|
|
|
|
&& !webcamForViewersIsLocked
|
|
|
|
&& currentUserIsModerator
|
|
|
|
&& !this.interval) {
|
|
|
|
this.interval = setInterval(this.intervalCallback, REPEAT_INTERVAL);
|
|
|
|
this.intervalCallback();
|
|
|
|
}
|
|
|
|
if (webcamForViewersIsLocked || (!viwerersInWebcamGreaterThatLimit && this.interval)) {
|
2024-05-02 03:48:12 +08:00
|
|
|
if (this.interval) clearInterval(this.interval);
|
2024-04-20 04:34:43 +08:00
|
|
|
this.interval = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
intervalCallback() {
|
|
|
|
const {
|
|
|
|
toggleWebcamsOnlyForModerator,
|
|
|
|
intl,
|
|
|
|
} = this.props;
|
|
|
|
const lockToastId = `suggestLock-${new Date().getTime()}`;
|
|
|
|
|
|
|
|
notify(
|
|
|
|
(
|
|
|
|
<>
|
|
|
|
<Styled.Info>{intl.formatMessage(intlMessages.suggestLockTitle)}</Styled.Info>
|
|
|
|
<Styled.ButtonWrapper>
|
|
|
|
<Styled.ManyUsersButton
|
|
|
|
label={intl.formatMessage(intlMessages.enable)}
|
|
|
|
aria-label={intl.formatMessage(intlMessages.enable)}
|
|
|
|
onClick={toggleWebcamsOnlyForModerator}
|
|
|
|
/>
|
|
|
|
|
|
|
|
|
<Styled.ManyUsersButton
|
|
|
|
label={intl.formatMessage(intlMessages.cancel)}
|
|
|
|
aria-label={intl.formatMessage(intlMessages.cancel)}
|
|
|
|
onClick={() => toast.dismiss(lockToastId)}
|
|
|
|
/>
|
|
|
|
</Styled.ButtonWrapper>
|
|
|
|
<Styled.Info>{intl.formatMessage(intlMessages.suggestLockReason)}</Styled.Info>
|
|
|
|
</>
|
|
|
|
),
|
|
|
|
'info',
|
|
|
|
'rooms',
|
|
|
|
{
|
|
|
|
toastId: lockToastId,
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default injectIntl(LockViewersNotifyComponent);
|