2020-12-14 21:38:29 +00:00
|
|
|
/* global APP */
|
2020-05-20 10:57:03 +00:00
|
|
|
|
2021-11-10 10:11:29 +00:00
|
|
|
import Logger from '@jitsi/logger';
|
2015-07-10 09:57:20 +00:00
|
|
|
|
2022-09-07 21:23:05 +00:00
|
|
|
import { getMultipleVideoSupportFeatureFlag } from '../../../react/features/base/config';
|
2020-04-14 22:41:30 +00:00
|
|
|
import { MEDIA_TYPE, VIDEO_TYPE } from '../../../react/features/base/media';
|
2017-08-10 20:51:35 +00:00
|
|
|
import {
|
|
|
|
getPinnedParticipant,
|
2021-01-21 20:46:47 +00:00
|
|
|
getParticipantById
|
2017-08-10 20:51:35 +00:00
|
|
|
} from '../../../react/features/base/participants';
|
2022-04-04 18:57:58 +00:00
|
|
|
import {
|
|
|
|
getTrackByMediaTypeAndParticipant,
|
2022-04-29 14:32:16 +00:00
|
|
|
getVirtualScreenshareParticipantTrack
|
2022-04-04 18:57:58 +00:00
|
|
|
} from '../../../react/features/base/tracks';
|
2018-05-22 17:13:51 +00:00
|
|
|
|
2017-10-12 23:02:29 +00:00
|
|
|
import LargeVideoManager from './LargeVideoManager';
|
|
|
|
import { VIDEO_CONTAINER_TYPE } from './VideoContainer';
|
2018-05-22 17:13:51 +00:00
|
|
|
|
2020-05-20 10:57:03 +00:00
|
|
|
const logger = Logger.getLogger(__filename);
|
2017-10-12 23:02:29 +00:00
|
|
|
let largeVideo;
|
2015-01-27 12:03:26 +00:00
|
|
|
|
2017-10-12 23:02:29 +00:00
|
|
|
const VideoLayout = {
|
2017-05-11 00:19:35 +00:00
|
|
|
/**
|
2021-01-21 20:46:47 +00:00
|
|
|
* Handler for local flip X changed event.
|
2017-05-11 00:19:35 +00:00
|
|
|
*/
|
2021-01-21 20:46:47 +00:00
|
|
|
onLocalFlipXChanged() {
|
|
|
|
if (largeVideo) {
|
|
|
|
const { store } = APP;
|
|
|
|
const { localFlipX } = store.getState()['features/base/settings'];
|
|
|
|
|
|
|
|
largeVideo.onLocalFlipXChange(localFlipX);
|
|
|
|
}
|
2017-05-11 00:19:35 +00:00
|
|
|
},
|
|
|
|
|
2017-02-15 21:39:16 +00:00
|
|
|
/**
|
2019-01-01 21:19:34 +00:00
|
|
|
* Cleans up state of this singleton {@code VideoLayout}.
|
2017-02-15 21:39:16 +00:00
|
|
|
*
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
2019-01-01 21:19:34 +00:00
|
|
|
reset() {
|
|
|
|
this._resetLargeVideo();
|
2015-12-14 12:26:50 +00:00
|
|
|
},
|
2015-01-19 09:20:00 +00:00
|
|
|
|
2017-10-12 23:02:29 +00:00
|
|
|
initLargeVideo() {
|
2019-01-01 21:19:34 +00:00
|
|
|
this._resetLargeVideo();
|
2017-05-11 00:19:35 +00:00
|
|
|
|
2021-01-21 20:46:47 +00:00
|
|
|
largeVideo = new LargeVideoManager();
|
|
|
|
|
|
|
|
const { store } = APP;
|
|
|
|
const { localFlipX } = store.getState()['features/base/settings'];
|
|
|
|
|
|
|
|
if (typeof localFlipX === 'boolean') {
|
2016-05-07 01:50:37 +00:00
|
|
|
largeVideo.onLocalFlipXChange(localFlipX);
|
|
|
|
}
|
2016-09-08 18:16:23 +00:00
|
|
|
largeVideo.updateContainerSize();
|
2015-12-25 16:55:45 +00:00
|
|
|
},
|
|
|
|
|
2016-09-28 21:31:40 +00: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 16:55:45 +00:00
|
|
|
setAudioLevel(id, lvl) {
|
2017-10-12 23:02:29 +00:00
|
|
|
if (largeVideo && id === largeVideo.id) {
|
2016-09-28 21:31:40 +00:00
|
|
|
largeVideo.updateLargeVideoAudioLevel(lvl);
|
2017-10-12 23:02:29 +00:00
|
|
|
}
|
2015-12-25 16:55:45 +00:00
|
|
|
},
|
|
|
|
|
2017-07-19 10:08:51 +00: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 20:59:13 +00:00
|
|
|
updateVideoMutedForNoTracks(participantId) {
|
2017-07-19 10:08:51 +00:00
|
|
|
const participant = APP.conference.getParticipantById(participantId);
|
|
|
|
|
2020-11-09 20:59:13 +00:00
|
|
|
if (participant && !participant.getTracksByMediaType('video').length) {
|
2021-01-21 20:46:47 +00:00
|
|
|
VideoLayout._updateLargeVideoIfDisplayed(participantId, true);
|
2017-07-19 10:08:51 +00:00
|
|
|
}
|
2016-02-23 22:47:55 +00:00
|
|
|
},
|
2014-11-21 13:29:05 +00:00
|
|
|
|
2015-11-16 23:42:21 +00:00
|
|
|
/**
|
|
|
|
* Return the type of the remote video.
|
2015-12-14 12:26:50 +00:00
|
|
|
* @param id the id for the remote video
|
2016-03-15 18:36:17 +00:00
|
|
|
* @returns {String} the video type video or screen.
|
2015-11-16 23:42:21 +00:00
|
|
|
*/
|
2017-10-12 23:02:29 +00:00
|
|
|
getRemoteVideoType(id) {
|
2020-04-14 22:41:30 +00:00
|
|
|
const state = APP.store.getState();
|
|
|
|
const participant = getParticipantById(state, id);
|
|
|
|
|
|
|
|
if (participant?.isFakeParticipant) {
|
2021-04-16 09:43:34 +00:00
|
|
|
return VIDEO_TYPE.CAMERA;
|
2020-04-14 22:41:30 +00:00
|
|
|
}
|
2017-10-12 23:02:29 +00:00
|
|
|
|
2022-09-07 21:23:05 +00:00
|
|
|
if (getMultipleVideoSupportFeatureFlag(state) && participant?.isVirtualScreenshareParticipant) {
|
2022-04-04 18:57:58 +00:00
|
|
|
return VIDEO_TYPE.DESKTOP;
|
|
|
|
}
|
|
|
|
|
2020-04-14 22:41:30 +00:00
|
|
|
const videoTrack = getTrackByMediaTypeAndParticipant(state['features/base/tracks'], MEDIA_TYPE.VIDEO, id);
|
2017-10-12 23:02:29 +00:00
|
|
|
|
2020-04-14 22:41:30 +00:00
|
|
|
return videoTrack?.videoType;
|
2015-12-14 12:26:50 +00:00
|
|
|
},
|
2015-11-16 23:42:21 +00:00
|
|
|
|
2017-10-12 23:02:29 +00:00
|
|
|
getPinnedId() {
|
2017-08-10 20:51:35 +00:00
|
|
|
const { id } = getPinnedParticipant(APP.store.getState()) || {};
|
|
|
|
|
|
|
|
return id || null;
|
|
|
|
},
|
|
|
|
|
2016-09-16 20:51:19 +00:00
|
|
|
/**
|
2018-06-25 17:44:12 +00:00
|
|
|
* Shows/hides warning about a user's connectivity issues.
|
2016-09-16 20:51:19 +00:00
|
|
|
*
|
2018-06-25 17:44:12 +00:00
|
|
|
* @param {string} id - The ID of the remote participant(MUC nickname).
|
|
|
|
* @returns {void}
|
2016-09-16 20:51:19 +00:00
|
|
|
*/
|
2020-02-04 07:25:13 +00:00
|
|
|
onParticipantConnectionStatusChanged(id) {
|
2018-06-25 17:44:12 +00:00
|
|
|
if (APP.conference.isLocalId(id)) {
|
|
|
|
|
|
|
|
return;
|
2016-09-24 18:24:18 +00:00
|
|
|
}
|
2017-10-12 23:02:29 +00:00
|
|
|
|
2018-06-25 17:44:12 +00:00
|
|
|
// We have to trigger full large video update to transition from
|
|
|
|
// avatar to video on connectivity restored.
|
|
|
|
this._updateLargeVideoIfDisplayed(id, true);
|
2016-09-16 20:51:19 +00:00
|
|
|
},
|
|
|
|
|
2014-08-22 15:37:11 +00:00
|
|
|
/**
|
|
|
|
* On last N change event.
|
|
|
|
*
|
2017-03-21 21:51:49 +00:00
|
|
|
* @param endpointsLeavingLastN the list currently leaving last N
|
|
|
|
* endpoints
|
2014-08-22 15:37:11 +00:00
|
|
|
* @param endpointsEnteringLastN the list currently entering last N
|
|
|
|
* endpoints
|
|
|
|
*/
|
2017-10-12 23:02:29 +00:00
|
|
|
onLastNEndpointsChanged(endpointsLeavingLastN, endpointsEnteringLastN) {
|
2017-03-21 21:51:49 +00:00
|
|
|
if (endpointsLeavingLastN) {
|
2021-01-21 20:46:47 +00:00
|
|
|
endpointsLeavingLastN.forEach(this._updateLargeVideoIfDisplayed, this);
|
2017-03-21 21:51:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (endpointsEnteringLastN) {
|
2021-01-21 20:46:47 +00:00
|
|
|
endpointsEnteringLastN.forEach(this._updateLargeVideoIfDisplayed, this);
|
2017-03-21 21:51:49 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2015-06-23 08:00:46 +00:00
|
|
|
/**
|
2015-11-13 17:04:49 +00:00
|
|
|
* Resizes the video area.
|
2016-03-15 21:03:38 +00:00
|
|
|
*/
|
2020-02-10 15:27:43 +00:00
|
|
|
resizeVideoArea() {
|
2015-12-25 16:55:45 +00:00
|
|
|
if (largeVideo) {
|
2016-09-08 18:16:23 +00:00
|
|
|
largeVideo.updateContainerSize();
|
2020-02-10 15:27:43 +00:00
|
|
|
largeVideo.resize(false);
|
2015-12-25 16:55:45 +00:00
|
|
|
}
|
2015-12-14 12:26:50 +00:00
|
|
|
},
|
2015-08-06 23:34:40 +00:00
|
|
|
|
2017-10-12 23:02:29 +00:00
|
|
|
changeUserAvatar(id, avatarUrl) {
|
2015-12-25 16:55:45 +00:00
|
|
|
if (this.isCurrentlyOnLarge(id)) {
|
2016-01-19 23:10:44 +00:00
|
|
|
largeVideo.updateAvatar(avatarUrl);
|
2015-12-25 16:55:45 +00:00
|
|
|
}
|
2015-12-14 12:26:50 +00:00
|
|
|
},
|
2015-07-29 19:39:09 +00:00
|
|
|
|
2017-10-12 23:02:29 +00:00
|
|
|
isLargeVideoVisible() {
|
2016-03-18 20:00:55 +00:00
|
|
|
return this.isLargeContainerTypeVisible(VIDEO_CONTAINER_TYPE);
|
2015-12-25 16:55:45 +00:00
|
|
|
},
|
|
|
|
|
2016-03-18 03:19:09 +00:00
|
|
|
/**
|
|
|
|
* @return {LargeContainer} the currently displayed container on large
|
|
|
|
* video.
|
|
|
|
*/
|
2017-10-12 23:02:29 +00:00
|
|
|
getCurrentlyOnLargeContainer() {
|
2017-07-10 09:02:22 +00:00
|
|
|
return largeVideo.getCurrentContainer();
|
2016-03-18 03:19:09 +00:00
|
|
|
},
|
|
|
|
|
2017-10-12 23:02:29 +00:00
|
|
|
isCurrentlyOnLarge(id) {
|
2015-12-25 16:55:45 +00:00
|
|
|
return largeVideo && largeVideo.id === id;
|
|
|
|
},
|
|
|
|
|
2022-08-05 09:11:09 +00:00
|
|
|
updateLargeVideo(id, forceUpdate, forceStreamToReattach = false) {
|
2015-12-25 16:55:45 +00:00
|
|
|
if (!largeVideo) {
|
|
|
|
return;
|
|
|
|
}
|
2017-07-10 10:06:48 +00:00
|
|
|
const currentContainer = largeVideo.getCurrentContainer();
|
|
|
|
const currentContainerType = largeVideo.getCurrentContainerType();
|
|
|
|
const isOnLarge = this.isCurrentlyOnLarge(id);
|
2020-04-14 22:41:30 +00:00
|
|
|
const state = APP.store.getState();
|
2022-04-04 18:57:58 +00:00
|
|
|
const participant = getParticipantById(state, id);
|
|
|
|
const tracks = state['features/base/tracks'];
|
|
|
|
|
|
|
|
let videoTrack;
|
|
|
|
|
2022-09-07 21:23:05 +00:00
|
|
|
if (getMultipleVideoSupportFeatureFlag(state) && participant?.isVirtualScreenshareParticipant) {
|
2022-04-29 14:32:16 +00:00
|
|
|
videoTrack = getVirtualScreenshareParticipantTrack(tracks, id);
|
2022-04-04 18:57:58 +00:00
|
|
|
} else {
|
|
|
|
videoTrack = getTrackByMediaTypeAndParticipant(tracks, MEDIA_TYPE.VIDEO, id);
|
|
|
|
}
|
|
|
|
|
2020-04-14 22:41:30 +00:00
|
|
|
const videoStream = videoTrack?.jitsiTrack;
|
2017-07-10 10:06:48 +00:00
|
|
|
|
2022-08-05 09:11:09 +00:00
|
|
|
if (videoStream && forceStreamToReattach) {
|
|
|
|
videoStream.forceStreamToReattach = forceStreamToReattach;
|
|
|
|
}
|
|
|
|
|
2017-07-10 10:06:48 +00:00
|
|
|
if (isOnLarge && !forceUpdate
|
|
|
|
&& LargeVideoManager.isVideoContainer(currentContainerType)
|
2020-04-14 22:41:30 +00:00
|
|
|
&& videoStream) {
|
2017-07-10 10:06:48 +00:00
|
|
|
const currentStreamId = currentContainer.getStreamID();
|
2020-04-14 22:41:30 +00:00
|
|
|
const newStreamId = videoStream?.getId() || null;
|
2017-07-10 10:06:48 +00: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 23:02:29 +00:00
|
|
|
forceUpdate = true; // eslint-disable-line no-param-reassign
|
2017-07-10 10:06:48 +00:00
|
|
|
}
|
|
|
|
}
|
2015-12-25 16:55:45 +00:00
|
|
|
|
2020-04-14 22:41:30 +00:00
|
|
|
if (!isOnLarge || forceUpdate) {
|
2017-10-12 23:02:29 +00:00
|
|
|
const videoType = this.getRemoteVideoType(id);
|
|
|
|
|
2016-01-14 16:28:24 +00:00
|
|
|
largeVideo.updateLargeVideo(
|
2016-01-29 19:31:58 +00:00
|
|
|
id,
|
2020-04-14 22:41:30 +00:00
|
|
|
videoStream,
|
2018-07-02 15:39:28 +00:00
|
|
|
videoType || VIDEO_TYPE.CAMERA
|
2020-04-14 22:41:30 +00:00
|
|
|
).catch(() => {
|
|
|
|
// do nothing
|
2016-01-22 15:08:58 +00:00
|
|
|
});
|
2015-12-25 16:55:45 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2017-10-12 23:02:29 +00:00
|
|
|
addLargeVideoContainer(type, container) {
|
2015-12-25 16:55:45 +00:00
|
|
|
largeVideo && largeVideo.addContainer(type, container);
|
|
|
|
},
|
|
|
|
|
2017-10-12 23:02:29 +00:00
|
|
|
removeLargeVideoContainer(type) {
|
2015-12-25 16:55:45 +00:00
|
|
|
largeVideo && largeVideo.removeContainer(type);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @returns Promise
|
|
|
|
*/
|
2017-10-12 23:02:29 +00:00
|
|
|
showLargeVideoContainer(type, show) {
|
2015-12-25 16:55:45 +00:00
|
|
|
if (!largeVideo) {
|
|
|
|
return Promise.reject();
|
|
|
|
}
|
|
|
|
|
2017-10-12 23:02:29 +00:00
|
|
|
const isVisible = this.isLargeContainerTypeVisible(type);
|
|
|
|
|
2015-12-25 16:55:45 +00:00
|
|
|
if (isVisible === show) {
|
|
|
|
return Promise.resolve();
|
|
|
|
}
|
|
|
|
|
2016-03-22 21:12:25 +00:00
|
|
|
let containerTypeToShow = type;
|
2017-10-12 23:02:29 +00:00
|
|
|
|
2016-03-22 21:12:25 +00: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 23:02:29 +00:00
|
|
|
|
2016-03-22 21:12:25 +00:00
|
|
|
if (!show) {
|
2017-08-10 20:51:35 +00:00
|
|
|
const pinnedId = this.getPinnedId();
|
|
|
|
|
2017-10-12 23:02:29 +00:00
|
|
|
if (pinnedId) {
|
2016-03-24 18:16:42 +00:00
|
|
|
containerTypeToShow = this.getRemoteVideoType(pinnedId);
|
2017-10-12 23:02:29 +00:00
|
|
|
} else {
|
2016-03-22 21:12:25 +00:00
|
|
|
containerTypeToShow = VIDEO_CONTAINER_TYPE;
|
2017-10-12 23:02:29 +00:00
|
|
|
}
|
2016-03-22 21:12:25 +00:00
|
|
|
}
|
|
|
|
|
2021-01-21 20:46:47 +00:00
|
|
|
return largeVideo.showContainer(containerTypeToShow);
|
2015-12-25 16:55:45 +00:00
|
|
|
},
|
|
|
|
|
2017-10-12 23:02:29 +00:00
|
|
|
isLargeContainerTypeVisible(type) {
|
2015-12-25 16:55:45 +00:00
|
|
|
return largeVideo && largeVideo.state === type;
|
2016-01-14 19:30:27 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the id of the current video shown on large.
|
2016-03-18 20:00:55 +00:00
|
|
|
* Currently used by tests (torture).
|
2016-01-14 19:30:27 +00:00
|
|
|
*/
|
2017-10-12 23:02:29 +00:00
|
|
|
getLargeVideoID() {
|
2018-04-12 21:23:03 +00:00
|
|
|
return largeVideo && largeVideo.id;
|
2016-03-18 20:00:55 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the the current video shown on large.
|
|
|
|
* Currently used by tests (torture).
|
|
|
|
*/
|
2017-10-12 23:02:29 +00:00
|
|
|
getLargeVideo() {
|
2016-03-18 20:00:55 +00:00
|
|
|
return largeVideo;
|
2016-03-15 20:26:22 +00:00
|
|
|
},
|
|
|
|
|
2017-01-20 20:26:25 +00: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-19 00:40:14 +00:00
|
|
|
},
|
|
|
|
|
2018-08-08 18:48:23 +00: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 21:19:34 +00:00
|
|
|
/**
|
|
|
|
* Cleans up any existing largeVideo instance.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
_resetLargeVideo() {
|
|
|
|
if (largeVideo) {
|
|
|
|
largeVideo.destroy();
|
|
|
|
}
|
|
|
|
|
|
|
|
largeVideo = null;
|
|
|
|
},
|
|
|
|
|
2018-05-21 22:10:43 +00: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 17:44:12 +00:00
|
|
|
* @param {boolean} force - Whether or not the large video update should
|
|
|
|
* happen no matter what.
|
2018-05-21 22:10:43 +00:00
|
|
|
* @returns {void}
|
|
|
|
*/
|
2018-06-25 17:44:12 +00:00
|
|
|
_updateLargeVideoIfDisplayed(participantId, force = false) {
|
2018-05-21 22:10:43 +00:00
|
|
|
if (this.isCurrentlyOnLarge(participantId)) {
|
2022-08-05 09:11:09 +00:00
|
|
|
this.updateLargeVideo(participantId, force, false);
|
2018-05-21 22:10:43 +00:00
|
|
|
}
|
2020-01-24 16:28:47 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handles window resizes.
|
|
|
|
*/
|
|
|
|
onResize() {
|
|
|
|
VideoLayout.resizeVideoArea();
|
2017-01-06 01:18:07 +00:00
|
|
|
}
|
2015-12-14 12:26:50 +00:00
|
|
|
};
|
2015-01-07 14:54:03 +00:00
|
|
|
|
2015-12-14 12:26:50 +00:00
|
|
|
export default VideoLayout;
|