2020-04-16 11:26:44 +00:00
|
|
|
// @flow
|
|
|
|
|
2021-03-30 09:59:32 +00:00
|
|
|
import { APP_WILL_MOUNT, APP_WILL_UNMOUNT } from '../base/app';
|
2020-04-16 11:26:44 +00:00
|
|
|
import { getCurrentConference } from '../base/conference';
|
2020-04-23 12:12:30 +00:00
|
|
|
import { getLocalParticipant, participantUpdated } from '../base/participants';
|
2020-04-16 11:26:44 +00:00
|
|
|
import { MiddlewareRegistry, StateListenerRegistry } from '../base/redux';
|
2021-03-30 09:59:32 +00:00
|
|
|
import { playSound, registerSound, unregisterSound } from '../base/sounds';
|
2020-04-16 11:26:44 +00:00
|
|
|
|
2020-05-07 09:54:02 +00:00
|
|
|
import { TOGGLE_E2EE } from './actionTypes';
|
|
|
|
import { toggleE2EE } from './actions';
|
2021-03-30 09:59:32 +00:00
|
|
|
import { E2EE_OFF_SOUND_ID, E2EE_ON_SOUND_ID } from './constants';
|
2020-04-16 11:26:44 +00:00
|
|
|
import logger from './logger';
|
2021-03-30 09:59:32 +00:00
|
|
|
import { E2EE_OFF_SOUND_FILE, E2EE_ON_SOUND_FILE } from './sounds';
|
2020-04-16 11:26:44 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Middleware that captures actions related to E2EE.
|
|
|
|
*
|
|
|
|
* @param {Store} store - The redux store.
|
|
|
|
* @returns {Function}
|
|
|
|
*/
|
2020-04-23 12:12:30 +00:00
|
|
|
MiddlewareRegistry.register(({ dispatch, getState }) => next => action => {
|
2020-04-16 11:26:44 +00:00
|
|
|
switch (action.type) {
|
2021-03-30 09:59:32 +00:00
|
|
|
case APP_WILL_MOUNT:
|
|
|
|
dispatch(registerSound(
|
|
|
|
E2EE_OFF_SOUND_ID,
|
|
|
|
E2EE_OFF_SOUND_FILE));
|
|
|
|
|
|
|
|
dispatch(registerSound(
|
|
|
|
E2EE_ON_SOUND_ID,
|
|
|
|
E2EE_ON_SOUND_FILE));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case APP_WILL_UNMOUNT:
|
|
|
|
dispatch(unregisterSound(E2EE_OFF_SOUND_ID));
|
|
|
|
dispatch(unregisterSound(E2EE_ON_SOUND_ID));
|
|
|
|
break;
|
|
|
|
|
2020-05-07 09:54:02 +00:00
|
|
|
case TOGGLE_E2EE: {
|
2020-04-16 11:26:44 +00:00
|
|
|
const conference = getCurrentConference(getState);
|
|
|
|
|
2021-04-01 09:34:01 +00:00
|
|
|
if (conference && conference.isE2EEEnabled() !== action.enabled) {
|
2020-05-07 09:54:02 +00:00
|
|
|
logger.debug(`E2EE will be ${action.enabled ? 'enabled' : 'disabled'}`);
|
|
|
|
conference.toggleE2EE(action.enabled);
|
2020-04-23 12:12:30 +00:00
|
|
|
|
2021-03-22 10:21:48 +00:00
|
|
|
// Broadcast that we enabled / disabled E2EE.
|
2020-04-23 12:12:30 +00:00
|
|
|
const participant = getLocalParticipant(getState);
|
|
|
|
|
|
|
|
dispatch(participantUpdated({
|
2020-05-07 09:54:02 +00:00
|
|
|
e2eeEnabled: action.enabled,
|
2020-04-23 12:12:30 +00:00
|
|
|
id: participant.id,
|
|
|
|
local: true
|
|
|
|
}));
|
2021-03-30 09:59:32 +00:00
|
|
|
|
|
|
|
const soundID = action.enabled ? E2EE_ON_SOUND_ID : E2EE_OFF_SOUND_ID;
|
|
|
|
|
|
|
|
dispatch(playSound(soundID));
|
2020-04-16 11:26:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return next(action);
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set up state change listener to perform maintenance tasks when the conference
|
|
|
|
* is left or failed.
|
|
|
|
*/
|
|
|
|
StateListenerRegistry.register(
|
|
|
|
state => getCurrentConference(state),
|
|
|
|
(conference, { dispatch }, previousConference) => {
|
|
|
|
if (previousConference) {
|
2020-05-07 09:54:02 +00:00
|
|
|
dispatch(toggleE2EE(false));
|
2020-04-16 11:26:44 +00:00
|
|
|
}
|
|
|
|
});
|