2019-07-31 12:47:52 +00:00
|
|
|
// @flow
|
|
|
|
|
|
|
|
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';
|
2019-08-02 17:22:19 +00:00
|
|
|
import { SCREEN_SHARE_PARTICIPANTS_UPDATED, SET_TILE_VIEW } from '../../video-layout/actionTypes';
|
|
|
|
import { SET_AUDIO_ONLY } from '../audio-only/actionTypes';
|
2019-07-31 12:47:52 +00:00
|
|
|
import { CONFERENCE_JOINED } from '../conference/actionTypes';
|
2019-08-02 17:22:19 +00:00
|
|
|
import { getParticipantById } from '../participants/functions';
|
2019-07-31 12:47:52 +00:00
|
|
|
import { MiddlewareRegistry } from '../redux';
|
|
|
|
|
2019-08-21 14:50:00 +00:00
|
|
|
import logger from './logger';
|
|
|
|
|
2019-07-31 12:47:52 +00:00
|
|
|
declare var APP: Object;
|
|
|
|
|
|
|
|
|
|
|
|
MiddlewareRegistry.register(store => next => action => {
|
2019-08-02 12:23:09 +00:00
|
|
|
const result = next(action);
|
|
|
|
|
2019-07-31 12:47:52 +00:00
|
|
|
switch (action.type) {
|
|
|
|
case APP_STATE_CHANGED:
|
|
|
|
case CONFERENCE_JOINED:
|
2019-08-02 17:22:19 +00:00
|
|
|
case SCREEN_SHARE_PARTICIPANTS_UPDATED:
|
|
|
|
case SELECT_LARGE_VIDEO_PARTICIPANT:
|
2019-07-31 12:47:52 +00:00
|
|
|
case SET_AUDIO_ONLY:
|
|
|
|
case SET_FILMSTRIP_ENABLED:
|
2019-08-02 17:22:19 +00:00
|
|
|
case SET_TILE_VIEW:
|
2019-08-02 12:23:09 +00:00
|
|
|
_updateLastN(store);
|
|
|
|
break;
|
2019-07-31 12:47:52 +00:00
|
|
|
}
|
|
|
|
|
2019-08-02 12:23:09 +00:00
|
|
|
return result;
|
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
|
|
|
*/
|
2019-08-02 12:23:09 +00:00
|
|
|
function _updateLastN({ getState }) {
|
|
|
|
const state = getState();
|
|
|
|
const { conference } = state['features/base/conference'];
|
|
|
|
const { enabled: audioOnly } = state['features/base/audio-only'];
|
2020-06-04 14:09:13 +00:00
|
|
|
const { appState } = state['features/background'] || {};
|
2019-08-02 12:23:09 +00:00
|
|
|
const { enabled: filmStripEnabled } = state['features/filmstrip'];
|
|
|
|
const config = state['features/base/config'];
|
|
|
|
|
|
|
|
if (!conference) {
|
|
|
|
logger.debug('There is no active conference, not updating last N');
|
|
|
|
|
|
|
|
return;
|
2019-07-31 12:47:52 +00:00
|
|
|
}
|
|
|
|
|
2019-08-02 12:23:09 +00:00
|
|
|
const defaultLastN = typeof config.channelLastN === 'undefined' ? -1 : config.channelLastN;
|
|
|
|
let lastN = defaultLastN;
|
2019-07-31 12:47:52 +00:00
|
|
|
|
2020-06-04 14:09:13 +00:00
|
|
|
if (typeof appState !== 'undefined' && appState !== 'active') {
|
2019-08-02 12:23:09 +00:00
|
|
|
lastN = 0;
|
2019-08-02 17:22:19 +00:00
|
|
|
} else if (audioOnly) {
|
|
|
|
const { screenShares, tileViewEnabled } = state['features/video-layout'];
|
|
|
|
const largeVideoParticipantId = state['features/large-video'].participantId;
|
|
|
|
const largeVideoParticipant
|
|
|
|
= largeVideoParticipantId ? getParticipantById(state, largeVideoParticipantId) : undefined;
|
|
|
|
|
|
|
|
if (!tileViewEnabled && largeVideoParticipant && !largeVideoParticipant.local) {
|
|
|
|
lastN = (screenShares || []).includes(largeVideoParticipantId) ? 1 : 0;
|
|
|
|
} else {
|
|
|
|
lastN = 0;
|
|
|
|
}
|
2019-08-02 12:23:09 +00:00
|
|
|
} else if (!filmStripEnabled) {
|
|
|
|
lastN = 1;
|
2019-07-31 12:47:52 +00:00
|
|
|
}
|
|
|
|
|
2019-08-02 17:22:19 +00:00
|
|
|
if (conference.getLastN() === lastN) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-08-02 12:23:09 +00:00
|
|
|
logger.info(`Setting last N to: ${lastN}`);
|
2019-07-31 12:47:52 +00:00
|
|
|
|
2019-08-02 12:23:09 +00:00
|
|
|
try {
|
|
|
|
conference.setLastN(lastN);
|
|
|
|
} catch (err) {
|
|
|
|
logger.error(`Failed to set lastN: ${err}`);
|
2019-07-31 12:47:52 +00:00
|
|
|
}
|
|
|
|
}
|