2019-07-31 12:47:52 +00:00
|
|
|
// @flow
|
|
|
|
|
2021-09-01 15:25:05 +00:00
|
|
|
import debounce from 'lodash/debounce';
|
|
|
|
|
2019-07-31 12:47:52 +00:00
|
|
|
import { SET_FILMSTRIP_ENABLED } from '../../filmstrip/actionTypes';
|
2019-08-02 17:22:19 +00:00
|
|
|
import { SELECT_LARGE_VIDEO_PARTICIPANT } from '../../large-video/actionTypes';
|
2019-07-31 12:47:52 +00:00
|
|
|
import { APP_STATE_CHANGED } from '../../mobile/background/actionTypes';
|
2022-04-04 18:57:58 +00:00
|
|
|
import {
|
|
|
|
SCREEN_SHARE_REMOTE_PARTICIPANTS_UPDATED,
|
2022-04-29 14:32:16 +00:00
|
|
|
SET_TILE_VIEW,
|
|
|
|
VIRTUAL_SCREENSHARE_REMOTE_PARTICIPANTS_UPDATED
|
2022-04-04 18:57:58 +00:00
|
|
|
} from '../../video-layout/actionTypes';
|
2019-08-02 17:22:19 +00:00
|
|
|
import { SET_AUDIO_ONLY } from '../audio-only/actionTypes';
|
2019-07-31 12:47:52 +00:00
|
|
|
import { CONFERENCE_JOINED } from '../conference/actionTypes';
|
2020-08-03 17:39:17 +00:00
|
|
|
import {
|
|
|
|
PARTICIPANT_JOINED,
|
|
|
|
PARTICIPANT_KICKED,
|
|
|
|
PARTICIPANT_LEFT
|
|
|
|
} from '../participants/actionTypes';
|
|
|
|
import {
|
|
|
|
getParticipantById,
|
|
|
|
getParticipantCount
|
|
|
|
} from '../participants/functions';
|
2019-07-31 12:47:52 +00:00
|
|
|
import { MiddlewareRegistry } from '../redux';
|
2020-11-04 08:32:06 +00:00
|
|
|
import { isLocalVideoTrackDesktop } from '../tracks/functions';
|
2019-07-31 12:47:52 +00:00
|
|
|
|
2021-05-10 20:06:19 +00:00
|
|
|
import { setLastN } from './actions';
|
2020-08-03 17:39:17 +00:00
|
|
|
import { limitLastN } from './functions';
|
2019-08-21 14:50:00 +00:00
|
|
|
import logger from './logger';
|
|
|
|
|
2019-07-31 12:47:52 +00:00
|
|
|
/**
|
2019-08-02 12:23:09 +00:00
|
|
|
* Updates the last N value in the conference based on the current state of the redux store.
|
2019-07-31 12:47:52 +00:00
|
|
|
*
|
2019-08-02 12:23:09 +00:00
|
|
|
* @param {Store} store - The redux store.
|
2019-07-31 12:47:52 +00:00
|
|
|
* @private
|
2019-08-02 12:23:09 +00:00
|
|
|
* @returns {void}
|
2019-07-31 12:47:52 +00:00
|
|
|
*/
|
2021-09-01 15:25:05 +00:00
|
|
|
const _updateLastN = debounce(({ dispatch, getState }) => {
|
2019-08-02 12:23:09 +00:00
|
|
|
const state = getState();
|
|
|
|
const { conference } = state['features/base/conference'];
|
|
|
|
|
|
|
|
if (!conference) {
|
|
|
|
logger.debug('There is no active conference, not updating last N');
|
|
|
|
|
|
|
|
return;
|
2019-07-31 12:47:52 +00:00
|
|
|
}
|
|
|
|
|
2021-09-01 15:25:05 +00:00
|
|
|
const { enabled: audioOnly } = state['features/base/audio-only'];
|
|
|
|
const { appState } = state['features/background'] || {};
|
|
|
|
const { enabled: filmStripEnabled } = state['features/filmstrip'];
|
|
|
|
const config = state['features/base/config'];
|
2022-04-25 15:07:13 +00:00
|
|
|
const { lastNLimits } = state['features/base/lastn'];
|
2021-09-01 15:25:05 +00:00
|
|
|
const participantCount = getParticipantCount(state);
|
|
|
|
|
2022-04-25 15:07:13 +00:00
|
|
|
// 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);
|
2019-07-31 12:47:52 +00:00
|
|
|
|
2021-04-28 23:00:20 +00:00
|
|
|
// Apply last N limit based on the # of participants and config settings.
|
2020-08-03 17:39:17 +00:00
|
|
|
const limitedLastN = limitLastN(participantCount, lastNLimits);
|
|
|
|
|
|
|
|
if (limitedLastN !== undefined) {
|
2021-04-28 23:00:20 +00:00
|
|
|
lastNSelected = lastNSelected === -1 ? limitedLastN : Math.min(limitedLastN, lastNSelected);
|
2020-08-03 17:39:17 +00:00
|
|
|
}
|
|
|
|
|
2020-06-04 14:09:13 +00:00
|
|
|
if (typeof appState !== 'undefined' && appState !== 'active') {
|
2021-04-28 23:00:20 +00:00
|
|
|
lastNSelected = isLocalVideoTrackDesktop(state) ? 1 : 0;
|
2019-08-02 17:22:19 +00:00
|
|
|
} else if (audioOnly) {
|
2021-01-28 12:36:01 +00:00
|
|
|
const { remoteScreenShares, tileViewEnabled } = state['features/video-layout'];
|
2019-08-02 17:22:19 +00:00
|
|
|
const largeVideoParticipantId = state['features/large-video'].participantId;
|
|
|
|
const largeVideoParticipant
|
|
|
|
= largeVideoParticipantId ? getParticipantById(state, largeVideoParticipantId) : undefined;
|
|
|
|
|
2020-10-23 20:41:13 +00:00
|
|
|
// 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.
|
2019-08-02 17:22:19 +00:00
|
|
|
if (!tileViewEnabled && largeVideoParticipant && !largeVideoParticipant.local) {
|
2021-04-28 23:00:20 +00:00
|
|
|
lastNSelected = (remoteScreenShares || []).includes(largeVideoParticipantId) ? 1 : 0;
|
2019-08-02 17:22:19 +00:00
|
|
|
} else {
|
2021-04-28 23:00:20 +00:00
|
|
|
lastNSelected = 0;
|
2019-08-02 17:22:19 +00:00
|
|
|
}
|
2019-08-02 12:23:09 +00:00
|
|
|
} else if (!filmStripEnabled) {
|
2021-04-28 23:00:20 +00:00
|
|
|
lastNSelected = 1;
|
2019-07-31 12:47:52 +00:00
|
|
|
}
|
|
|
|
|
2021-05-10 20:06:19 +00:00
|
|
|
dispatch(setLastN(lastNSelected));
|
2021-09-01 15:25:05 +00:00
|
|
|
}, 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 PARTICIPANT_JOINED:
|
|
|
|
case PARTICIPANT_KICKED:
|
|
|
|
case PARTICIPANT_LEFT:
|
|
|
|
case SCREEN_SHARE_REMOTE_PARTICIPANTS_UPDATED:
|
|
|
|
case SELECT_LARGE_VIDEO_PARTICIPANT:
|
|
|
|
case SET_AUDIO_ONLY:
|
|
|
|
case SET_FILMSTRIP_ENABLED:
|
|
|
|
case SET_TILE_VIEW:
|
2022-04-29 14:32:16 +00:00
|
|
|
case VIRTUAL_SCREENSHARE_REMOTE_PARTICIPANTS_UPDATED:
|
2021-09-01 15:25:05 +00:00
|
|
|
_updateLastN(store);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
});
|