2021-05-10 20:06:19 +00:00
|
|
|
import debounce from 'lodash/debounce';
|
|
|
|
|
2022-10-27 07:33:11 +00:00
|
|
|
import { IStore } from '../app/types';
|
|
|
|
import { _handleParticipantError } from '../base/conference/functions';
|
|
|
|
import { MEDIA_TYPE } from '../base/media/constants';
|
|
|
|
import { getLocalParticipant } from '../base/participants/functions';
|
|
|
|
import StateListenerRegistry from '../base/redux/StateListenerRegistry';
|
2022-11-08 19:15:49 +00:00
|
|
|
import { getTrackSourceNameByMediaTypeAndParticipant } from '../base/tracks/functions';
|
2022-10-27 07:33:11 +00:00
|
|
|
import { reportError } from '../base/util/helpers';
|
2022-08-16 11:56:47 +00:00
|
|
|
import {
|
|
|
|
getActiveParticipantsIds,
|
|
|
|
getScreenshareFilmstripParticipantId,
|
|
|
|
isTopPanelEnabled
|
|
|
|
} from '../filmstrip/functions';
|
2022-10-27 07:33:11 +00:00
|
|
|
import { LAYOUTS } from '../video-layout/constants';
|
2022-03-16 14:57:30 +00:00
|
|
|
import {
|
2022-11-10 08:45:56 +00:00
|
|
|
getCurrentLayout,
|
2022-03-16 14:57:30 +00:00
|
|
|
getVideoQualityForLargeVideo,
|
|
|
|
getVideoQualityForResizableFilmstripThumbnails,
|
2022-11-10 08:45:56 +00:00
|
|
|
getVideoQualityForScreenSharingFilmstrip,
|
2022-03-29 08:45:09 +00:00
|
|
|
getVideoQualityForStageThumbnails,
|
2022-03-16 14:57:30 +00:00
|
|
|
shouldDisplayTileView
|
2022-10-27 07:33:11 +00:00
|
|
|
} from '../video-layout/functions';
|
2021-05-10 20:06:19 +00:00
|
|
|
|
2022-08-16 11:56:47 +00:00
|
|
|
import {
|
|
|
|
setMaxReceiverVideoQualityForLargeVideo,
|
|
|
|
setMaxReceiverVideoQualityForScreenSharingFilmstrip,
|
|
|
|
setMaxReceiverVideoQualityForStageFilmstrip,
|
|
|
|
setMaxReceiverVideoQualityForTileView,
|
|
|
|
setMaxReceiverVideoQualityForVerticalFilmstrip
|
|
|
|
} from './actions';
|
|
|
|
import { MAX_VIDEO_QUALITY, VIDEO_QUALITY_LEVELS, VIDEO_QUALITY_UNLIMITED } from './constants';
|
2021-05-10 20:06:19 +00:00
|
|
|
import { getReceiverVideoQualityLevel } from './functions';
|
|
|
|
import logger from './logger';
|
|
|
|
import { getMinHeightForQualityLvlMap } from './selector';
|
|
|
|
|
|
|
|
/**
|
2021-05-19 23:23:40 +00:00
|
|
|
* Handles changes in the visible participants in the filmstrip. The listener is debounced
|
2021-05-10 20:06:19 +00:00
|
|
|
* so that the client doesn't end up sending too many bridge messages when the user is
|
|
|
|
* scrolling through the thumbnails prompting updates to the selected endpoints.
|
|
|
|
*/
|
|
|
|
StateListenerRegistry.register(
|
2021-08-18 22:34:01 +00:00
|
|
|
/* selector */ state => state['features/filmstrip'].visibleRemoteParticipants,
|
|
|
|
/* listener */ debounce((visibleRemoteParticipants, store) => {
|
2021-05-10 20:06:19 +00:00
|
|
|
_updateReceiverVideoConstraints(store);
|
2021-05-19 23:23:40 +00:00
|
|
|
}, 100));
|
|
|
|
|
2022-03-02 03:04:44 +00:00
|
|
|
StateListenerRegistry.register(
|
|
|
|
/* selector */ state => state['features/base/tracks'],
|
|
|
|
/* listener */(remoteTracks, store) => {
|
|
|
|
_updateReceiverVideoConstraints(store);
|
|
|
|
});
|
|
|
|
|
2021-05-19 23:23:40 +00:00
|
|
|
/**
|
|
|
|
* Handles the use case when the on-stage participant has changed.
|
|
|
|
*/
|
|
|
|
StateListenerRegistry.register(
|
|
|
|
state => state['features/large-video'].participantId,
|
|
|
|
(participantId, store) => {
|
|
|
|
_updateReceiverVideoConstraints(store);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handles the use case when we have set some of the constraints in redux but the conference object wasn't available
|
|
|
|
* and we haven't been able to pass the constraints to lib-jitsi-meet.
|
|
|
|
*/
|
|
|
|
StateListenerRegistry.register(
|
|
|
|
state => state['features/base/conference'].conference,
|
|
|
|
(conference, store) => {
|
|
|
|
_updateReceiverVideoConstraints(store);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2021-05-10 20:06:19 +00:00
|
|
|
/**
|
|
|
|
* StateListenerRegistry provides a reliable way of detecting changes to
|
|
|
|
* lastn state and dispatching additional actions.
|
|
|
|
*/
|
|
|
|
StateListenerRegistry.register(
|
|
|
|
/* selector */ state => state['features/base/lastn'].lastN,
|
|
|
|
/* listener */ (lastN, store) => {
|
|
|
|
_updateReceiverVideoConstraints(store);
|
|
|
|
});
|
|
|
|
|
2022-03-29 08:45:09 +00:00
|
|
|
/**
|
|
|
|
* Updates the receiver constraints when the stage participants change.
|
|
|
|
*/
|
|
|
|
StateListenerRegistry.register(
|
2022-04-05 13:00:32 +00:00
|
|
|
state => getActiveParticipantsIds(state).sort(),
|
2022-03-29 08:45:09 +00:00
|
|
|
(_, store) => {
|
|
|
|
_updateReceiverVideoConstraints(store);
|
2022-04-05 13:00:32 +00:00
|
|
|
}, {
|
|
|
|
deepEquals: true
|
2022-03-29 08:45:09 +00:00
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2021-05-10 20:06:19 +00:00
|
|
|
/**
|
|
|
|
* StateListenerRegistry provides a reliable way of detecting changes to
|
2022-08-16 11:56:47 +00:00
|
|
|
* maxReceiverVideoQuality* and preferredVideoQuality state and dispatching additional actions.
|
2021-05-10 20:06:19 +00:00
|
|
|
*/
|
|
|
|
StateListenerRegistry.register(
|
|
|
|
/* selector */ state => {
|
|
|
|
const {
|
2022-08-16 11:56:47 +00:00
|
|
|
maxReceiverVideoQualityForLargeVideo,
|
|
|
|
maxReceiverVideoQualityForScreenSharingFilmstrip,
|
|
|
|
maxReceiverVideoQualityForStageFilmstrip,
|
|
|
|
maxReceiverVideoQualityForTileView,
|
|
|
|
maxReceiverVideoQualityForVerticalFilmstrip,
|
2021-05-10 20:06:19 +00:00
|
|
|
preferredVideoQuality
|
|
|
|
} = state['features/video-quality'];
|
|
|
|
|
|
|
|
return {
|
2022-08-16 11:56:47 +00:00
|
|
|
maxReceiverVideoQualityForLargeVideo,
|
|
|
|
maxReceiverVideoQualityForScreenSharingFilmstrip,
|
|
|
|
maxReceiverVideoQualityForStageFilmstrip,
|
|
|
|
maxReceiverVideoQualityForTileView,
|
|
|
|
maxReceiverVideoQualityForVerticalFilmstrip,
|
2021-05-10 20:06:19 +00:00
|
|
|
preferredVideoQuality
|
|
|
|
};
|
|
|
|
},
|
|
|
|
/* listener */ (currentState, store, previousState = {}) => {
|
2022-08-16 11:56:47 +00:00
|
|
|
const { preferredVideoQuality } = currentState;
|
2021-05-10 20:06:19 +00:00
|
|
|
const changedPreferredVideoQuality = preferredVideoQuality !== previousState.preferredVideoQuality;
|
|
|
|
|
|
|
|
if (changedPreferredVideoQuality) {
|
|
|
|
_setSenderVideoConstraint(preferredVideoQuality, store);
|
|
|
|
typeof APP !== 'undefined' && APP.API.notifyVideoQualityChanged(preferredVideoQuality);
|
|
|
|
}
|
2022-08-16 11:56:47 +00:00
|
|
|
_updateReceiverVideoConstraints(store);
|
2021-05-19 23:23:40 +00:00
|
|
|
}, {
|
|
|
|
deepEquals: true
|
2021-05-10 20:06:19 +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);
|
2022-08-16 11:56:47 +00:00
|
|
|
const tileViewThumbnailSize = state['features/filmstrip']?.tileViewDimensions?.thumbnailSize;
|
|
|
|
const { visibleRemoteParticipants } = state['features/filmstrip'];
|
|
|
|
const { height: largeVideoHeight } = state['features/large-video'];
|
|
|
|
const activeParticipantsIds = getActiveParticipantsIds(state);
|
|
|
|
const {
|
|
|
|
screenshareFilmstripDimensions: {
|
|
|
|
thumbnailSize
|
|
|
|
}
|
|
|
|
} = state['features/filmstrip'];
|
|
|
|
const screenshareFilmstripParticipantId = getScreenshareFilmstripParticipantId(state);
|
2021-05-10 20:06:19 +00:00
|
|
|
|
|
|
|
return {
|
2022-08-16 11:56:47 +00:00
|
|
|
activeParticipantsCount: activeParticipantsIds?.length,
|
2021-05-10 20:06:19 +00:00
|
|
|
displayTileView: _shouldDisplayTileView,
|
2022-08-16 11:56:47 +00:00
|
|
|
largeVideoHeight,
|
|
|
|
participantCount: visibleRemoteParticipants?.size || 0,
|
2021-05-10 20:06:19 +00:00
|
|
|
reducedUI,
|
2022-08-16 11:56:47 +00:00
|
|
|
screenSharingFilmstripHeight:
|
|
|
|
screenshareFilmstripParticipantId && getCurrentLayout(state) === LAYOUTS.STAGE_FILMSTRIP_VIEW
|
|
|
|
? thumbnailSize?.height : undefined,
|
|
|
|
stageFilmstripThumbnailHeight: state['features/filmstrip'].stageFilmstripDimensions?.thumbnailSize?.height,
|
|
|
|
tileViewThumbnailHeight: tileViewThumbnailSize?.height,
|
|
|
|
verticalFilmstripThumbnailHeight:
|
|
|
|
state['features/filmstrip'].verticalViewDimensions?.gridView?.thumbnailSize?.height
|
2021-05-10 20:06:19 +00:00
|
|
|
};
|
|
|
|
},
|
2022-08-16 11:56:47 +00:00
|
|
|
/* listener */ ({
|
|
|
|
activeParticipantsCount,
|
|
|
|
displayTileView,
|
|
|
|
largeVideoHeight,
|
|
|
|
participantCount,
|
|
|
|
reducedUI,
|
|
|
|
screenSharingFilmstripHeight,
|
|
|
|
stageFilmstripThumbnailHeight,
|
|
|
|
tileViewThumbnailHeight,
|
|
|
|
verticalFilmstripThumbnailHeight
|
|
|
|
}, store, previousState = {}) => {
|
|
|
|
const { dispatch, getState } = store;
|
2021-05-10 20:06:19 +00:00
|
|
|
const state = getState();
|
2022-08-16 11:56:47 +00:00
|
|
|
const {
|
|
|
|
maxReceiverVideoQualityForLargeVideo,
|
|
|
|
maxReceiverVideoQualityForScreenSharingFilmstrip,
|
|
|
|
maxReceiverVideoQualityForStageFilmstrip,
|
|
|
|
maxReceiverVideoQualityForTileView,
|
|
|
|
maxReceiverVideoQualityForVerticalFilmstrip
|
|
|
|
} = state['features/video-quality'];
|
2021-05-10 20:06:19 +00:00
|
|
|
const { maxFullResolutionParticipants = 2 } = state['features/base/config'];
|
2022-08-16 11:56:47 +00:00
|
|
|
let maxVideoQualityChanged = false;
|
|
|
|
|
2021-05-10 20:06:19 +00:00
|
|
|
|
2022-08-16 11:56:47 +00:00
|
|
|
if (displayTileView) {
|
|
|
|
let newMaxRecvVideoQuality = VIDEO_QUALITY_LEVELS.STANDARD;
|
2021-05-10 20:06:19 +00:00
|
|
|
|
2022-08-16 11:56:47 +00:00
|
|
|
if (reducedUI) {
|
|
|
|
newMaxRecvVideoQuality = VIDEO_QUALITY_LEVELS.LOW;
|
|
|
|
} else if (typeof tileViewThumbnailHeight === 'number' && !Number.isNaN(tileViewThumbnailHeight)) {
|
|
|
|
newMaxRecvVideoQuality
|
|
|
|
= getReceiverVideoQualityLevel(tileViewThumbnailHeight, getMinHeightForQualityLvlMap(state));
|
2021-05-10 20:06:19 +00:00
|
|
|
|
2022-08-16 11:56:47 +00:00
|
|
|
// Override HD level calculated for the thumbnail height when # of participants threshold is exceeded
|
|
|
|
if (maxFullResolutionParticipants !== -1) {
|
|
|
|
const override
|
|
|
|
= participantCount > maxFullResolutionParticipants
|
|
|
|
&& newMaxRecvVideoQuality > VIDEO_QUALITY_LEVELS.STANDARD;
|
2021-05-10 20:06:19 +00:00
|
|
|
|
2022-08-16 11:56:47 +00:00
|
|
|
logger.info(`Video quality level for thumbnail height: ${tileViewThumbnailHeight}, `
|
|
|
|
+ `is: ${newMaxRecvVideoQuality}, `
|
|
|
|
+ `override: ${String(override)}, `
|
|
|
|
+ `max full res N: ${maxFullResolutionParticipants}`);
|
2021-05-10 20:06:19 +00:00
|
|
|
|
2022-08-16 11:56:47 +00:00
|
|
|
if (override) {
|
|
|
|
newMaxRecvVideoQuality = VIDEO_QUALITY_LEVELS.STANDARD;
|
|
|
|
}
|
2021-05-10 20:06:19 +00:00
|
|
|
}
|
|
|
|
}
|
2022-08-16 11:56:47 +00:00
|
|
|
|
|
|
|
if (maxReceiverVideoQualityForTileView !== newMaxRecvVideoQuality) {
|
|
|
|
maxVideoQualityChanged = true;
|
|
|
|
dispatch(setMaxReceiverVideoQualityForTileView(newMaxRecvVideoQuality));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
let newMaxRecvVideoQualityForStageFilmstrip;
|
|
|
|
let newMaxRecvVideoQualityForVerticalFilmstrip;
|
|
|
|
let newMaxRecvVideoQualityForLargeVideo;
|
|
|
|
let newMaxRecvVideoQualityForScreenSharingFilmstrip;
|
|
|
|
|
|
|
|
if (reducedUI) {
|
|
|
|
newMaxRecvVideoQualityForVerticalFilmstrip
|
|
|
|
= newMaxRecvVideoQualityForStageFilmstrip
|
|
|
|
= newMaxRecvVideoQualityForLargeVideo
|
|
|
|
= newMaxRecvVideoQualityForScreenSharingFilmstrip
|
|
|
|
= VIDEO_QUALITY_LEVELS.LOW;
|
|
|
|
} else {
|
|
|
|
newMaxRecvVideoQualityForStageFilmstrip
|
|
|
|
= getVideoQualityForStageThumbnails(stageFilmstripThumbnailHeight, state);
|
|
|
|
newMaxRecvVideoQualityForVerticalFilmstrip
|
|
|
|
= getVideoQualityForResizableFilmstripThumbnails(verticalFilmstripThumbnailHeight, state);
|
|
|
|
newMaxRecvVideoQualityForLargeVideo = getVideoQualityForLargeVideo(largeVideoHeight);
|
|
|
|
newMaxRecvVideoQualityForScreenSharingFilmstrip
|
|
|
|
= getVideoQualityForScreenSharingFilmstrip(screenSharingFilmstripHeight, state);
|
|
|
|
|
|
|
|
// Override HD level calculated for the thumbnail height when # of participants threshold is exceeded
|
|
|
|
if (maxFullResolutionParticipants !== -1) {
|
|
|
|
if (activeParticipantsCount > 0
|
|
|
|
&& newMaxRecvVideoQualityForStageFilmstrip > VIDEO_QUALITY_LEVELS.STANDARD) {
|
|
|
|
const isScreenSharingFilmstripParticipantFullResolution
|
|
|
|
= newMaxRecvVideoQualityForScreenSharingFilmstrip > VIDEO_QUALITY_LEVELS.STANDARD;
|
|
|
|
|
|
|
|
if (activeParticipantsCount > maxFullResolutionParticipants
|
|
|
|
- (isScreenSharingFilmstripParticipantFullResolution ? 1 : 0)) {
|
|
|
|
newMaxRecvVideoQualityForStageFilmstrip = VIDEO_QUALITY_LEVELS.STANDARD;
|
|
|
|
newMaxRecvVideoQualityForVerticalFilmstrip
|
|
|
|
= Math.min(VIDEO_QUALITY_LEVELS.STANDARD, newMaxRecvVideoQualityForVerticalFilmstrip);
|
|
|
|
} else if (newMaxRecvVideoQualityForVerticalFilmstrip > VIDEO_QUALITY_LEVELS.STANDARD
|
|
|
|
&& participantCount > maxFullResolutionParticipants - activeParticipantsCount) {
|
|
|
|
newMaxRecvVideoQualityForVerticalFilmstrip = VIDEO_QUALITY_LEVELS.STANDARD;
|
|
|
|
}
|
|
|
|
} else if (newMaxRecvVideoQualityForVerticalFilmstrip > VIDEO_QUALITY_LEVELS.STANDARD
|
|
|
|
&& participantCount > maxFullResolutionParticipants
|
|
|
|
- (newMaxRecvVideoQualityForLargeVideo > VIDEO_QUALITY_LEVELS.STANDARD ? 1 : 0)) {
|
|
|
|
newMaxRecvVideoQualityForVerticalFilmstrip = VIDEO_QUALITY_LEVELS.STANDARD;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (maxReceiverVideoQualityForStageFilmstrip !== newMaxRecvVideoQualityForStageFilmstrip) {
|
|
|
|
maxVideoQualityChanged = true;
|
|
|
|
dispatch(setMaxReceiverVideoQualityForStageFilmstrip(newMaxRecvVideoQualityForStageFilmstrip));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (maxReceiverVideoQualityForVerticalFilmstrip !== newMaxRecvVideoQualityForVerticalFilmstrip) {
|
|
|
|
maxVideoQualityChanged = true;
|
|
|
|
dispatch(setMaxReceiverVideoQualityForVerticalFilmstrip(newMaxRecvVideoQualityForVerticalFilmstrip));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (maxReceiverVideoQualityForLargeVideo !== newMaxRecvVideoQualityForLargeVideo) {
|
|
|
|
maxVideoQualityChanged = true;
|
|
|
|
dispatch(setMaxReceiverVideoQualityForLargeVideo(newMaxRecvVideoQualityForLargeVideo));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (maxReceiverVideoQualityForScreenSharingFilmstrip !== newMaxRecvVideoQualityForScreenSharingFilmstrip) {
|
|
|
|
maxVideoQualityChanged = true;
|
|
|
|
dispatch(
|
|
|
|
setMaxReceiverVideoQualityForScreenSharingFilmstrip(
|
|
|
|
newMaxRecvVideoQualityForScreenSharingFilmstrip));
|
|
|
|
}
|
2021-05-10 20:06:19 +00:00
|
|
|
}
|
|
|
|
|
2022-08-16 11:56:47 +00:00
|
|
|
if (!maxVideoQualityChanged && Boolean(displayTileView) !== Boolean(previousState.displayTileView)) {
|
|
|
|
_updateReceiverVideoConstraints(store);
|
2021-05-10 20:06:19 +00:00
|
|
|
}
|
2022-08-16 11:56:47 +00:00
|
|
|
|
2021-05-10 20:06:19 +00:00
|
|
|
}, {
|
|
|
|
deepEquals: true
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Helper function for updating the preferred sender video constraint, based on the user preference.
|
|
|
|
*
|
|
|
|
* @param {number} preferred - The user preferred max frame height.
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
2022-10-27 07:33:11 +00:00
|
|
|
function _setSenderVideoConstraint(preferred: number, { getState }: IStore) {
|
2021-05-10 20:06:19 +00:00
|
|
|
const state = getState();
|
|
|
|
const { conference } = state['features/base/conference'];
|
|
|
|
|
|
|
|
if (!conference) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
logger.info(`Setting sender resolution to ${preferred}`);
|
|
|
|
conference.setSenderVideoConstraint(preferred)
|
2022-10-27 07:33:11 +00:00
|
|
|
.catch((error: any) => {
|
2021-05-10 20:06:19 +00:00
|
|
|
_handleParticipantError(error);
|
|
|
|
reportError(error, `Changing sender resolution to ${preferred} failed.`);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Private helper to calculate the receiver video constraints and set them on the bridge channel.
|
|
|
|
*
|
|
|
|
* @param {*} store - The redux store.
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
2022-10-27 07:33:11 +00:00
|
|
|
function _updateReceiverVideoConstraints({ getState }: IStore) {
|
2021-05-10 20:06:19 +00:00
|
|
|
const state = getState();
|
|
|
|
const { conference } = state['features/base/conference'];
|
|
|
|
|
|
|
|
if (!conference) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const { lastN } = state['features/base/lastn'];
|
2022-08-16 11:56:47 +00:00
|
|
|
const {
|
|
|
|
maxReceiverVideoQualityForTileView,
|
|
|
|
maxReceiverVideoQualityForStageFilmstrip,
|
|
|
|
maxReceiverVideoQualityForVerticalFilmstrip,
|
|
|
|
maxReceiverVideoQualityForLargeVideo,
|
|
|
|
maxReceiverVideoQualityForScreenSharingFilmstrip,
|
|
|
|
preferredVideoQuality
|
|
|
|
} = state['features/video-quality'];
|
2022-10-27 07:33:11 +00:00
|
|
|
const { participantId: largeVideoParticipantId = '' } = state['features/large-video'];
|
2022-08-16 11:56:47 +00:00
|
|
|
const maxFrameHeightForTileView = Math.min(maxReceiverVideoQualityForTileView, preferredVideoQuality);
|
|
|
|
const maxFrameHeightForStageFilmstrip = Math.min(maxReceiverVideoQualityForStageFilmstrip, preferredVideoQuality);
|
|
|
|
const maxFrameHeightForVerticalFilmstrip
|
|
|
|
= Math.min(maxReceiverVideoQualityForVerticalFilmstrip, preferredVideoQuality);
|
|
|
|
const maxFrameHeightForLargeVideo
|
|
|
|
= Math.min(maxReceiverVideoQualityForLargeVideo, preferredVideoQuality);
|
|
|
|
const maxFrameHeightForScreenSharingFilmstrip
|
|
|
|
= Math.min(maxReceiverVideoQualityForScreenSharingFilmstrip, preferredVideoQuality);
|
2021-11-19 16:17:54 +00:00
|
|
|
const { remoteScreenShares } = state['features/video-layout'];
|
2021-08-20 23:32:38 +00:00
|
|
|
const { visibleRemoteParticipants } = state['features/filmstrip'];
|
2021-12-16 17:49:36 +00:00
|
|
|
const tracks = state['features/base/tracks'];
|
2022-10-27 07:33:11 +00:00
|
|
|
const localParticipantId = getLocalParticipant(state)?.id;
|
2022-03-29 08:45:09 +00:00
|
|
|
const activeParticipantsIds = getActiveParticipantsIds(state);
|
2022-08-16 11:56:47 +00:00
|
|
|
const screenshareFilmstripParticipantId = isTopPanelEnabled(state) && getScreenshareFilmstripParticipantId(state);
|
|
|
|
|
2022-10-27 07:33:11 +00:00
|
|
|
const receiverConstraints: any = {
|
2022-08-16 11:56:47 +00:00
|
|
|
constraints: {},
|
|
|
|
defaultConstraints: { 'maxHeight': VIDEO_QUALITY_LEVELS.NONE },
|
|
|
|
lastN
|
|
|
|
};
|
2021-08-05 14:49:40 +00:00
|
|
|
|
2022-11-08 19:15:49 +00:00
|
|
|
const activeParticipantsSources: string[] = [];
|
|
|
|
const visibleRemoteTrackSourceNames: string[] = [];
|
2022-10-27 07:33:11 +00:00
|
|
|
let largeVideoSourceName: string | undefined;
|
2022-08-16 11:56:47 +00:00
|
|
|
|
2022-11-08 19:15:49 +00:00
|
|
|
receiverConstraints.onStageSources = [];
|
|
|
|
receiverConstraints.selectedSources = [];
|
2021-12-16 17:49:36 +00:00
|
|
|
|
2022-11-08 19:15:49 +00:00
|
|
|
if (visibleRemoteParticipants?.size) {
|
|
|
|
visibleRemoteParticipants.forEach(participantId => {
|
|
|
|
let sourceName;
|
2022-04-04 18:57:58 +00:00
|
|
|
|
2022-11-08 19:15:49 +00:00
|
|
|
if (remoteScreenShares.includes(participantId)) {
|
|
|
|
sourceName = participantId;
|
|
|
|
} else {
|
|
|
|
sourceName = getTrackSourceNameByMediaTypeAndParticipant(tracks, MEDIA_TYPE.VIDEO, participantId);
|
|
|
|
}
|
2021-12-16 17:49:36 +00:00
|
|
|
|
2022-11-08 19:15:49 +00:00
|
|
|
if (sourceName) {
|
|
|
|
visibleRemoteTrackSourceNames.push(sourceName);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2021-05-10 20:06:19 +00:00
|
|
|
|
2022-11-08 19:15:49 +00:00
|
|
|
if (activeParticipantsIds?.length > 0) {
|
|
|
|
activeParticipantsIds.forEach((participantId: string) => {
|
|
|
|
let sourceName;
|
2022-08-16 11:56:47 +00:00
|
|
|
|
2022-11-08 19:15:49 +00:00
|
|
|
if (remoteScreenShares.includes(participantId)) {
|
|
|
|
sourceName = participantId;
|
|
|
|
} else {
|
|
|
|
sourceName = getTrackSourceNameByMediaTypeAndParticipant(tracks, MEDIA_TYPE.VIDEO, participantId);
|
|
|
|
}
|
2022-08-16 11:56:47 +00:00
|
|
|
|
2022-11-08 19:15:49 +00:00
|
|
|
if (sourceName) {
|
|
|
|
activeParticipantsSources.push(sourceName);
|
|
|
|
}
|
|
|
|
});
|
2022-08-16 11:56:47 +00:00
|
|
|
|
2022-11-08 19:15:49 +00:00
|
|
|
}
|
2022-08-16 11:56:47 +00:00
|
|
|
|
2022-11-08 19:15:49 +00:00
|
|
|
if (localParticipantId !== largeVideoParticipantId) {
|
|
|
|
if (remoteScreenShares.includes(largeVideoParticipantId)) {
|
|
|
|
largeVideoSourceName = largeVideoParticipantId;
|
|
|
|
} else {
|
|
|
|
largeVideoSourceName = getTrackSourceNameByMediaTypeAndParticipant(
|
|
|
|
tracks, MEDIA_TYPE.VIDEO, largeVideoParticipantId
|
|
|
|
);
|
2021-12-16 17:49:36 +00:00
|
|
|
}
|
2022-08-16 11:56:47 +00:00
|
|
|
}
|
2022-03-16 14:57:30 +00:00
|
|
|
|
2022-08-16 11:56:47 +00:00
|
|
|
// Tile view.
|
|
|
|
if (shouldDisplayTileView(state)) {
|
|
|
|
if (!visibleRemoteTrackSourceNames?.length) {
|
|
|
|
return;
|
2021-05-19 23:23:40 +00:00
|
|
|
}
|
|
|
|
|
2022-08-16 11:56:47 +00:00
|
|
|
visibleRemoteTrackSourceNames.forEach(sourceName => {
|
|
|
|
receiverConstraints.constraints[sourceName] = { 'maxHeight': maxFrameHeightForTileView };
|
|
|
|
});
|
|
|
|
|
|
|
|
// Prioritize screenshare in tile view.
|
2022-11-08 19:15:49 +00:00
|
|
|
if (remoteScreenShares?.length) {
|
|
|
|
receiverConstraints.selectedSources = remoteScreenShares;
|
2022-04-08 17:51:42 +00:00
|
|
|
}
|
|
|
|
|
2022-08-16 11:56:47 +00:00
|
|
|
// Stage view.
|
2021-12-16 17:49:36 +00:00
|
|
|
} else {
|
2022-08-16 11:56:47 +00:00
|
|
|
if (!visibleRemoteTrackSourceNames?.length && !largeVideoSourceName && !activeParticipantsSources?.length) {
|
|
|
|
return;
|
|
|
|
}
|
2021-12-16 17:49:36 +00:00
|
|
|
|
2022-08-16 11:56:47 +00:00
|
|
|
if (visibleRemoteTrackSourceNames?.length) {
|
|
|
|
visibleRemoteTrackSourceNames.forEach(sourceName => {
|
|
|
|
receiverConstraints.constraints[sourceName] = { 'maxHeight': maxFrameHeightForVerticalFilmstrip };
|
2021-05-19 23:23:40 +00:00
|
|
|
});
|
2022-08-16 11:56:47 +00:00
|
|
|
}
|
2021-05-19 23:23:40 +00:00
|
|
|
|
2022-08-16 11:56:47 +00:00
|
|
|
if (getCurrentLayout(state) === LAYOUTS.STAGE_FILMSTRIP_VIEW && activeParticipantsSources.length > 0) {
|
|
|
|
const onStageSources = [ ...activeParticipantsSources ];
|
2021-12-16 17:49:36 +00:00
|
|
|
|
2022-08-16 11:56:47 +00:00
|
|
|
activeParticipantsSources.forEach(sourceName => {
|
|
|
|
const isScreenSharing = remoteScreenShares.includes(sourceName);
|
|
|
|
const quality
|
|
|
|
= isScreenSharing && preferredVideoQuality >= MAX_VIDEO_QUALITY
|
|
|
|
? VIDEO_QUALITY_UNLIMITED : maxFrameHeightForStageFilmstrip;
|
2022-03-16 14:57:30 +00:00
|
|
|
|
2022-08-16 11:56:47 +00:00
|
|
|
receiverConstraints.constraints[sourceName] = { 'maxHeight': quality };
|
|
|
|
});
|
2022-03-29 08:45:09 +00:00
|
|
|
|
2022-08-16 11:56:47 +00:00
|
|
|
if (screenshareFilmstripParticipantId) {
|
|
|
|
onStageSources.push(screenshareFilmstripParticipantId);
|
|
|
|
receiverConstraints.constraints[screenshareFilmstripParticipantId]
|
|
|
|
= {
|
|
|
|
'maxHeight':
|
|
|
|
preferredVideoQuality >= MAX_VIDEO_QUALITY
|
|
|
|
? VIDEO_QUALITY_UNLIMITED : maxFrameHeightForScreenSharingFilmstrip
|
|
|
|
};
|
2021-12-16 17:49:36 +00:00
|
|
|
}
|
|
|
|
|
2022-11-08 19:15:49 +00:00
|
|
|
receiverConstraints.onStageSources = onStageSources;
|
2022-08-16 11:56:47 +00:00
|
|
|
} else if (largeVideoSourceName) {
|
|
|
|
let quality = VIDEO_QUALITY_UNLIMITED;
|
2022-03-16 14:57:30 +00:00
|
|
|
|
2022-08-16 11:56:47 +00:00
|
|
|
if (preferredVideoQuality < MAX_VIDEO_QUALITY
|
|
|
|
|| !remoteScreenShares.find(id => id === largeVideoParticipantId)) {
|
|
|
|
quality = maxFrameHeightForLargeVideo;
|
2021-12-16 17:49:36 +00:00
|
|
|
}
|
2022-08-16 11:56:47 +00:00
|
|
|
receiverConstraints.constraints[largeVideoSourceName] = { 'maxHeight': quality };
|
2022-11-08 19:15:49 +00:00
|
|
|
receiverConstraints.onStageSources = [ largeVideoSourceName ];
|
2021-05-19 23:23:40 +00:00
|
|
|
}
|
2021-05-10 20:06:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
conference.setReceiverConstraints(receiverConstraints);
|
2022-10-27 07:33:11 +00:00
|
|
|
} catch (error: any) {
|
2021-05-10 20:06:19 +00:00
|
|
|
_handleParticipantError(error);
|
|
|
|
reportError(error, `Failed to set receiver video constraints ${JSON.stringify(receiverConstraints)}`);
|
|
|
|
}
|
|
|
|
}
|