2021-07-13 06:50:08 +00:00
|
|
|
// @flow
|
|
|
|
|
2021-07-20 11:31:49 +00:00
|
|
|
import { batch } from 'react-redux';
|
|
|
|
|
2021-08-23 09:57:56 +00:00
|
|
|
import { APP_WILL_MOUNT, APP_WILL_UNMOUNT } from '../base/app';
|
2021-09-14 08:15:03 +00:00
|
|
|
import { getParticipantCount } from '../base/participants';
|
2021-07-13 06:50:08 +00:00
|
|
|
import { MiddlewareRegistry } from '../base/redux';
|
2021-08-23 09:57:56 +00:00
|
|
|
import { updateSettings } from '../base/settings';
|
|
|
|
import { playSound, registerSound, unregisterSound } from '../base/sounds';
|
2021-10-04 08:37:02 +00:00
|
|
|
import { getDisabledSounds } from '../base/sounds/functions.any';
|
2021-08-23 09:57:56 +00:00
|
|
|
import { NOTIFICATION_TIMEOUT, 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';
|
2021-08-31 11:00:27 +00:00
|
|
|
import { displayReactionSoundsNotification } from './actions';
|
2021-07-13 06:50:08 +00:00
|
|
|
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';
|
2021-10-04 08:37:02 +00:00
|
|
|
import {
|
|
|
|
ENDPOINT_REACTION_NAME,
|
|
|
|
RAISE_HAND_SOUND_ID,
|
|
|
|
REACTIONS,
|
|
|
|
REACTION_SOUND,
|
|
|
|
SOUNDS_THRESHOLDS
|
|
|
|
} from './constants';
|
2021-08-23 09:57:56 +00:00
|
|
|
import {
|
|
|
|
getReactionMessageFromBuffer,
|
|
|
|
getReactionsSoundsThresholds,
|
|
|
|
getReactionsWithId,
|
|
|
|
sendReactionsWebhook
|
|
|
|
} from './functions.any';
|
|
|
|
import { RAISE_HAND_SOUND_FILE } from './sounds';
|
2021-07-13 06:50:08 +00:00
|
|
|
|
|
|
|
|
|
|
|
declare var APP: Object;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Middleware which intercepts Reactions actions to handle changes to the
|
|
|
|
* visibility timeout of the Reactions.
|
|
|
|
*
|
|
|
|
* @param {Store} store - The redux store.
|
|
|
|
* @returns {Function}
|
|
|
|
*/
|
|
|
|
MiddlewareRegistry.register(store => next => action => {
|
|
|
|
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;
|
|
|
|
|
|
|
|
clearTimeout(timeoutID);
|
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;
|
|
|
|
}
|
|
|
|
|
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 SEND_REACTIONS: {
|
|
|
|
const state = getState();
|
|
|
|
const { buffer } = state['features/reactions'];
|
2021-07-13 06:50:08 +00:00
|
|
|
const { conference } = state['features/base/conference'];
|
|
|
|
|
|
|
|
if (conference) {
|
|
|
|
conference.sendEndpointMessage('', {
|
|
|
|
name: ENDPOINT_REACTION_NAME,
|
2021-07-20 11:31:49 +00:00
|
|
|
reactions: buffer,
|
2021-07-13 06:50:08 +00:00
|
|
|
timestamp: Date.now()
|
|
|
|
});
|
|
|
|
}
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
case SHOW_SOUNDS_NOTIFICATION: {
|
|
|
|
dispatch(showNotification({
|
|
|
|
titleKey: 'toolbar.disableReactionSounds',
|
|
|
|
customActionNameKey: 'notify.reactionSounds',
|
|
|
|
customActionHandler: () => dispatch(updateSettings({
|
|
|
|
soundsReactions: false
|
|
|
|
}))
|
|
|
|
}, NOTIFICATION_TIMEOUT));
|
|
|
|
break;
|
2021-07-13 06:50:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return next(action);
|
|
|
|
});
|