2021-07-09 12:36:19 +00:00
|
|
|
import { batch } from 'react-redux';
|
|
|
|
|
2022-10-07 08:39:18 +00:00
|
|
|
import { IStore } from '../app/types';
|
|
|
|
import { APP_WILL_MOUNT, APP_WILL_UNMOUNT } from '../base/app/actionTypes';
|
|
|
|
import { CONFERENCE_JOINED } from '../base/conference/actionTypes';
|
|
|
|
import { getCurrentConference } from '../base/conference/functions';
|
2022-12-06 17:29:33 +00:00
|
|
|
import { openDialog } from '../base/dialog/actions';
|
|
|
|
import { JitsiConferenceEvents } from '../base/lib-jitsi-meet';
|
2022-10-07 08:39:18 +00:00
|
|
|
import { PARTICIPANT_JOINED, PARTICIPANT_LEFT, PARTICIPANT_UPDATED } from '../base/participants/actionTypes';
|
|
|
|
import { participantUpdated } from '../base/participants/actions';
|
2021-07-09 12:36:19 +00:00
|
|
|
import {
|
2022-09-27 07:10:28 +00:00
|
|
|
getLocalParticipant,
|
|
|
|
getParticipantById,
|
|
|
|
getParticipantCount,
|
|
|
|
getRemoteParticipants,
|
2022-10-07 08:39:18 +00:00
|
|
|
isScreenShareParticipant
|
|
|
|
} from '../base/participants/functions';
|
|
|
|
import MiddlewareRegistry from '../base/redux/MiddlewareRegistry';
|
|
|
|
import StateListenerRegistry from '../base/redux/StateListenerRegistry';
|
|
|
|
import { playSound, registerSound, unregisterSound } from '../base/sounds/actions';
|
2020-04-16 11:26:44 +00:00
|
|
|
|
2022-12-06 17:29:33 +00:00
|
|
|
import { PARTICIPANT_VERIFIED, SET_MEDIA_ENCRYPTION_KEY, START_VERIFICATION, TOGGLE_E2EE } from './actionTypes';
|
2021-09-21 11:00:23 +00:00
|
|
|
import { setE2EEMaxMode, setEveryoneEnabledE2EE, setEveryoneSupportE2EE, toggleE2EE } from './actions';
|
2022-12-06 17:29:33 +00:00
|
|
|
import ParticipantVerificationDialog from './components/ParticipantVerificationDialog';
|
2021-09-21 11:00:23 +00:00
|
|
|
import { E2EE_OFF_SOUND_ID, E2EE_ON_SOUND_ID, MAX_MODE } from './constants';
|
|
|
|
import { isMaxModeReached, isMaxModeThresholdReached } from './functions';
|
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
|
|
|
|
2022-12-06 17:29:33 +00:00
|
|
|
|
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 => {
|
2021-11-16 11:12:10 +00:00
|
|
|
const conference = getCurrentConference(getState);
|
|
|
|
|
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;
|
|
|
|
|
2021-09-21 11:00:23 +00:00
|
|
|
case CONFERENCE_JOINED:
|
|
|
|
_updateMaxMode(dispatch, getState);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
2021-07-09 12:36:19 +00:00
|
|
|
case PARTICIPANT_UPDATED: {
|
|
|
|
const { id, e2eeEnabled, e2eeSupported } = action.participant;
|
|
|
|
const oldParticipant = getParticipantById(getState(), id);
|
|
|
|
const result = next(action);
|
|
|
|
|
|
|
|
if (e2eeEnabled !== oldParticipant?.e2eeEnabled
|
|
|
|
|| e2eeSupported !== oldParticipant?.e2eeSupported) {
|
|
|
|
const state = getState();
|
|
|
|
let newEveryoneSupportE2EE = true;
|
|
|
|
let newEveryoneEnabledE2EE = true;
|
|
|
|
|
2022-10-07 08:39:18 +00:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
2021-07-09 12:36:19 +00:00
|
|
|
for (const [ key, p ] of getRemoteParticipants(state)) {
|
|
|
|
if (!p.e2eeEnabled) {
|
|
|
|
newEveryoneEnabledE2EE = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!p.e2eeSupported) {
|
|
|
|
newEveryoneSupportE2EE = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!newEveryoneEnabledE2EE && !newEveryoneSupportE2EE) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!getLocalParticipant(state)?.e2eeEnabled) {
|
|
|
|
newEveryoneEnabledE2EE = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
batch(() => {
|
|
|
|
dispatch(setEveryoneEnabledE2EE(newEveryoneEnabledE2EE));
|
|
|
|
dispatch(setEveryoneSupportE2EE(newEveryoneSupportE2EE));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
case PARTICIPANT_JOINED: {
|
|
|
|
const result = next(action);
|
2022-10-06 11:12:57 +00:00
|
|
|
const { e2eeEnabled, e2eeSupported, local } = action.participant;
|
2021-07-09 12:36:19 +00:00
|
|
|
const { everyoneEnabledE2EE } = getState()['features/e2ee'];
|
2021-09-21 11:00:23 +00:00
|
|
|
const participantCount = getParticipantCount(getState);
|
2021-07-09 12:36:19 +00:00
|
|
|
|
2022-10-06 11:12:57 +00:00
|
|
|
if (isScreenShareParticipant(action.participant)) {
|
2022-05-02 20:39:43 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2021-07-09 12:36:19 +00:00
|
|
|
// the initial values
|
|
|
|
if (participantCount === 1) {
|
|
|
|
batch(() => {
|
|
|
|
dispatch(setEveryoneEnabledE2EE(e2eeEnabled));
|
|
|
|
dispatch(setEveryoneSupportE2EE(e2eeSupported));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
// if all had it enabled and this one disabled it, change value in store
|
|
|
|
// otherwise there is no change in the value we store
|
|
|
|
if (everyoneEnabledE2EE && !e2eeEnabled) {
|
|
|
|
dispatch(setEveryoneEnabledE2EE(false));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (local) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
const { everyoneSupportE2EE } = getState()['features/e2ee'];
|
|
|
|
|
|
|
|
// if all supported it and this one does not, change value in store
|
|
|
|
// otherwise there is no change in the value we store
|
|
|
|
if (everyoneSupportE2EE && !e2eeSupported) {
|
|
|
|
dispatch(setEveryoneSupportE2EE(false));
|
|
|
|
}
|
|
|
|
|
2021-09-21 11:00:23 +00:00
|
|
|
_updateMaxMode(dispatch, getState);
|
|
|
|
|
2021-07-09 12:36:19 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
case PARTICIPANT_LEFT: {
|
|
|
|
const previosState = getState();
|
2022-10-07 08:39:18 +00:00
|
|
|
const participant = getParticipantById(previosState, action.participant?.id);
|
2021-07-09 12:36:19 +00:00
|
|
|
const result = next(action);
|
|
|
|
const newState = getState();
|
2022-10-07 08:39:18 +00:00
|
|
|
const { e2eeEnabled = false, e2eeSupported = false } = participant ?? {};
|
2022-05-02 20:39:43 +00:00
|
|
|
|
2022-10-06 11:12:57 +00:00
|
|
|
if (isScreenShareParticipant(participant)) {
|
2022-05-02 20:39:43 +00:00
|
|
|
return result;
|
|
|
|
}
|
2021-07-09 12:36:19 +00:00
|
|
|
|
|
|
|
const { everyoneEnabledE2EE, everyoneSupportE2EE } = newState['features/e2ee'];
|
|
|
|
|
|
|
|
|
|
|
|
// if it was not enabled by everyone, and the participant leaving had it disabled, or if it was not supported
|
|
|
|
// by everyone, and the participant leaving had it not supported let's check is it enabled for all that stay
|
|
|
|
if ((!everyoneEnabledE2EE && !e2eeEnabled) || (!everyoneSupportE2EE && !e2eeSupported)) {
|
|
|
|
let latestEveryoneEnabledE2EE = true;
|
|
|
|
let latestEveryoneSupportE2EE = true;
|
|
|
|
|
2022-10-07 08:39:18 +00:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
2021-07-09 12:36:19 +00:00
|
|
|
for (const [ key, p ] of getRemoteParticipants(newState)) {
|
|
|
|
if (!p.e2eeEnabled) {
|
|
|
|
latestEveryoneEnabledE2EE = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!p.e2eeSupported) {
|
|
|
|
latestEveryoneSupportE2EE = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!latestEveryoneEnabledE2EE && !latestEveryoneSupportE2EE) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!getLocalParticipant(newState)?.e2eeEnabled) {
|
|
|
|
latestEveryoneEnabledE2EE = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
batch(() => {
|
|
|
|
if (!everyoneEnabledE2EE && latestEveryoneEnabledE2EE) {
|
|
|
|
dispatch(setEveryoneEnabledE2EE(true));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!everyoneSupportE2EE && latestEveryoneSupportE2EE) {
|
|
|
|
dispatch(setEveryoneSupportE2EE(true));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-09-21 11:00:23 +00:00
|
|
|
_updateMaxMode(dispatch, getState);
|
|
|
|
|
2021-07-09 12:36:19 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2020-05-07 09:54:02 +00:00
|
|
|
case TOGGLE_E2EE: {
|
2022-10-07 08:39:18 +00:00
|
|
|
if (conference?.isE2EESupported() && 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,
|
2022-10-07 08:39:18 +00:00
|
|
|
id: participant?.id ?? '',
|
2020-04-23 12:12:30 +00:00
|
|
|
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;
|
|
|
|
}
|
2021-11-16 11:12:10 +00:00
|
|
|
|
|
|
|
case SET_MEDIA_ENCRYPTION_KEY: {
|
2022-10-07 08:39:18 +00:00
|
|
|
if (conference?.isE2EESupported()) {
|
2021-11-16 11:12:10 +00:00
|
|
|
const { exportedKey, index } = action.keyInfo;
|
|
|
|
|
|
|
|
if (exportedKey) {
|
|
|
|
window.crypto.subtle.importKey(
|
|
|
|
'raw',
|
|
|
|
new Uint8Array(exportedKey),
|
|
|
|
'AES-GCM',
|
|
|
|
false,
|
|
|
|
[ 'encrypt', 'decrypt' ])
|
|
|
|
.then(
|
|
|
|
encryptionKey => {
|
|
|
|
conference.setMediaEncryptionKey({
|
|
|
|
encryptionKey,
|
|
|
|
index
|
|
|
|
});
|
|
|
|
})
|
|
|
|
.catch(error => logger.error('SET_MEDIA_ENCRYPTION_KEY error', error));
|
|
|
|
} else {
|
|
|
|
conference.setMediaEncryptionKey({
|
|
|
|
encryptionKey: false,
|
|
|
|
index
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2022-12-06 17:29:33 +00:00
|
|
|
|
|
|
|
case PARTICIPANT_VERIFIED: {
|
|
|
|
const { isVerified, pId } = action;
|
|
|
|
|
|
|
|
conference?.markParticipantVerified(pId, isVerified);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case START_VERIFICATION: {
|
|
|
|
conference?.startVerification(action.pId);
|
|
|
|
break;
|
|
|
|
}
|
2020-04-16 11:26:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|
2022-12-06 17:29:33 +00:00
|
|
|
|
2022-12-09 10:39:13 +00:00
|
|
|
if (conference) {
|
|
|
|
conference.on(JitsiConferenceEvents.E2EE_VERIFICATION_AVAILABLE, (pId: string) => {
|
2022-12-06 17:29:33 +00:00
|
|
|
dispatch(participantUpdated({
|
2022-12-09 10:39:13 +00:00
|
|
|
e2eeVerificationAvailable: true,
|
2022-12-06 17:29:33 +00:00
|
|
|
id: pId
|
|
|
|
}));
|
|
|
|
});
|
2022-12-09 10:39:13 +00:00
|
|
|
|
|
|
|
conference.on(JitsiConferenceEvents.E2EE_VERIFICATION_READY, (pId: string, sas: object) => {
|
|
|
|
dispatch(openDialog(ParticipantVerificationDialog, { pId,
|
|
|
|
sas }));
|
|
|
|
});
|
|
|
|
|
|
|
|
conference.on(JitsiConferenceEvents.E2EE_VERIFICATION_COMPLETED,
|
|
|
|
(pId: string, success: boolean, message: string) => {
|
|
|
|
if (message) {
|
|
|
|
logger.warn('E2EE_VERIFICATION_COMPLETED warning', message);
|
|
|
|
}
|
|
|
|
dispatch(participantUpdated({
|
|
|
|
e2eeVerified: success,
|
|
|
|
id: pId
|
|
|
|
}));
|
|
|
|
});
|
|
|
|
}
|
2020-04-16 11:26:44 +00:00
|
|
|
});
|
2021-09-21 11:00:23 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the maxMode based on the number of participants in the conference.
|
|
|
|
*
|
|
|
|
* @param { Dispatch<any>} dispatch - The redux dispatch function.
|
|
|
|
* @param {Function|Object} getState - The {@code getState} function.
|
|
|
|
* @private
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
2022-10-07 08:39:18 +00:00
|
|
|
function _updateMaxMode(dispatch: IStore['dispatch'], getState: IStore['getState']) {
|
2021-09-21 11:00:23 +00:00
|
|
|
const state = getState();
|
|
|
|
|
2021-11-16 11:12:10 +00:00
|
|
|
const { e2ee = {} } = state['features/base/config'];
|
|
|
|
|
|
|
|
if (e2ee.externallyManagedKey) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-09-21 11:00:23 +00:00
|
|
|
if (isMaxModeThresholdReached(state)) {
|
|
|
|
dispatch(setE2EEMaxMode(MAX_MODE.THRESHOLD_EXCEEDED));
|
|
|
|
dispatch(toggleE2EE(false));
|
|
|
|
} else if (isMaxModeReached(state)) {
|
|
|
|
dispatch(setE2EEMaxMode(MAX_MODE.ENABLED));
|
|
|
|
} else {
|
|
|
|
dispatch(setE2EEMaxMode(MAX_MODE.DISABLED));
|
|
|
|
}
|
|
|
|
}
|