2020-12-14 15:38:29 -06:00
|
|
|
/* global APP */
|
2020-05-20 12:57:03 +02:00
|
|
|
|
2021-11-10 11:11:29 +01:00
|
|
|
import Logger from '@jitsi/logger';
|
2015-07-10 11:57:20 +02:00
|
|
|
|
2023-04-03 13:49:19 +03:00
|
|
|
import { MEDIA_TYPE, VIDEO_TYPE } from '../../../react/features/base/media/constants';
|
2017-08-10 13:51:35 -07:00
|
|
|
import {
|
2022-09-27 10:10:28 +03:00
|
|
|
getParticipantById,
|
2022-10-06 14:12:57 +03:00
|
|
|
getPinnedParticipant,
|
|
|
|
|
isScreenShareParticipantById
|
2023-04-03 13:49:19 +03:00
|
|
|
} from '../../../react/features/base/participants/functions';
|
2022-04-04 14:57:58 -04:00
|
|
|
import {
|
|
|
|
|
getTrackByMediaTypeAndParticipant,
|
2022-11-08 14:15:49 -05:00
|
|
|
getVideoTrackByParticipant
|
2023-04-03 13:49:19 +03:00
|
|
|
} from '../../../react/features/base/tracks/functions.any';
|
2018-05-22 10:13:51 -07:00
|
|
|
|
2017-10-12 18:02:29 -05:00
|
|
|
import LargeVideoManager from './LargeVideoManager';
|
|
|
|
|
import { VIDEO_CONTAINER_TYPE } from './VideoContainer';
|
2018-05-22 10:13:51 -07:00
|
|
|
|
2020-05-20 12:57:03 +02:00
|
|
|
const logger = Logger.getLogger(__filename);
|
2017-10-12 18:02:29 -05:00
|
|
|
let largeVideo;
|
2015-01-27 14:03:26 +02:00
|
|
|
|
2017-10-12 18:02:29 -05:00
|
|
|
const VideoLayout = {
|
2017-05-10 17:19:35 -07:00
|
|
|
/**
|
2021-01-21 14:46:47 -06:00
|
|
|
* Handler for local flip X changed event.
|
2017-05-10 17:19:35 -07:00
|
|
|
*/
|
2023-08-18 17:37:07 +03:00
|
|
|
onLocalFlipXChanged(localFlipX) {
|
2021-01-21 14:46:47 -06:00
|
|
|
if (largeVideo) {
|
|
|
|
|
largeVideo.onLocalFlipXChange(localFlipX);
|
|
|
|
|
}
|
2017-05-10 17:19:35 -07:00
|
|
|
},
|
|
|
|
|
|
2017-02-15 15:39:16 -06:00
|
|
|
/**
|
2019-01-01 13:19:34 -08:00
|
|
|
* Cleans up state of this singleton {@code VideoLayout}.
|
2017-02-15 15:39:16 -06:00
|
|
|
*
|
|
|
|
|
* @returns {void}
|
|
|
|
|
*/
|
2019-01-01 13:19:34 -08:00
|
|
|
reset() {
|
|
|
|
|
this._resetLargeVideo();
|
2015-12-14 14:26:50 +02:00
|
|
|
},
|
2015-01-19 11:20:00 +02:00
|
|
|
|
2017-10-12 18:02:29 -05:00
|
|
|
initLargeVideo() {
|
2019-01-01 13:19:34 -08:00
|
|
|
this._resetLargeVideo();
|
2017-05-10 17:19:35 -07:00
|
|
|
|
2021-01-21 14:46:47 -06:00
|
|
|
largeVideo = new LargeVideoManager();
|
|
|
|
|
|
|
|
|
|
const { store } = APP;
|
|
|
|
|
const { localFlipX } = store.getState()['features/base/settings'];
|
|
|
|
|
|
|
|
|
|
if (typeof localFlipX === 'boolean') {
|
2016-05-06 20:50:37 -05:00
|
|
|
largeVideo.onLocalFlipXChange(localFlipX);
|
|
|
|
|
}
|
2016-09-08 13:16:23 -05:00
|
|
|
largeVideo.updateContainerSize();
|
2015-12-25 18:55:45 +02:00
|
|
|
},
|
|
|
|
|
|
2016-09-28 16:31:40 -05:00
|
|
|
/**
|
|
|
|
|
* Sets the audio level of the video elements associated to the given id.
|
|
|
|
|
*
|
|
|
|
|
* @param id the video identifier in the form it comes from the library
|
|
|
|
|
* @param lvl the new audio level to update to
|
|
|
|
|
*/
|
2015-12-25 18:55:45 +02:00
|
|
|
setAudioLevel(id, lvl) {
|
2017-10-12 18:02:29 -05:00
|
|
|
if (largeVideo && id === largeVideo.id) {
|
2016-09-28 16:31:40 -05:00
|
|
|
largeVideo.updateLargeVideoAudioLevel(lvl);
|
2017-10-12 18:02:29 -05:00
|
|
|
}
|
2015-12-25 18:55:45 +02:00
|
|
|
},
|
|
|
|
|
|
2017-07-19 12:08:51 +02:00
|
|
|
/**
|
|
|
|
|
* FIXME get rid of this method once muted indicator are reactified (by
|
|
|
|
|
* making sure that user with no tracks is displayed as muted )
|
|
|
|
|
*
|
|
|
|
|
* If participant has no tracks will make the UI display muted status.
|
|
|
|
|
* @param {string} participantId
|
|
|
|
|
*/
|
2020-11-09 14:59:13 -06:00
|
|
|
updateVideoMutedForNoTracks(participantId) {
|
2017-07-19 12:08:51 +02:00
|
|
|
const participant = APP.conference.getParticipantById(participantId);
|
|
|
|
|
|
2020-11-09 14:59:13 -06:00
|
|
|
if (participant && !participant.getTracksByMediaType('video').length) {
|
2021-01-21 14:46:47 -06:00
|
|
|
VideoLayout._updateLargeVideoIfDisplayed(participantId, true);
|
2017-07-19 12:08:51 +02:00
|
|
|
}
|
2016-02-23 16:47:55 -06:00
|
|
|
},
|
2014-11-21 15:29:05 +02:00
|
|
|
|
2015-11-16 17:42:21 -06:00
|
|
|
/**
|
|
|
|
|
* Return the type of the remote video.
|
2015-12-14 14:26:50 +02:00
|
|
|
* @param id the id for the remote video
|
2016-03-15 13:36:17 -05:00
|
|
|
* @returns {String} the video type video or screen.
|
2015-11-16 17:42:21 -06:00
|
|
|
*/
|
2017-10-12 18:02:29 -05:00
|
|
|
getRemoteVideoType(id) {
|
2020-04-14 17:41:30 -05:00
|
|
|
const state = APP.store.getState();
|
|
|
|
|
const participant = getParticipantById(state, id);
|
2022-10-06 14:12:57 +03:00
|
|
|
const isScreenShare = isScreenShareParticipantById(state, id);
|
2020-04-14 17:41:30 -05:00
|
|
|
|
2022-10-06 14:12:57 +03:00
|
|
|
if (participant?.fakeParticipant && !isScreenShare) {
|
2021-04-16 12:43:34 +03:00
|
|
|
return VIDEO_TYPE.CAMERA;
|
2020-04-14 17:41:30 -05:00
|
|
|
}
|
2017-10-12 18:02:29 -05:00
|
|
|
|
2022-11-08 14:15:49 -05:00
|
|
|
if (isScreenShare) {
|
2022-04-04 14:57:58 -04:00
|
|
|
return VIDEO_TYPE.DESKTOP;
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-14 17:41:30 -05:00
|
|
|
const videoTrack = getTrackByMediaTypeAndParticipant(state['features/base/tracks'], MEDIA_TYPE.VIDEO, id);
|
2017-10-12 18:02:29 -05:00
|
|
|
|
2020-04-14 17:41:30 -05:00
|
|
|
return videoTrack?.videoType;
|
2015-12-14 14:26:50 +02:00
|
|
|
},
|
2015-11-16 17:42:21 -06:00
|
|
|
|
2017-10-12 18:02:29 -05:00
|
|
|
getPinnedId() {
|
2017-08-10 13:51:35 -07:00
|
|
|
const { id } = getPinnedParticipant(APP.store.getState()) || {};
|
|
|
|
|
|
|
|
|
|
return id || null;
|
|
|
|
|
},
|
|
|
|
|
|
2014-08-22 17:37:11 +02:00
|
|
|
/**
|
|
|
|
|
* On last N change event.
|
|
|
|
|
*
|
2017-03-21 16:51:49 -05:00
|
|
|
* @param endpointsLeavingLastN the list currently leaving last N
|
|
|
|
|
* endpoints
|
2014-08-22 17:37:11 +02:00
|
|
|
* @param endpointsEnteringLastN the list currently entering last N
|
|
|
|
|
* endpoints
|
|
|
|
|
*/
|
2017-10-12 18:02:29 -05:00
|
|
|
onLastNEndpointsChanged(endpointsLeavingLastN, endpointsEnteringLastN) {
|
2017-03-21 16:51:49 -05:00
|
|
|
if (endpointsLeavingLastN) {
|
2021-01-21 14:46:47 -06:00
|
|
|
endpointsLeavingLastN.forEach(this._updateLargeVideoIfDisplayed, this);
|
2017-03-21 16:51:49 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (endpointsEnteringLastN) {
|
2021-01-21 14:46:47 -06:00
|
|
|
endpointsEnteringLastN.forEach(this._updateLargeVideoIfDisplayed, this);
|
2017-03-21 16:51:49 -05:00
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
2015-06-23 11:00:46 +03:00
|
|
|
/**
|
2015-11-13 11:04:49 -06:00
|
|
|
* Resizes the video area.
|
2016-03-15 16:03:38 -05:00
|
|
|
*/
|
2020-02-10 15:27:43 +00:00
|
|
|
resizeVideoArea() {
|
2015-12-25 18:55:45 +02:00
|
|
|
if (largeVideo) {
|
2016-09-08 13:16:23 -05:00
|
|
|
largeVideo.updateContainerSize();
|
2020-02-10 15:27:43 +00:00
|
|
|
largeVideo.resize(false);
|
2015-12-25 18:55:45 +02:00
|
|
|
}
|
2015-12-14 14:26:50 +02:00
|
|
|
},
|
2015-08-06 18:34:40 -05:00
|
|
|
|
2017-10-12 18:02:29 -05:00
|
|
|
isLargeVideoVisible() {
|
2016-03-18 15:00:55 -05:00
|
|
|
return this.isLargeContainerTypeVisible(VIDEO_CONTAINER_TYPE);
|
2015-12-25 18:55:45 +02:00
|
|
|
},
|
|
|
|
|
|
2016-03-17 22:19:09 -05:00
|
|
|
/**
|
|
|
|
|
* @return {LargeContainer} the currently displayed container on large
|
|
|
|
|
* video.
|
|
|
|
|
*/
|
2017-10-12 18:02:29 -05:00
|
|
|
getCurrentlyOnLargeContainer() {
|
2017-07-10 11:02:22 +02:00
|
|
|
return largeVideo.getCurrentContainer();
|
2016-03-17 22:19:09 -05:00
|
|
|
},
|
|
|
|
|
|
2017-10-12 18:02:29 -05:00
|
|
|
isCurrentlyOnLarge(id) {
|
2015-12-25 18:55:45 +02:00
|
|
|
return largeVideo && largeVideo.id === id;
|
|
|
|
|
},
|
|
|
|
|
|
2022-08-05 12:11:09 +03:00
|
|
|
updateLargeVideo(id, forceUpdate, forceStreamToReattach = false) {
|
2015-12-25 18:55:45 +02:00
|
|
|
if (!largeVideo) {
|
2024-01-24 17:08:01 -06:00
|
|
|
logger.debug(`Ignoring large video update with user id ${id}: large video not initialized yet!`);
|
|
|
|
|
|
2015-12-25 18:55:45 +02:00
|
|
|
return;
|
|
|
|
|
}
|
2017-07-10 12:06:48 +02:00
|
|
|
const currentContainer = largeVideo.getCurrentContainer();
|
|
|
|
|
const currentContainerType = largeVideo.getCurrentContainerType();
|
|
|
|
|
const isOnLarge = this.isCurrentlyOnLarge(id);
|
2020-04-14 17:41:30 -05:00
|
|
|
const state = APP.store.getState();
|
2022-04-04 14:57:58 -04:00
|
|
|
const participant = getParticipantById(state, id);
|
2022-11-08 14:15:49 -05:00
|
|
|
const videoTrack = getVideoTrackByParticipant(state, participant);
|
2020-04-14 17:41:30 -05:00
|
|
|
const videoStream = videoTrack?.jitsiTrack;
|
2017-07-10 12:06:48 +02:00
|
|
|
|
2022-08-05 12:11:09 +03:00
|
|
|
if (videoStream && forceStreamToReattach) {
|
|
|
|
|
videoStream.forceStreamToReattach = forceStreamToReattach;
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-10 12:06:48 +02:00
|
|
|
if (isOnLarge && !forceUpdate
|
|
|
|
|
&& LargeVideoManager.isVideoContainer(currentContainerType)
|
2020-04-14 17:41:30 -05:00
|
|
|
&& videoStream) {
|
2017-07-10 12:06:48 +02:00
|
|
|
const currentStreamId = currentContainer.getStreamID();
|
2020-04-14 17:41:30 -05:00
|
|
|
const newStreamId = videoStream?.getId() || null;
|
2017-07-10 12:06:48 +02:00
|
|
|
|
|
|
|
|
// FIXME it might be possible to get rid of 'forceUpdate' argument
|
|
|
|
|
if (currentStreamId !== newStreamId) {
|
|
|
|
|
logger.debug('Enforcing large video update for stream change');
|
2017-10-12 18:02:29 -05:00
|
|
|
forceUpdate = true; // eslint-disable-line no-param-reassign
|
2017-07-10 12:06:48 +02:00
|
|
|
}
|
|
|
|
|
}
|
2015-12-25 18:55:45 +02:00
|
|
|
|
2020-04-14 17:41:30 -05:00
|
|
|
if (!isOnLarge || forceUpdate) {
|
2017-10-12 18:02:29 -05:00
|
|
|
const videoType = this.getRemoteVideoType(id);
|
|
|
|
|
|
2016-01-14 10:28:24 -06:00
|
|
|
largeVideo.updateLargeVideo(
|
2016-01-29 13:31:58 -06:00
|
|
|
id,
|
2020-04-14 17:41:30 -05:00
|
|
|
videoStream,
|
2018-07-02 08:39:28 -07:00
|
|
|
videoType || VIDEO_TYPE.CAMERA
|
2020-04-14 17:41:30 -05:00
|
|
|
).catch(() => {
|
|
|
|
|
// do nothing
|
2016-01-22 17:08:58 +02:00
|
|
|
});
|
2015-12-25 18:55:45 +02:00
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
2017-10-12 18:02:29 -05:00
|
|
|
addLargeVideoContainer(type, container) {
|
2015-12-25 18:55:45 +02:00
|
|
|
largeVideo && largeVideo.addContainer(type, container);
|
|
|
|
|
},
|
|
|
|
|
|
2017-10-12 18:02:29 -05:00
|
|
|
removeLargeVideoContainer(type) {
|
2015-12-25 18:55:45 +02:00
|
|
|
largeVideo && largeVideo.removeContainer(type);
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @returns Promise
|
|
|
|
|
*/
|
2017-10-12 18:02:29 -05:00
|
|
|
showLargeVideoContainer(type, show) {
|
2015-12-25 18:55:45 +02:00
|
|
|
if (!largeVideo) {
|
|
|
|
|
return Promise.reject();
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-12 18:02:29 -05:00
|
|
|
const isVisible = this.isLargeContainerTypeVisible(type);
|
|
|
|
|
|
2015-12-25 18:55:45 +02:00
|
|
|
if (isVisible === show) {
|
|
|
|
|
return Promise.resolve();
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-22 16:12:25 -05:00
|
|
|
let containerTypeToShow = type;
|
2017-10-12 18:02:29 -05:00
|
|
|
|
2016-03-22 16:12:25 -05:00
|
|
|
// if we are hiding a container and there is focusedVideo
|
|
|
|
|
// (pinned remote video) use its video type,
|
|
|
|
|
// if not then use default type - large video
|
2017-10-12 18:02:29 -05:00
|
|
|
|
2016-03-22 16:12:25 -05:00
|
|
|
if (!show) {
|
2017-08-10 13:51:35 -07:00
|
|
|
const pinnedId = this.getPinnedId();
|
|
|
|
|
|
2017-10-12 18:02:29 -05:00
|
|
|
if (pinnedId) {
|
2016-03-24 13:16:42 -05:00
|
|
|
containerTypeToShow = this.getRemoteVideoType(pinnedId);
|
2017-10-12 18:02:29 -05:00
|
|
|
} else {
|
2016-03-22 16:12:25 -05:00
|
|
|
containerTypeToShow = VIDEO_CONTAINER_TYPE;
|
2017-10-12 18:02:29 -05:00
|
|
|
}
|
2016-03-22 16:12:25 -05:00
|
|
|
}
|
|
|
|
|
|
2021-01-21 14:46:47 -06:00
|
|
|
return largeVideo.showContainer(containerTypeToShow);
|
2015-12-25 18:55:45 +02:00
|
|
|
},
|
|
|
|
|
|
2017-10-12 18:02:29 -05:00
|
|
|
isLargeContainerTypeVisible(type) {
|
2015-12-25 18:55:45 +02:00
|
|
|
return largeVideo && largeVideo.state === type;
|
2016-01-14 13:30:27 -06:00
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns the id of the current video shown on large.
|
2016-03-18 15:00:55 -05:00
|
|
|
* Currently used by tests (torture).
|
2016-01-14 13:30:27 -06:00
|
|
|
*/
|
2017-10-12 18:02:29 -05:00
|
|
|
getLargeVideoID() {
|
2018-04-12 14:23:03 -07:00
|
|
|
return largeVideo && largeVideo.id;
|
2016-03-18 15:00:55 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns the the current video shown on large.
|
|
|
|
|
* Currently used by tests (torture).
|
|
|
|
|
*/
|
2017-10-12 18:02:29 -05:00
|
|
|
getLargeVideo() {
|
2016-03-18 15:00:55 -05:00
|
|
|
return largeVideo;
|
2016-03-15 15:26:22 -05:00
|
|
|
},
|
|
|
|
|
|
2017-01-20 14:26:25 -06:00
|
|
|
/**
|
|
|
|
|
* Returns the wrapper jquery selector for the largeVideo
|
|
|
|
|
* @returns {JQuerySelector} the wrapper jquery selector for the largeVideo
|
|
|
|
|
*/
|
|
|
|
|
getLargeVideoWrapper() {
|
|
|
|
|
return this.getCurrentlyOnLargeContainer().$wrapper;
|
2017-05-18 17:40:14 -07:00
|
|
|
},
|
|
|
|
|
|
2018-08-08 11:48:23 -07:00
|
|
|
/**
|
|
|
|
|
* Helper method to invoke when the video layout has changed and elements
|
|
|
|
|
* have to be re-arranged and resized.
|
|
|
|
|
*
|
|
|
|
|
* @returns {void}
|
|
|
|
|
*/
|
|
|
|
|
refreshLayout() {
|
|
|
|
|
VideoLayout.resizeVideoArea();
|
|
|
|
|
},
|
|
|
|
|
|
2019-01-01 13:19:34 -08:00
|
|
|
/**
|
|
|
|
|
* Cleans up any existing largeVideo instance.
|
|
|
|
|
*
|
|
|
|
|
* @private
|
|
|
|
|
* @returns {void}
|
|
|
|
|
*/
|
|
|
|
|
_resetLargeVideo() {
|
|
|
|
|
if (largeVideo) {
|
|
|
|
|
largeVideo.destroy();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
largeVideo = null;
|
|
|
|
|
},
|
|
|
|
|
|
2018-05-21 15:10:43 -07:00
|
|
|
/**
|
|
|
|
|
* Triggers an update of large video if the passed in participant is
|
|
|
|
|
* currently displayed on large video.
|
|
|
|
|
*
|
|
|
|
|
* @param {string} participantId - The participant ID that should trigger an
|
|
|
|
|
* update of large video if displayed.
|
2018-06-25 10:44:12 -07:00
|
|
|
* @param {boolean} force - Whether or not the large video update should
|
|
|
|
|
* happen no matter what.
|
2018-05-21 15:10:43 -07:00
|
|
|
* @returns {void}
|
|
|
|
|
*/
|
2018-06-25 10:44:12 -07:00
|
|
|
_updateLargeVideoIfDisplayed(participantId, force = false) {
|
2018-05-21 15:10:43 -07:00
|
|
|
if (this.isCurrentlyOnLarge(participantId)) {
|
2022-08-05 12:11:09 +03:00
|
|
|
this.updateLargeVideo(participantId, force, false);
|
2018-05-21 15:10:43 -07:00
|
|
|
}
|
2020-01-24 16:28:47 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Handles window resizes.
|
|
|
|
|
*/
|
|
|
|
|
onResize() {
|
|
|
|
|
VideoLayout.resizeVideoArea();
|
2017-01-05 19:18:07 -06:00
|
|
|
}
|
2015-12-14 14:26:50 +02:00
|
|
|
};
|
2015-01-07 16:54:03 +02:00
|
|
|
|
2015-12-14 14:26:50 +02:00
|
|
|
export default VideoLayout;
|