2020-07-07 20:34:52 +00:00
|
|
|
// @flow
|
|
|
|
|
2020-07-15 20:30:44 +00:00
|
|
|
import {
|
|
|
|
CONFERENCE_JOINED,
|
|
|
|
VIDEO_QUALITY_LEVELS,
|
|
|
|
setMaxReceiverVideoQuality,
|
|
|
|
setPreferredVideoQuality
|
|
|
|
} from '../base/conference';
|
2020-08-05 15:10:14 +00:00
|
|
|
import { getParticipantCount } from '../base/participants';
|
2020-07-15 20:30:44 +00:00
|
|
|
import { MiddlewareRegistry, StateListenerRegistry } from '../base/redux';
|
|
|
|
import { shouldDisplayTileView } from '../video-layout';
|
2020-07-07 20:34:52 +00:00
|
|
|
|
2020-08-19 21:38:10 +00:00
|
|
|
import { getReceiverVideoQualityLevel } from './functions';
|
2020-07-07 20:34:52 +00:00
|
|
|
import logger from './logger';
|
2020-08-19 21:38:10 +00:00
|
|
|
import { getMinHeightForQualityLvlMap } from './selector';
|
2020-07-07 20:34:52 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Implements the middleware of the feature video-quality.
|
|
|
|
*
|
|
|
|
* @param {Store} store - The redux store.
|
|
|
|
* @returns {Function}
|
|
|
|
*/
|
|
|
|
MiddlewareRegistry.register(({ dispatch, getState }) => next => action => {
|
|
|
|
const result = next(action);
|
|
|
|
|
|
|
|
switch (action.type) {
|
|
|
|
case CONFERENCE_JOINED: {
|
|
|
|
if (navigator.product === 'ReactNative') {
|
|
|
|
const { resolution } = getState()['features/base/config'];
|
|
|
|
|
|
|
|
if (typeof resolution !== 'undefined') {
|
|
|
|
dispatch(setPreferredVideoQuality(Number.parseInt(resolution, 10)));
|
|
|
|
logger.info(`Configured preferred receiver video frame height to: ${resolution}`);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
});
|
2020-07-15 20:30:44 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Implements a state listener in order to calculate max receiver video quality.
|
|
|
|
*/
|
|
|
|
StateListenerRegistry.register(
|
|
|
|
/* selector */ state => {
|
|
|
|
const { reducedUI } = state['features/base/responsive-ui'];
|
|
|
|
const _shouldDisplayTileView = shouldDisplayTileView(state);
|
|
|
|
const thumbnailSize = state['features/filmstrip']?.tileViewDimensions?.thumbnailSize;
|
2020-08-05 15:10:14 +00:00
|
|
|
const participantCount = getParticipantCount(state);
|
2020-07-15 20:30:44 +00:00
|
|
|
|
|
|
|
return {
|
|
|
|
displayTileView: _shouldDisplayTileView,
|
2020-08-05 15:10:14 +00:00
|
|
|
participantCount,
|
2020-07-15 20:30:44 +00:00
|
|
|
reducedUI,
|
|
|
|
thumbnailHeight: thumbnailSize?.height
|
|
|
|
};
|
|
|
|
},
|
2020-08-05 15:10:14 +00:00
|
|
|
/* listener */ ({ displayTileView, participantCount, reducedUI, thumbnailHeight }, { dispatch, getState }) => {
|
|
|
|
const state = getState();
|
|
|
|
const { maxReceiverVideoQuality } = state['features/base/conference'];
|
|
|
|
const { maxFullResolutionParticipants = 2 } = state['features/base/config'];
|
|
|
|
|
2020-07-15 20:30:44 +00:00
|
|
|
let newMaxRecvVideoQuality = VIDEO_QUALITY_LEVELS.HIGH;
|
|
|
|
|
|
|
|
if (reducedUI) {
|
|
|
|
newMaxRecvVideoQuality = VIDEO_QUALITY_LEVELS.LOW;
|
|
|
|
} else if (displayTileView && !Number.isNaN(thumbnailHeight)) {
|
2020-08-19 21:38:10 +00:00
|
|
|
newMaxRecvVideoQuality = getReceiverVideoQualityLevel(thumbnailHeight, getMinHeightForQualityLvlMap(state));
|
2020-08-05 15:10:14 +00:00
|
|
|
|
|
|
|
// Override HD level calculated for the thumbnail height when # of participants threshold is exceeded
|
|
|
|
if (maxReceiverVideoQuality !== newMaxRecvVideoQuality && maxFullResolutionParticipants !== -1) {
|
|
|
|
const override
|
|
|
|
= participantCount > maxFullResolutionParticipants
|
|
|
|
&& newMaxRecvVideoQuality > VIDEO_QUALITY_LEVELS.STANDARD;
|
|
|
|
|
2020-08-19 21:38:10 +00:00
|
|
|
logger.info(`Video quality level for thumbnail height: ${thumbnailHeight}, `
|
2020-08-05 15:10:14 +00:00
|
|
|
+ `is: ${newMaxRecvVideoQuality}, `
|
|
|
|
+ `override: ${String(override)}, `
|
|
|
|
+ `max full res N: ${maxFullResolutionParticipants}`);
|
|
|
|
|
|
|
|
if (override) {
|
|
|
|
newMaxRecvVideoQuality = VIDEO_QUALITY_LEVELS.STANDARD;
|
|
|
|
}
|
|
|
|
}
|
2020-07-15 20:30:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (maxReceiverVideoQuality !== newMaxRecvVideoQuality) {
|
|
|
|
dispatch(setMaxReceiverVideoQuality(newMaxRecvVideoQuality));
|
|
|
|
}
|
|
|
|
}, {
|
|
|
|
deepEquals: true
|
|
|
|
});
|