2020-05-07 18:26:10 +00:00
|
|
|
// @flow
|
|
|
|
|
2020-05-20 10:57:03 +00:00
|
|
|
import type { Dispatch } from 'redux';
|
|
|
|
|
2020-09-01 19:19:04 +00:00
|
|
|
import { SET_MAX_RECEIVER_VIDEO_QUALITY, SET_PREFERRED_VIDEO_QUALITY } from './actionTypes';
|
|
|
|
import { VIDEO_QUALITY_LEVELS } from './constants';
|
2020-05-07 18:26:10 +00:00
|
|
|
import logger from './logger';
|
|
|
|
|
2020-09-01 19:19:04 +00:00
|
|
|
/**
|
|
|
|
* Sets the max frame height the user prefers to send and receive from the
|
|
|
|
* remote participants.
|
|
|
|
*
|
|
|
|
* @param {number} preferredVideoQuality - The max video resolution to send and
|
|
|
|
* receive.
|
|
|
|
* @returns {{
|
|
|
|
* type: SET_PREFERRED_VIDEO_QUALITY,
|
|
|
|
* preferredVideoQuality: number
|
|
|
|
* }}
|
|
|
|
*/
|
|
|
|
export function setPreferredVideoQuality(preferredVideoQuality: number) {
|
|
|
|
return {
|
|
|
|
type: SET_PREFERRED_VIDEO_QUALITY,
|
|
|
|
preferredVideoQuality
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the max frame height that should be received from remote videos.
|
|
|
|
*
|
|
|
|
* @param {number} maxReceiverVideoQuality - The max video frame height to
|
|
|
|
* receive.
|
|
|
|
* @returns {{
|
|
|
|
* type: SET_MAX_RECEIVER_VIDEO_QUALITY,
|
|
|
|
* maxReceiverVideoQuality: number
|
|
|
|
* }}
|
|
|
|
*/
|
|
|
|
export function setMaxReceiverVideoQuality(maxReceiverVideoQuality: number) {
|
|
|
|
return {
|
|
|
|
type: SET_MAX_RECEIVER_VIDEO_QUALITY,
|
|
|
|
maxReceiverVideoQuality
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-05-07 18:26:10 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the maximum video size the local participant should send and receive from
|
|
|
|
* remote participants.
|
|
|
|
*
|
|
|
|
* @param {number} frameHeight - The user preferred max frame height for send and
|
|
|
|
* receive video.
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
export function setVideoQuality(frameHeight: number) {
|
2020-09-01 20:48:14 +00:00
|
|
|
return (dispatch: Dispatch<any>) => {
|
2020-05-07 18:26:10 +00:00
|
|
|
if (frameHeight < VIDEO_QUALITY_LEVELS.LOW) {
|
|
|
|
logger.error(`Invalid frame height for video quality - ${frameHeight}`);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
2020-09-01 20:48:14 +00:00
|
|
|
|
|
|
|
dispatch(setPreferredVideoQuality(Math.min(frameHeight, VIDEO_QUALITY_LEVELS.HIGH)));
|
2020-05-07 18:26:10 +00:00
|
|
|
};
|
|
|
|
}
|