2018-05-18 19:59:07 +00:00
|
|
|
// @flow
|
|
|
|
|
2018-05-18 00:41:28 +00:00
|
|
|
import VideoLayout from '../../../modules/UI/videolayout/VideoLayout.js';
|
2018-05-18 19:59:07 +00:00
|
|
|
import UIEvents from '../../../service/UI/UIEvents';
|
2018-05-18 00:41:28 +00:00
|
|
|
|
2018-05-18 19:59:07 +00:00
|
|
|
import {
|
|
|
|
DOMINANT_SPEAKER_CHANGED,
|
2018-05-22 17:13:51 +00:00
|
|
|
PARTICIPANT_JOINED,
|
2018-05-21 21:22:41 +00:00
|
|
|
PARTICIPANT_LEFT,
|
2018-05-21 21:06:02 +00:00
|
|
|
PARTICIPANT_UPDATED,
|
2018-05-22 17:13:51 +00:00
|
|
|
PIN_PARTICIPANT,
|
|
|
|
getParticipantById
|
2018-05-18 19:59:07 +00:00
|
|
|
} from '../base/participants';
|
2018-05-17 22:42:21 +00:00
|
|
|
import { MiddlewareRegistry } from '../base/redux';
|
|
|
|
|
2018-05-18 19:59:07 +00:00
|
|
|
declare var APP: Object;
|
|
|
|
|
2018-05-17 22:42:21 +00:00
|
|
|
/**
|
|
|
|
* Middleware which intercepts actions and updates the legacy component
|
|
|
|
* {@code VideoLayout} as needed. The purpose of this middleware is to redux-ify
|
|
|
|
* {@code VideoLayout} without having to simultaneously react-ifying it.
|
|
|
|
*
|
|
|
|
* @param {Store} store - The redux store.
|
|
|
|
* @returns {Function}
|
|
|
|
*/
|
|
|
|
// eslint-disable-next-line no-unused-vars
|
2018-05-18 00:41:28 +00:00
|
|
|
MiddlewareRegistry.register(store => next => action => {
|
2018-05-18 19:59:07 +00:00
|
|
|
// Purposefully perform additional actions after state update to mimic
|
|
|
|
// being connected to the store for updates.
|
2018-05-18 00:41:28 +00:00
|
|
|
const result = next(action);
|
|
|
|
|
|
|
|
switch (action.type) {
|
2018-05-22 17:13:51 +00:00
|
|
|
case PARTICIPANT_JOINED:
|
|
|
|
if (!action.participant.local) {
|
|
|
|
VideoLayout.addRemoteParticipantContainer(
|
|
|
|
getParticipantById(store.getState(), action.participant.id));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2018-05-21 21:22:41 +00:00
|
|
|
case PARTICIPANT_LEFT:
|
|
|
|
VideoLayout.removeParticipantContainer(action.participant.id);
|
|
|
|
break;
|
2018-05-21 21:06:02 +00:00
|
|
|
|
|
|
|
case PARTICIPANT_UPDATED: {
|
|
|
|
// Look for actions that triggered a change to connectionStatus. This is
|
|
|
|
// done instead of changing the connection status change action to be
|
|
|
|
// explicit in order to minimize changes to other code.
|
|
|
|
if (typeof action.participant.connectionStatus !== 'undefined') {
|
|
|
|
VideoLayout.onParticipantConnectionStatusChanged(
|
|
|
|
action.participant.id);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2018-05-18 00:41:28 +00:00
|
|
|
case DOMINANT_SPEAKER_CHANGED:
|
|
|
|
VideoLayout.onDominantSpeakerChanged(action.participant.id);
|
|
|
|
break;
|
2018-05-18 19:59:07 +00:00
|
|
|
|
|
|
|
case PIN_PARTICIPANT:
|
|
|
|
VideoLayout.onPinChange(action.participant.id);
|
|
|
|
APP.UI.emitEvent(
|
|
|
|
UIEvents.PINNED_ENDPOINT,
|
|
|
|
action.participant.id,
|
|
|
|
Boolean(action.participant.id));
|
|
|
|
break;
|
2018-05-18 00:41:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
});
|