2022-09-14 11:32:58 +00:00
|
|
|
/* eslint-disable lines-around-comment */
|
2021-06-23 11:23:44 +00:00
|
|
|
import { batch } from 'react-redux';
|
|
|
|
|
2022-09-14 11:32:58 +00:00
|
|
|
import { APP_WILL_MOUNT, APP_WILL_UNMOUNT } from '../base/app/actionTypes';
|
|
|
|
// @ts-ignore
|
2021-06-23 11:23:44 +00:00
|
|
|
import { getConferenceState } from '../base/conference';
|
|
|
|
import { JitsiConferenceEvents } from '../base/lib-jitsi-meet';
|
2022-09-14 11:32:58 +00:00
|
|
|
import { MediaType, MEDIA_TYPE } from '../base/media/constants';
|
|
|
|
import { PARTICIPANT_UPDATED } from '../base/participants/actionTypes';
|
|
|
|
import { raiseHand } from '../base/participants/actions';
|
2021-06-23 11:23:44 +00:00
|
|
|
import {
|
2021-08-23 19:53:49 +00:00
|
|
|
getLocalParticipant,
|
|
|
|
getRemoteParticipants,
|
2021-10-21 09:40:57 +00:00
|
|
|
hasRaisedHand,
|
2021-06-23 11:23:44 +00:00
|
|
|
isLocalParticipantModerator,
|
2022-09-14 11:32:58 +00:00
|
|
|
isParticipantModerator
|
|
|
|
} from '../base/participants/functions';
|
|
|
|
import MiddlewareRegistry from '../base/redux/MiddlewareRegistry';
|
|
|
|
import StateListenerRegistry from '../base/redux/StateListenerRegistry';
|
|
|
|
// @ts-ignore
|
2021-09-15 08:28:44 +00:00
|
|
|
import { playSound, registerSound, unregisterSound } from '../base/sounds';
|
2022-09-14 11:32:58 +00:00
|
|
|
// @ts-ignore
|
|
|
|
import { hideNotification, showNotification } from '../notifications';
|
|
|
|
import { NOTIFICATION_TIMEOUT_TYPE } from '../notifications/constants';
|
|
|
|
// @ts-ignore
|
2021-09-10 11:05:16 +00:00
|
|
|
import { muteLocal } from '../video-menu/actions.any';
|
2021-06-23 11:23:44 +00:00
|
|
|
|
|
|
|
import {
|
2021-09-29 13:41:23 +00:00
|
|
|
DISABLE_MODERATION,
|
|
|
|
ENABLE_MODERATION,
|
|
|
|
LOCAL_PARTICIPANT_APPROVED,
|
2021-06-23 11:23:44 +00:00
|
|
|
LOCAL_PARTICIPANT_MODERATION_NOTIFICATION,
|
2021-09-29 13:41:23 +00:00
|
|
|
LOCAL_PARTICIPANT_REJECTED,
|
|
|
|
PARTICIPANT_APPROVED,
|
|
|
|
PARTICIPANT_REJECTED,
|
2021-09-10 11:05:16 +00:00
|
|
|
REQUEST_DISABLE_AUDIO_MODERATION,
|
|
|
|
REQUEST_DISABLE_VIDEO_MODERATION,
|
|
|
|
REQUEST_ENABLE_AUDIO_MODERATION,
|
|
|
|
REQUEST_ENABLE_VIDEO_MODERATION
|
2021-06-23 11:23:44 +00:00
|
|
|
} from './actionTypes';
|
|
|
|
import {
|
|
|
|
disableModeration,
|
|
|
|
dismissPendingParticipant,
|
|
|
|
dismissPendingAudioParticipant,
|
|
|
|
enableModeration,
|
|
|
|
localParticipantApproved,
|
|
|
|
participantApproved,
|
2021-09-28 16:11:13 +00:00
|
|
|
participantPendingAudio,
|
|
|
|
localParticipantRejected,
|
|
|
|
participantRejected
|
2021-06-23 11:23:44 +00:00
|
|
|
} from './actions';
|
2021-09-15 08:28:44 +00:00
|
|
|
import {
|
2022-05-06 07:27:01 +00:00
|
|
|
ASKED_TO_UNMUTE_NOTIFICATION_ID,
|
|
|
|
ASKED_TO_UNMUTE_SOUND_ID,
|
|
|
|
AUDIO_MODERATION_NOTIFICATION_ID,
|
2021-09-15 08:28:44 +00:00
|
|
|
CS_MODERATION_NOTIFICATION_ID,
|
|
|
|
VIDEO_MODERATION_NOTIFICATION_ID
|
|
|
|
} from './constants';
|
2021-06-23 11:23:44 +00:00
|
|
|
import {
|
|
|
|
isEnabledFromState,
|
|
|
|
isParticipantApproved,
|
|
|
|
isParticipantPending
|
|
|
|
} from './functions';
|
2021-09-15 08:28:44 +00:00
|
|
|
import { ASKED_TO_UNMUTE_FILE } from './sounds';
|
2021-06-23 11:23:44 +00:00
|
|
|
|
2022-09-14 11:32:58 +00:00
|
|
|
declare const APP: any;
|
2021-09-29 13:41:23 +00:00
|
|
|
|
2021-06-23 11:23:44 +00:00
|
|
|
MiddlewareRegistry.register(({ dispatch, getState }) => next => action => {
|
2021-09-10 11:05:16 +00:00
|
|
|
const { type } = action;
|
|
|
|
const { conference } = getConferenceState(getState());
|
2021-06-23 11:23:44 +00:00
|
|
|
|
|
|
|
switch (type) {
|
2021-09-15 08:28:44 +00:00
|
|
|
case APP_WILL_MOUNT: {
|
|
|
|
dispatch(registerSound(ASKED_TO_UNMUTE_SOUND_ID, ASKED_TO_UNMUTE_FILE));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case APP_WILL_UNMOUNT: {
|
|
|
|
dispatch(unregisterSound(ASKED_TO_UNMUTE_SOUND_ID));
|
|
|
|
break;
|
|
|
|
}
|
2021-06-23 11:23:44 +00:00
|
|
|
case LOCAL_PARTICIPANT_MODERATION_NOTIFICATION: {
|
|
|
|
let descriptionKey;
|
|
|
|
let titleKey;
|
2022-09-14 11:32:58 +00:00
|
|
|
let uid: string | undefined;
|
2022-05-26 11:36:12 +00:00
|
|
|
const localParticipant = getLocalParticipant(getState);
|
|
|
|
const raisedHand = hasRaisedHand(localParticipant);
|
2021-06-23 11:23:44 +00:00
|
|
|
|
|
|
|
switch (action.mediaType) {
|
|
|
|
case MEDIA_TYPE.AUDIO: {
|
|
|
|
titleKey = 'notify.moderationInEffectTitle';
|
|
|
|
uid = AUDIO_MODERATION_NOTIFICATION_ID;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MEDIA_TYPE.VIDEO: {
|
|
|
|
titleKey = 'notify.moderationInEffectVideoTitle';
|
|
|
|
uid = VIDEO_MODERATION_NOTIFICATION_ID;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MEDIA_TYPE.PRESENTER: {
|
|
|
|
titleKey = 'notify.moderationInEffectCSTitle';
|
|
|
|
uid = CS_MODERATION_NOTIFICATION_ID;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
dispatch(showNotification({
|
2021-11-10 11:19:40 +00:00
|
|
|
customActionNameKey: [ 'notify.raiseHandAction' ],
|
|
|
|
customActionHandler: [ () => batch(() => {
|
2022-05-26 11:36:12 +00:00
|
|
|
!raisedHand && dispatch(raiseHand(true));
|
2021-06-23 11:23:44 +00:00
|
|
|
dispatch(hideNotification(uid));
|
2021-11-10 11:19:40 +00:00
|
|
|
}) ],
|
2021-06-23 11:23:44 +00:00
|
|
|
descriptionKey,
|
|
|
|
sticky: true,
|
|
|
|
titleKey,
|
|
|
|
uid
|
2022-03-30 14:24:50 +00:00
|
|
|
}, NOTIFICATION_TIMEOUT_TYPE.MEDIUM));
|
2021-06-23 11:23:44 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2021-09-10 11:05:16 +00:00
|
|
|
case REQUEST_DISABLE_AUDIO_MODERATION: {
|
2021-06-23 11:23:44 +00:00
|
|
|
conference.disableAVModeration(MEDIA_TYPE.AUDIO);
|
2021-09-10 11:05:16 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case REQUEST_DISABLE_VIDEO_MODERATION: {
|
2021-06-23 11:23:44 +00:00
|
|
|
conference.disableAVModeration(MEDIA_TYPE.VIDEO);
|
|
|
|
break;
|
|
|
|
}
|
2021-09-10 11:05:16 +00:00
|
|
|
case REQUEST_ENABLE_AUDIO_MODERATION: {
|
2021-06-23 11:23:44 +00:00
|
|
|
conference.enableAVModeration(MEDIA_TYPE.AUDIO);
|
2021-09-10 11:05:16 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case REQUEST_ENABLE_VIDEO_MODERATION: {
|
2021-06-23 11:23:44 +00:00
|
|
|
conference.enableAVModeration(MEDIA_TYPE.VIDEO);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case PARTICIPANT_UPDATED: {
|
|
|
|
const state = getState();
|
|
|
|
const audioModerationEnabled = isEnabledFromState(MEDIA_TYPE.AUDIO, state);
|
2021-08-23 19:53:49 +00:00
|
|
|
const participant = action.participant;
|
2021-06-23 11:23:44 +00:00
|
|
|
|
2021-08-23 19:53:49 +00:00
|
|
|
if (participant && audioModerationEnabled) {
|
|
|
|
if (isLocalParticipantModerator(state)) {
|
2021-06-23 11:23:44 +00:00
|
|
|
|
2021-08-23 19:53:49 +00:00
|
|
|
// this is handled only by moderators
|
2021-10-21 09:40:57 +00:00
|
|
|
if (hasRaisedHand(participant)) {
|
2021-08-23 19:53:49 +00:00
|
|
|
// if participant raises hand show notification
|
|
|
|
!isParticipantApproved(participant.id, MEDIA_TYPE.AUDIO)(state)
|
2021-07-09 12:36:19 +00:00
|
|
|
&& dispatch(participantPendingAudio(participant));
|
2021-08-23 19:53:49 +00:00
|
|
|
} else {
|
|
|
|
// if participant lowers hand hide notification
|
|
|
|
isParticipantPending(participant, MEDIA_TYPE.AUDIO)(state)
|
2021-07-09 12:36:19 +00:00
|
|
|
&& dispatch(dismissPendingAudioParticipant(participant));
|
2021-08-23 19:53:49 +00:00
|
|
|
}
|
2022-09-14 11:32:58 +00:00
|
|
|
} else if (participant.id === getLocalParticipant(state)?.id
|
2021-08-23 19:53:49 +00:00
|
|
|
&& /* the new role */ isParticipantModerator(participant)) {
|
|
|
|
|
|
|
|
// this is the granted moderator case
|
|
|
|
getRemoteParticipants(state).forEach(p => {
|
2021-10-21 09:40:57 +00:00
|
|
|
hasRaisedHand(p) && !isParticipantApproved(p.id, MEDIA_TYPE.AUDIO)(state)
|
2021-08-23 19:53:49 +00:00
|
|
|
&& dispatch(participantPendingAudio(p));
|
|
|
|
});
|
2021-06-23 11:23:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2021-09-29 13:41:23 +00:00
|
|
|
case ENABLE_MODERATION: {
|
|
|
|
if (typeof APP !== 'undefined') {
|
|
|
|
APP.API.notifyModerationChanged(action.mediaType, true);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case DISABLE_MODERATION: {
|
|
|
|
if (typeof APP !== 'undefined') {
|
|
|
|
APP.API.notifyModerationChanged(action.mediaType, false);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case LOCAL_PARTICIPANT_APPROVED: {
|
|
|
|
if (typeof APP !== 'undefined') {
|
|
|
|
const local = getLocalParticipant(getState());
|
|
|
|
|
2022-09-14 11:32:58 +00:00
|
|
|
APP.API.notifyParticipantApproved(local?.id, action.mediaType);
|
2021-09-29 13:41:23 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case PARTICIPANT_APPROVED: {
|
|
|
|
if (typeof APP !== 'undefined') {
|
|
|
|
APP.API.notifyParticipantApproved(action.id, action.mediaType);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case LOCAL_PARTICIPANT_REJECTED: {
|
|
|
|
if (typeof APP !== 'undefined') {
|
|
|
|
const local = getLocalParticipant(getState());
|
|
|
|
|
2022-09-14 11:32:58 +00:00
|
|
|
APP.API.notifyParticipantRejected(local?.id, action.mediaType);
|
2021-09-29 13:41:23 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case PARTICIPANT_REJECTED: {
|
|
|
|
if (typeof APP !== 'undefined') {
|
|
|
|
APP.API.notifyParticipantRejected(action.id, action.mediaType);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2021-06-23 11:23:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return next(action);
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Registers a change handler for state['features/base/conference'].conference to
|
|
|
|
* set the event listeners needed for the A/V moderation feature to operate.
|
|
|
|
*/
|
|
|
|
StateListenerRegistry.register(
|
|
|
|
state => state['features/base/conference'].conference,
|
|
|
|
(conference, { dispatch }, previousConference) => {
|
|
|
|
if (conference && !previousConference) {
|
|
|
|
// local participant is allowed to unmute
|
2022-09-14 11:32:58 +00:00
|
|
|
conference.on(JitsiConferenceEvents.AV_MODERATION_APPROVED, ({ mediaType }: { mediaType: MediaType; }) => {
|
2021-06-23 11:23:44 +00:00
|
|
|
dispatch(localParticipantApproved(mediaType));
|
|
|
|
|
|
|
|
// Audio & video moderation are both enabled at the same time.
|
|
|
|
// Avoid displaying 2 different notifications.
|
2021-09-10 11:05:16 +00:00
|
|
|
if (mediaType === MEDIA_TYPE.AUDIO) {
|
2021-06-23 11:23:44 +00:00
|
|
|
dispatch(showNotification({
|
2021-09-10 11:05:16 +00:00
|
|
|
titleKey: 'notify.hostAskedUnmute',
|
|
|
|
sticky: true,
|
2021-11-10 11:19:40 +00:00
|
|
|
customActionNameKey: [ 'notify.unmute' ],
|
2022-05-06 07:27:01 +00:00
|
|
|
customActionHandler: [ () => dispatch(muteLocal(false, MEDIA_TYPE.AUDIO)) ],
|
|
|
|
uid: ASKED_TO_UNMUTE_NOTIFICATION_ID
|
2022-03-30 14:24:50 +00:00
|
|
|
}, NOTIFICATION_TIMEOUT_TYPE.MEDIUM));
|
2021-09-15 08:28:44 +00:00
|
|
|
dispatch(playSound(ASKED_TO_UNMUTE_SOUND_ID));
|
2021-06-23 11:23:44 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2022-09-14 11:32:58 +00:00
|
|
|
conference.on(JitsiConferenceEvents.AV_MODERATION_REJECTED, ({ mediaType }: { mediaType: MediaType; }) => {
|
2021-09-28 16:11:13 +00:00
|
|
|
dispatch(localParticipantRejected(mediaType));
|
|
|
|
});
|
|
|
|
|
2022-09-14 11:32:58 +00:00
|
|
|
conference.on(JitsiConferenceEvents.AV_MODERATION_CHANGED, ({ enabled, mediaType, actor }: {
|
|
|
|
actor: Object; enabled: boolean; mediaType: MediaType;
|
|
|
|
}) => {
|
2021-06-23 11:23:44 +00:00
|
|
|
enabled ? dispatch(enableModeration(mediaType, actor)) : dispatch(disableModeration(mediaType, actor));
|
|
|
|
});
|
|
|
|
|
|
|
|
// this is received by moderators
|
|
|
|
conference.on(
|
|
|
|
JitsiConferenceEvents.AV_MODERATION_PARTICIPANT_APPROVED,
|
2022-09-14 11:32:58 +00:00
|
|
|
({ participant, mediaType }: { mediaType: MediaType; participant: { _id: string; }; }) => {
|
2021-06-23 11:23:44 +00:00
|
|
|
const { _id: id } = participant;
|
|
|
|
|
|
|
|
batch(() => {
|
|
|
|
// store in the whitelist
|
|
|
|
dispatch(participantApproved(id, mediaType));
|
|
|
|
|
|
|
|
// remove from pending list
|
|
|
|
dispatch(dismissPendingParticipant(id, mediaType));
|
|
|
|
});
|
|
|
|
});
|
2021-09-28 16:11:13 +00:00
|
|
|
|
|
|
|
// this is received by moderators
|
|
|
|
conference.on(
|
|
|
|
JitsiConferenceEvents.AV_MODERATION_PARTICIPANT_REJECTED,
|
2022-09-14 11:32:58 +00:00
|
|
|
({ participant, mediaType }: { mediaType: MediaType; participant: { _id: string; }; }) => {
|
2021-09-28 16:11:13 +00:00
|
|
|
const { _id: id } = participant;
|
|
|
|
|
|
|
|
dispatch(participantRejected(id, mediaType));
|
|
|
|
});
|
2021-06-23 11:23:44 +00:00
|
|
|
}
|
|
|
|
});
|