2022-09-06 17:32:20 +00:00
|
|
|
/* eslint-disable lines-around-comment */
|
2021-07-20 11:31:49 +00:00
|
|
|
import { batch } from 'react-redux';
|
2022-07-11 12:30:37 +00:00
|
|
|
|
2022-09-07 08:20:05 +00:00
|
|
|
import { createReactionSoundsDisabledEvent } from '../analytics/AnalyticsEvents';
|
|
|
|
import { sendAnalytics } from '../analytics/functions';
|
2022-07-11 12:30:37 +00:00
|
|
|
import { IStore } from '../app/types';
|
|
|
|
import { APP_WILL_MOUNT, APP_WILL_UNMOUNT } from '../base/app/actionTypes';
|
2021-12-13 19:46:05 +00:00
|
|
|
import {
|
2022-04-06 02:13:39 +00:00
|
|
|
CONFERENCE_JOIN_IN_PROGRESS,
|
2021-12-13 19:46:05 +00:00
|
|
|
SET_START_REACTIONS_MUTED,
|
|
|
|
setStartReactionsMuted
|
2022-06-08 07:44:47 +00:00
|
|
|
// @ts-ignore
|
2021-12-13 19:46:05 +00:00
|
|
|
} from '../base/conference';
|
2021-11-10 11:19:40 +00:00
|
|
|
import {
|
|
|
|
getParticipantById,
|
|
|
|
getParticipantCount,
|
|
|
|
isLocalParticipantModerator
|
2022-08-08 08:12:22 +00:00
|
|
|
} from '../base/participants/functions';
|
2022-07-27 09:56:07 +00:00
|
|
|
import MiddlewareRegistry from '../base/redux/MiddlewareRegistry';
|
2021-11-10 11:19:40 +00:00
|
|
|
import { SETTINGS_UPDATED } from '../base/settings/actionTypes';
|
2022-06-08 07:44:47 +00:00
|
|
|
// @ts-ignore
|
2021-11-10 11:19:40 +00:00
|
|
|
import { updateSettings } from '../base/settings/actions';
|
2022-06-08 07:44:47 +00:00
|
|
|
// @ts-ignore
|
2021-08-23 09:57:56 +00:00
|
|
|
import { playSound, registerSound, unregisterSound } from '../base/sounds';
|
2022-06-08 07:44:47 +00:00
|
|
|
// @ts-ignore
|
2021-10-04 08:37:02 +00:00
|
|
|
import { getDisabledSounds } from '../base/sounds/functions.any';
|
2022-06-08 07:44:47 +00:00
|
|
|
// @ts-ignore
|
2021-11-24 11:05:27 +00:00
|
|
|
import { NOTIFICATION_TIMEOUT_TYPE, showNotification } from '../notifications';
|
2021-07-13 06:50:08 +00:00
|
|
|
|
|
|
|
import {
|
2021-07-20 11:31:49 +00:00
|
|
|
ADD_REACTION_BUFFER,
|
|
|
|
FLUSH_REACTION_BUFFER,
|
|
|
|
SEND_REACTIONS,
|
2021-08-23 09:57:56 +00:00
|
|
|
PUSH_REACTIONS,
|
|
|
|
SHOW_SOUNDS_NOTIFICATION
|
2021-07-13 06:50:08 +00:00
|
|
|
} from './actionTypes';
|
|
|
|
import {
|
2021-07-20 11:31:49 +00:00
|
|
|
addReactionsToChat,
|
|
|
|
flushReactionBuffer,
|
|
|
|
pushReactions,
|
|
|
|
sendReactions,
|
2021-07-13 06:50:08 +00:00
|
|
|
setReactionQueue
|
|
|
|
} from './actions.any';
|
2022-06-08 07:44:47 +00:00
|
|
|
import { displayReactionSoundsNotification } from './actions.web';
|
2021-10-04 08:37:02 +00:00
|
|
|
import {
|
|
|
|
ENDPOINT_REACTION_NAME,
|
|
|
|
RAISE_HAND_SOUND_ID,
|
|
|
|
REACTIONS,
|
|
|
|
REACTION_SOUND,
|
2021-11-10 11:19:40 +00:00
|
|
|
SOUNDS_THRESHOLDS,
|
2022-06-08 07:44:47 +00:00
|
|
|
MUTE_REACTIONS_COMMAND,
|
|
|
|
MuteCommandAttributes
|
2021-10-04 08:37:02 +00:00
|
|
|
} from './constants';
|
2021-08-23 09:57:56 +00:00
|
|
|
import {
|
|
|
|
getReactionMessageFromBuffer,
|
|
|
|
getReactionsSoundsThresholds,
|
|
|
|
getReactionsWithId,
|
|
|
|
sendReactionsWebhook
|
|
|
|
} from './functions.any';
|
2021-11-10 11:19:40 +00:00
|
|
|
import logger from './logger';
|
2021-08-23 09:57:56 +00:00
|
|
|
import { RAISE_HAND_SOUND_FILE } from './sounds';
|
2021-07-13 06:50:08 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Middleware which intercepts Reactions actions to handle changes to the
|
|
|
|
* visibility timeout of the Reactions.
|
|
|
|
*
|
2022-06-08 07:44:47 +00:00
|
|
|
* @param {IStore} store - The redux store.
|
2021-07-13 06:50:08 +00:00
|
|
|
* @returns {Function}
|
|
|
|
*/
|
2022-09-08 09:52:36 +00:00
|
|
|
MiddlewareRegistry.register((store: IStore) => (next: Function) => (action: any) => {
|
2021-07-13 06:50:08 +00:00
|
|
|
const { dispatch, getState } = store;
|
|
|
|
|
|
|
|
switch (action.type) {
|
2021-08-23 09:57:56 +00:00
|
|
|
case APP_WILL_MOUNT:
|
|
|
|
batch(() => {
|
|
|
|
Object.keys(REACTIONS).forEach(key => {
|
|
|
|
for (let i = 0; i < SOUNDS_THRESHOLDS.length; i++) {
|
|
|
|
dispatch(registerSound(
|
|
|
|
`${REACTIONS[key].soundId}${SOUNDS_THRESHOLDS[i]}`,
|
|
|
|
REACTIONS[key].soundFiles[i]
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
dispatch(registerSound(RAISE_HAND_SOUND_ID, RAISE_HAND_SOUND_FILE));
|
|
|
|
});
|
|
|
|
break;
|
|
|
|
|
|
|
|
case APP_WILL_UNMOUNT:
|
|
|
|
batch(() => {
|
|
|
|
Object.keys(REACTIONS).forEach(key => {
|
|
|
|
for (let i = 0; i < SOUNDS_THRESHOLDS.length; i++) {
|
|
|
|
dispatch(unregisterSound(`${REACTIONS[key].soundId}${SOUNDS_THRESHOLDS[i]}`));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
dispatch(unregisterSound(RAISE_HAND_SOUND_ID));
|
|
|
|
});
|
|
|
|
break;
|
|
|
|
|
2021-07-20 11:31:49 +00:00
|
|
|
case ADD_REACTION_BUFFER: {
|
|
|
|
const { timeoutID, buffer } = getState()['features/reactions'];
|
2021-07-13 06:50:08 +00:00
|
|
|
const { reaction } = action;
|
|
|
|
|
2022-09-05 09:05:07 +00:00
|
|
|
clearTimeout(timeoutID ?? 0);
|
2021-07-20 11:31:49 +00:00
|
|
|
buffer.push(reaction);
|
|
|
|
action.buffer = buffer;
|
2021-07-13 06:50:08 +00:00
|
|
|
action.timeoutID = setTimeout(() => {
|
2021-07-20 11:31:49 +00:00
|
|
|
dispatch(flushReactionBuffer());
|
2021-07-13 06:50:08 +00:00
|
|
|
}, 500);
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2022-04-06 02:13:39 +00:00
|
|
|
case CONFERENCE_JOIN_IN_PROGRESS: {
|
2021-11-10 11:19:40 +00:00
|
|
|
const { conference } = action;
|
2021-07-13 06:50:08 +00:00
|
|
|
|
2021-11-10 11:19:40 +00:00
|
|
|
conference.addCommandListener(
|
2022-09-08 09:52:36 +00:00
|
|
|
MUTE_REACTIONS_COMMAND, ({ attributes }: { attributes: MuteCommandAttributes; }, id: any) => {
|
2021-11-10 11:19:40 +00:00
|
|
|
_onMuteReactionsCommand(attributes, id, store);
|
|
|
|
});
|
|
|
|
break;
|
|
|
|
}
|
2021-07-20 11:31:49 +00:00
|
|
|
case FLUSH_REACTION_BUFFER: {
|
2021-07-15 12:23:48 +00:00
|
|
|
const state = getState();
|
2021-07-20 11:31:49 +00:00
|
|
|
const { buffer } = state['features/reactions'];
|
2021-09-14 08:15:03 +00:00
|
|
|
const participantCount = getParticipantCount(state);
|
2021-07-20 11:31:49 +00:00
|
|
|
|
|
|
|
batch(() => {
|
2021-09-14 08:15:03 +00:00
|
|
|
if (participantCount > 1) {
|
|
|
|
dispatch(sendReactions());
|
|
|
|
}
|
2021-07-20 11:31:49 +00:00
|
|
|
dispatch(addReactionsToChat(getReactionMessageFromBuffer(buffer)));
|
|
|
|
dispatch(pushReactions(buffer));
|
|
|
|
});
|
2021-07-15 12:23:48 +00:00
|
|
|
|
2021-10-04 09:01:14 +00:00
|
|
|
sendReactionsWebhook(state, buffer);
|
2021-07-13 06:50:08 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2021-07-20 11:31:49 +00:00
|
|
|
case PUSH_REACTIONS: {
|
2021-08-23 09:57:56 +00:00
|
|
|
const state = getState();
|
|
|
|
const { queue, notificationDisplayed } = state['features/reactions'];
|
|
|
|
const { soundsReactions } = state['features/base/settings'];
|
2021-10-04 08:37:02 +00:00
|
|
|
const disabledSounds = getDisabledSounds(state);
|
2021-07-20 11:31:49 +00:00
|
|
|
const reactions = action.reactions;
|
2021-07-13 06:50:08 +00:00
|
|
|
|
2021-08-23 09:57:56 +00:00
|
|
|
batch(() => {
|
2021-10-04 08:37:02 +00:00
|
|
|
if (!notificationDisplayed && soundsReactions && !disabledSounds.includes(REACTION_SOUND)
|
|
|
|
&& displayReactionSoundsNotification) {
|
2021-08-23 09:57:56 +00:00
|
|
|
dispatch(displayReactionSoundsNotification());
|
|
|
|
}
|
|
|
|
if (soundsReactions) {
|
|
|
|
const reactionSoundsThresholds = getReactionsSoundsThresholds(reactions);
|
|
|
|
|
|
|
|
reactionSoundsThresholds.forEach(reaction =>
|
|
|
|
dispatch(playSound(`${REACTIONS[reaction.reaction].soundId}${reaction.threshold}`))
|
|
|
|
);
|
|
|
|
}
|
|
|
|
dispatch(setReactionQueue([ ...queue, ...getReactionsWithId(reactions) ]));
|
|
|
|
});
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2021-10-25 08:31:22 +00:00
|
|
|
case SEND_REACTIONS: {
|
|
|
|
const state = getState();
|
|
|
|
const { buffer } = state['features/reactions'];
|
|
|
|
const { conference } = state['features/base/conference'];
|
|
|
|
|
|
|
|
if (conference) {
|
|
|
|
conference.sendEndpointMessage('', {
|
|
|
|
name: ENDPOINT_REACTION_NAME,
|
|
|
|
reactions: buffer,
|
|
|
|
timestamp: Date.now()
|
|
|
|
});
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2021-12-13 19:46:05 +00:00
|
|
|
// Settings changed for mute reactions in the meeting
|
|
|
|
case SET_START_REACTIONS_MUTED: {
|
|
|
|
const state = getState();
|
|
|
|
const { conference } = state['features/base/conference'];
|
|
|
|
const { muted, updateBackend } = action;
|
|
|
|
|
|
|
|
if (conference && isLocalParticipantModerator(state) && updateBackend) {
|
|
|
|
conference.sendCommand(MUTE_REACTIONS_COMMAND, { attributes: { startReactionsMuted: Boolean(muted) } });
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2021-10-25 08:31:22 +00:00
|
|
|
case SETTINGS_UPDATED: {
|
|
|
|
const { soundsReactions } = getState()['features/base/settings'];
|
|
|
|
|
|
|
|
if (action.settings.soundsReactions === false && soundsReactions === true) {
|
|
|
|
sendAnalytics(createReactionSoundsDisabledEvent());
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2021-08-23 09:57:56 +00:00
|
|
|
case SHOW_SOUNDS_NOTIFICATION: {
|
2021-11-10 11:19:40 +00:00
|
|
|
const state = getState();
|
|
|
|
const isModerator = isLocalParticipantModerator(state);
|
2021-12-14 14:24:35 +00:00
|
|
|
const { disableReactionsModeration } = state['features/base/config'];
|
2021-11-10 11:19:40 +00:00
|
|
|
|
|
|
|
const customActions = [ 'notify.reactionSounds' ];
|
2022-09-14 07:54:56 +00:00
|
|
|
const customFunctions: Function[] = [ () => dispatch(updateSettings({
|
2021-11-10 11:19:40 +00:00
|
|
|
soundsReactions: false
|
|
|
|
})) ];
|
|
|
|
|
2021-12-14 14:24:35 +00:00
|
|
|
if (isModerator && !disableReactionsModeration) {
|
2021-11-10 11:19:40 +00:00
|
|
|
customActions.push('notify.reactionSoundsForAll');
|
|
|
|
customFunctions.push(() => batch(() => {
|
|
|
|
dispatch(setStartReactionsMuted(true));
|
|
|
|
dispatch(updateSettings({ soundsReactions: false }));
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
2021-08-23 09:57:56 +00:00
|
|
|
dispatch(showNotification({
|
|
|
|
titleKey: 'toolbar.disableReactionSounds',
|
2021-11-10 11:19:40 +00:00
|
|
|
customActionNameKey: customActions,
|
|
|
|
customActionHandler: customFunctions
|
2021-11-24 11:05:27 +00:00
|
|
|
}, NOTIFICATION_TIMEOUT_TYPE.MEDIUM));
|
2021-08-23 09:57:56 +00:00
|
|
|
break;
|
2021-07-13 06:50:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return next(action);
|
|
|
|
});
|
2021-11-10 11:19:40 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Notifies this instance about a "Mute Reaction Sounds" command received by the Jitsi
|
|
|
|
* conference.
|
|
|
|
*
|
|
|
|
* @param {Object} attributes - The attributes carried by the command.
|
|
|
|
* @param {string} id - The identifier of the participant who issuing the
|
|
|
|
* command. A notable idiosyncrasy to be mindful of here is that the command
|
|
|
|
* may be issued by the local participant.
|
|
|
|
* @param {Object} store - The redux store. Used to calculate and dispatch
|
|
|
|
* updates.
|
|
|
|
* @private
|
2022-07-11 12:30:37 +00:00
|
|
|
* @returns {void}
|
2021-11-10 11:19:40 +00:00
|
|
|
*/
|
2022-06-08 07:44:47 +00:00
|
|
|
function _onMuteReactionsCommand(attributes: MuteCommandAttributes = {}, id: string, store: IStore) {
|
2021-11-10 11:19:40 +00:00
|
|
|
const state = store.getState();
|
|
|
|
|
|
|
|
// We require to know who issued the command because (1) only a
|
|
|
|
// moderator is allowed to send commands and (2) a command MUST be
|
|
|
|
// issued by a defined commander.
|
|
|
|
if (typeof id === 'undefined') {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const participantSendingCommand = getParticipantById(state, id);
|
|
|
|
|
|
|
|
// The Command(s) API will send us our own commands and we don't want
|
|
|
|
// to act upon them.
|
2022-08-08 08:12:22 +00:00
|
|
|
if (participantSendingCommand?.local) {
|
2021-11-10 11:19:40 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-08-08 08:12:22 +00:00
|
|
|
if (participantSendingCommand?.role !== 'moderator') {
|
2021-11-10 11:19:40 +00:00
|
|
|
logger.warn('Received mute-reactions command not from moderator');
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const oldState = Boolean(state['features/base/conference'].startReactionsMuted);
|
2022-07-11 12:30:37 +00:00
|
|
|
|
2022-06-08 07:44:47 +00:00
|
|
|
// @ts-ignore
|
2021-11-10 11:19:40 +00:00
|
|
|
const newState = attributes.startReactionsMuted === 'true';
|
|
|
|
|
|
|
|
if (oldState !== newState) {
|
|
|
|
batch(() => {
|
|
|
|
store.dispatch(setStartReactionsMuted(newState));
|
|
|
|
store.dispatch(updateSettings({ soundsReactions: !newState }));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|