2017-10-04 22:36:09 +00:00
|
|
|
// @flow
|
|
|
|
|
2019-03-19 15:42:25 +00:00
|
|
|
import type { Dispatch } from 'redux';
|
|
|
|
|
2018-07-20 18:19:26 +00:00
|
|
|
import { MEDIA_TYPE } from '../base/media';
|
2021-07-09 12:36:19 +00:00
|
|
|
import {
|
|
|
|
getDominantSpeakerParticipant,
|
|
|
|
getLocalParticipant,
|
|
|
|
getPinnedParticipant,
|
|
|
|
getRemoteParticipants
|
|
|
|
} from '../base/participants';
|
2022-04-21 06:15:34 +00:00
|
|
|
import { isStageFilmstripAvailable } from '../filmstrip/functions';
|
2016-10-05 14:36:59 +00:00
|
|
|
|
2017-08-09 19:40:03 +00:00
|
|
|
import {
|
|
|
|
SELECT_LARGE_VIDEO_PARTICIPANT,
|
2022-08-16 11:56:47 +00:00
|
|
|
SET_LARGE_VIDEO_DIMENSIONS,
|
2017-08-09 19:40:03 +00:00
|
|
|
UPDATE_KNOWN_LARGE_VIDEO_RESOLUTION
|
|
|
|
} from './actionTypes';
|
2016-10-05 14:36:59 +00:00
|
|
|
|
|
|
|
/**
|
2020-09-14 20:01:46 +00:00
|
|
|
* Action to select the participant to be displayed in LargeVideo based on the
|
2020-09-18 15:53:27 +00:00
|
|
|
* participant id provided. If a participant id is not provided, the LargeVideo
|
2020-09-14 20:01:46 +00:00
|
|
|
* participant will be selected based on a variety of factors: If there is a
|
|
|
|
* dominant or pinned speaker, or if there are remote tracks, etc.
|
2016-10-05 14:36:59 +00:00
|
|
|
*
|
2020-09-14 20:01:46 +00:00
|
|
|
* @param {string} participant - The participant id of the user that needs to be
|
|
|
|
* displayed on the large video.
|
2016-10-05 14:36:59 +00:00
|
|
|
* @returns {Function}
|
|
|
|
*/
|
2020-09-14 20:01:46 +00:00
|
|
|
export function selectParticipantInLargeVideo(participant: ?string) {
|
2019-03-19 15:42:25 +00:00
|
|
|
return (dispatch: Dispatch<any>, getState: Function) => {
|
2016-10-05 14:36:59 +00:00
|
|
|
const state = getState();
|
2021-12-01 14:00:38 +00:00
|
|
|
|
2022-04-21 06:15:34 +00:00
|
|
|
if (isStageFilmstripAvailable(state, 2)) {
|
2022-04-12 13:19:10 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-12-01 14:00:38 +00:00
|
|
|
// Keep Etherpad open.
|
|
|
|
if (state['features/etherpad'].editing) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-09-14 20:01:46 +00:00
|
|
|
const participantId = participant ?? _electParticipantInLargeVideo(state);
|
2017-01-17 14:44:50 +00:00
|
|
|
const largeVideo = state['features/large-video'];
|
2021-01-28 12:36:01 +00:00
|
|
|
const remoteScreenShares = state['features/video-layout'].remoteScreenShares;
|
2020-11-19 21:42:49 +00:00
|
|
|
let latestScreenshareParticipantId;
|
2016-10-05 14:36:59 +00:00
|
|
|
|
2021-01-28 12:36:01 +00:00
|
|
|
if (remoteScreenShares && remoteScreenShares.length) {
|
|
|
|
latestScreenshareParticipantId = remoteScreenShares[remoteScreenShares.length - 1];
|
2020-11-19 21:42:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// When trying to auto pin screenshare, always select the endpoint even though it happens to be
|
|
|
|
// the large video participant in redux (for the reasons listed above in the large video selection
|
|
|
|
// logic above). The auto pin screenshare logic kicks in after the track is added
|
|
|
|
// (which updates the large video participant and selects all endpoints because of the auto tile
|
|
|
|
// view mode). If the screenshare endpoint is not among the forwarded endpoints from the bridge,
|
|
|
|
// it needs to be selected again at this point.
|
|
|
|
if (participantId !== largeVideo.participantId || participantId === latestScreenshareParticipantId) {
|
2016-10-05 14:36:59 +00:00
|
|
|
dispatch({
|
2017-01-11 18:14:00 +00:00
|
|
|
type: SELECT_LARGE_VIDEO_PARTICIPANT,
|
2016-10-05 14:36:59 +00:00
|
|
|
participantId
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2017-08-09 19:40:03 +00:00
|
|
|
/**
|
|
|
|
* Updates the currently seen resolution of the video displayed on large video.
|
|
|
|
*
|
|
|
|
* @param {number} resolution - The current resolution (height) of the video.
|
|
|
|
* @returns {{
|
|
|
|
* type: UPDATE_KNOWN_LARGE_VIDEO_RESOLUTION,
|
|
|
|
* resolution: number
|
|
|
|
* }}
|
|
|
|
*/
|
2017-10-04 22:36:09 +00:00
|
|
|
export function updateKnownLargeVideoResolution(resolution: number) {
|
2017-08-09 19:40:03 +00:00
|
|
|
return {
|
|
|
|
type: UPDATE_KNOWN_LARGE_VIDEO_RESOLUTION,
|
|
|
|
resolution
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-08-16 11:56:47 +00:00
|
|
|
/**
|
|
|
|
* Sets the dimenstions of the large video in redux.
|
|
|
|
*
|
|
|
|
* @param {number} height - The height of the large video.
|
|
|
|
* @param {number} width - The width of the large video.
|
|
|
|
* @returns {{
|
|
|
|
* type: SET_LARGE_VIDEO_DIMENSIONS,
|
|
|
|
* height: number,
|
|
|
|
* width: number
|
|
|
|
* }}
|
|
|
|
*/
|
|
|
|
export function setLargeVideoDimensions(height, width) {
|
|
|
|
return {
|
|
|
|
type: SET_LARGE_VIDEO_DIMENSIONS,
|
|
|
|
height,
|
|
|
|
width
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2016-10-05 14:36:59 +00:00
|
|
|
/**
|
2017-10-06 19:43:58 +00:00
|
|
|
* Returns the most recent existing remote video track.
|
2016-10-05 14:36:59 +00:00
|
|
|
*
|
|
|
|
* @param {Track[]} tracks - All current tracks.
|
|
|
|
* @private
|
|
|
|
* @returns {(Track|undefined)}
|
|
|
|
*/
|
2017-10-06 19:43:58 +00:00
|
|
|
function _electLastVisibleRemoteVideo(tracks) {
|
2016-10-05 14:36:59 +00:00
|
|
|
// First we try to get most recent remote video track.
|
2016-11-04 18:28:47 +00:00
|
|
|
for (let i = tracks.length - 1; i >= 0; --i) {
|
|
|
|
const track = tracks[i];
|
|
|
|
|
|
|
|
if (!track.local && track.mediaType === MEDIA_TYPE.VIDEO) {
|
|
|
|
return track;
|
2016-10-05 14:36:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-11-08 12:25:02 +00:00
|
|
|
* Returns the identifier of the participant who is to be on the stage and
|
2017-10-01 06:35:19 +00:00
|
|
|
* should be displayed in {@code LargeVideo}.
|
2016-10-05 14:36:59 +00:00
|
|
|
*
|
2016-11-04 18:28:47 +00:00
|
|
|
* @param {Object} state - The Redux state from which the participant to be
|
2017-10-01 06:35:19 +00:00
|
|
|
* displayed in {@code LargeVideo} is to be elected.
|
2016-10-05 14:36:59 +00:00
|
|
|
* @private
|
|
|
|
* @returns {(string|undefined)}
|
|
|
|
*/
|
2016-11-04 18:28:47 +00:00
|
|
|
function _electParticipantInLargeVideo(state) {
|
2022-08-25 23:47:36 +00:00
|
|
|
// If a participant is pinned, they will be shown in the LargeVideo (regardless of whether they are local or
|
|
|
|
// remote) when the filmstrip on stage is disabled.
|
|
|
|
let participant = getPinnedParticipant(state);
|
2022-03-31 19:08:08 +00:00
|
|
|
|
2022-08-25 23:47:36 +00:00
|
|
|
if (participant) {
|
|
|
|
return participant.id;
|
2022-03-31 19:08:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Pick the most recent remote screenshare that was added to the conference.
|
2022-03-29 08:45:09 +00:00
|
|
|
const remoteScreenShares = state['features/video-layout'].remoteScreenShares;
|
|
|
|
|
|
|
|
if (remoteScreenShares?.length) {
|
|
|
|
return remoteScreenShares[remoteScreenShares.length - 1];
|
|
|
|
}
|
|
|
|
|
2022-03-31 19:08:08 +00:00
|
|
|
// Next, pick the dominant speaker (other than self).
|
2021-07-09 12:36:19 +00:00
|
|
|
participant = getDominantSpeakerParticipant(state);
|
|
|
|
if (participant && !participant.local) {
|
2021-03-26 13:14:03 +00:00
|
|
|
return participant.id;
|
|
|
|
}
|
|
|
|
|
2021-07-09 12:36:19 +00:00
|
|
|
// In case this is the local participant.
|
|
|
|
participant = undefined;
|
|
|
|
|
2022-03-31 19:08:08 +00:00
|
|
|
// Next, pick the most recent participant with video.
|
2021-03-26 13:14:03 +00:00
|
|
|
const tracks = state['features/base/tracks'];
|
|
|
|
const videoTrack = _electLastVisibleRemoteVideo(tracks);
|
|
|
|
|
|
|
|
if (videoTrack) {
|
|
|
|
return videoTrack.participantId;
|
|
|
|
}
|
|
|
|
|
2022-03-31 19:08:08 +00:00
|
|
|
// Last, select the participant that joined last (other than poltergist or other bot type participants).
|
2021-07-09 12:36:19 +00:00
|
|
|
const participants = [ ...getRemoteParticipants(state).values() ];
|
|
|
|
|
2021-03-26 13:14:03 +00:00
|
|
|
for (let i = participants.length; i > 0 && !participant; i--) {
|
|
|
|
const p = participants[i - 1];
|
|
|
|
|
|
|
|
!p.botType && (participant = p);
|
|
|
|
}
|
|
|
|
if (participant) {
|
|
|
|
return participant.id;
|
2016-10-05 14:36:59 +00:00
|
|
|
}
|
|
|
|
|
2021-07-09 12:36:19 +00:00
|
|
|
return getLocalParticipant(state)?.id;
|
2016-10-05 14:36:59 +00:00
|
|
|
}
|