This commit is contained in:
9
react/features/base/lastn/actionTypes.ts
Normal file
9
react/features/base/lastn/actionTypes.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
/**
|
||||
* The type of (redux) action which sets the last-n for the conference.
|
||||
*
|
||||
* {
|
||||
* type: SET_LAST_N,
|
||||
* lastN: number
|
||||
* }
|
||||
*/
|
||||
export const SET_LAST_N = 'SET_LAST_N';
|
||||
17
react/features/base/lastn/actions.ts
Normal file
17
react/features/base/lastn/actions.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
import { SET_LAST_N } from './actionTypes';
|
||||
|
||||
/**
|
||||
* Sets the last-n, i.e., the number of remote videos to be requested from the bridge for the conference.
|
||||
*
|
||||
* @param {number} lastN - The number of remote videos to be requested.
|
||||
* @returns {{
|
||||
* type: SET_LAST_N,
|
||||
* lastN: number
|
||||
* }}
|
||||
*/
|
||||
export function setLastN(lastN: number) {
|
||||
return {
|
||||
type: SET_LAST_N,
|
||||
lastN
|
||||
};
|
||||
}
|
||||
24
react/features/base/lastn/functions.ts
Normal file
24
react/features/base/lastn/functions.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import { VIDEO_QUALITY_LEVELS } from '../../video-quality/constants';
|
||||
|
||||
/**
|
||||
* Determines the lastN value to be used for the conference based on the video quality selected.
|
||||
*
|
||||
* @param {string} qualityLevel - Quality level (height) selected.
|
||||
* @param {number} channelLastN - LastN value set for the whole conference.
|
||||
* @returns {number} LastN value applicable to the quality level specified.
|
||||
*/
|
||||
export function getLastNForQualityLevel(qualityLevel: number, channelLastN: number) {
|
||||
let lastN = channelLastN;
|
||||
|
||||
const videoQualityLevels = Object.values(VIDEO_QUALITY_LEVELS);
|
||||
|
||||
for (const lvl in videoQualityLevels) {
|
||||
if (videoQualityLevels.hasOwnProperty(lvl)
|
||||
&& qualityLevel === videoQualityLevels[lvl]
|
||||
&& Number(lvl) > 1) {
|
||||
lastN = Math.floor(channelLastN / Math.pow(2, Number(lvl) - 1));
|
||||
}
|
||||
}
|
||||
|
||||
return lastN;
|
||||
}
|
||||
3
react/features/base/lastn/logger.ts
Normal file
3
react/features/base/lastn/logger.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
import { getLogger } from '../logging/functions';
|
||||
|
||||
export default getLogger('features/base/lastn');
|
||||
92
react/features/base/lastn/middleware.ts
Normal file
92
react/features/base/lastn/middleware.ts
Normal file
@@ -0,0 +1,92 @@
|
||||
import { debounce } from 'lodash-es';
|
||||
|
||||
import { IStore } from '../../app/types';
|
||||
import { SET_FILMSTRIP_ENABLED } from '../../filmstrip/actionTypes';
|
||||
import { APP_STATE_CHANGED } from '../../mobile/background/actionTypes';
|
||||
import {
|
||||
SET_CAR_MODE,
|
||||
VIRTUAL_SCREENSHARE_REMOTE_PARTICIPANTS_UPDATED
|
||||
} from '../../video-layout/actionTypes';
|
||||
import { SET_AUDIO_ONLY } from '../audio-only/actionTypes';
|
||||
import { CONFERENCE_JOINED } from '../conference/actionTypes';
|
||||
import { getParticipantById } from '../participants/functions';
|
||||
import MiddlewareRegistry from '../redux/MiddlewareRegistry';
|
||||
|
||||
import { setLastN } from './actions';
|
||||
import logger from './logger';
|
||||
|
||||
/**
|
||||
* Updates the last N value in the conference based on the current state of the redux store.
|
||||
*
|
||||
* @param {Store} store - The redux store.
|
||||
* @private
|
||||
* @returns {void}
|
||||
*/
|
||||
const _updateLastN = debounce(({ dispatch, getState }: IStore) => {
|
||||
const state = getState();
|
||||
const { conference } = state['features/base/conference'];
|
||||
|
||||
if (!conference) {
|
||||
logger.debug('There is no active conference, not updating last N');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
const { enabled: audioOnly } = state['features/base/audio-only'];
|
||||
const { appState } = state['features/mobile/background'] || {};
|
||||
const { enabled: filmStripEnabled } = state['features/filmstrip'];
|
||||
const config = state['features/base/config'];
|
||||
const { carMode } = state['features/video-layout'];
|
||||
|
||||
// Select the (initial) lastN value based on the following preference order.
|
||||
// 1. The last-n value from 'startLastN' if it is specified in config.js
|
||||
// 2. The last-n value from 'channelLastN' if specified in config.js.
|
||||
// 3. -1 as the default value.
|
||||
let lastNSelected = config.startLastN ?? (config.channelLastN ?? -1);
|
||||
|
||||
// Because this is shared, on web appState is always undefined,
|
||||
// meaning that it is never active
|
||||
if (navigator.product === 'ReactNative' && (appState !== 'active' || carMode)) {
|
||||
lastNSelected = 0;
|
||||
} else if (audioOnly) {
|
||||
const { remoteScreenShares, tileViewEnabled } = state['features/video-layout'];
|
||||
const largeVideoParticipantId = state['features/large-video'].participantId;
|
||||
const largeVideoParticipant
|
||||
= largeVideoParticipantId ? getParticipantById(state, largeVideoParticipantId) : undefined;
|
||||
|
||||
// Use tileViewEnabled state from redux here instead of determining if client should be in tile
|
||||
// view since we make an exception only for screenshare when in audio-only mode. If the user unpins
|
||||
// the screenshare, lastN will be set to 0 here. It will be set to 1 if screenshare has been auto pinned.
|
||||
if (!tileViewEnabled && largeVideoParticipant && !largeVideoParticipant.local) {
|
||||
lastNSelected = (remoteScreenShares || []).includes(largeVideoParticipantId ?? '') ? 1 : 0;
|
||||
} else {
|
||||
lastNSelected = 0;
|
||||
}
|
||||
} else if (!filmStripEnabled) {
|
||||
lastNSelected = 1;
|
||||
}
|
||||
|
||||
const { lastN } = state['features/base/lastn'];
|
||||
|
||||
if (lastN !== lastNSelected) {
|
||||
dispatch(setLastN(lastNSelected));
|
||||
}
|
||||
}, 1000); /* Don't send this more often than once a second. */
|
||||
|
||||
|
||||
MiddlewareRegistry.register(store => next => action => {
|
||||
const result = next(action);
|
||||
|
||||
switch (action.type) {
|
||||
case APP_STATE_CHANGED:
|
||||
case CONFERENCE_JOINED:
|
||||
case SET_AUDIO_ONLY:
|
||||
case SET_CAR_MODE:
|
||||
case SET_FILMSTRIP_ENABLED:
|
||||
case VIRTUAL_SCREENSHARE_REMOTE_PARTICIPANTS_UPDATED:
|
||||
_updateLastN(store);
|
||||
break;
|
||||
}
|
||||
|
||||
return result;
|
||||
});
|
||||
22
react/features/base/lastn/reducer.ts
Normal file
22
react/features/base/lastn/reducer.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import ReducerRegistry from '../redux/ReducerRegistry';
|
||||
|
||||
import { SET_LAST_N } from './actionTypes';
|
||||
|
||||
export interface ILastNState {
|
||||
lastN?: number;
|
||||
}
|
||||
|
||||
ReducerRegistry.register<ILastNState>('features/base/lastn', (state = {}, action): ILastNState => {
|
||||
switch (action.type) {
|
||||
case SET_LAST_N: {
|
||||
const { lastN } = action;
|
||||
|
||||
return {
|
||||
...state,
|
||||
lastN
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
return state;
|
||||
});
|
||||
Reference in New Issue
Block a user