jiti-meet/modules/UI/videolayout/VideoLayout.js

1172 lines
36 KiB
JavaScript
Raw Normal View History

/* global APP, $, interfaceConfig, JitsiMeetJS */
2016-11-11 15:00:54 +00:00
const logger = require("jitsi-meet-logger").getLogger(__filename);
import {
getPinnedParticipant,
pinParticipant
} from '../../../react/features/base/participants';
import Filmstrip from "./Filmstrip";
2015-12-14 12:26:50 +00:00
import UIEvents from "../../../service/UI/UIEvents";
import UIUtil from "../util/UIUtil";
2015-06-23 08:00:46 +00:00
2015-12-14 12:26:50 +00:00
import RemoteVideo from "./RemoteVideo";
import LargeVideoManager from "./LargeVideoManager";
import {VIDEO_CONTAINER_TYPE} from "./VideoContainer";
2015-12-14 12:26:50 +00:00
import LocalVideo from "./LocalVideo";
const ParticipantConnectionStatus
= JitsiMeetJS.constants.participantConnectionStatus;
2015-06-23 08:00:46 +00:00
var remoteVideos = {};
var localVideoThumbnail = null;
2015-01-07 14:54:03 +00:00
var currentDominantSpeaker = null;
var eventEmitter = null;
/**
* flipX state of the localVideo
*/
let localFlipX = null;
2015-12-14 12:26:50 +00:00
/**
* On contact list item clicked.
*/
2015-12-14 15:40:30 +00:00
function onContactClicked (id) {
2015-12-14 12:26:50 +00:00
if (APP.conference.isLocalId(id)) {
$("#localVideoContainer").click();
return;
}
2015-12-14 15:40:30 +00:00
let remoteVideo = remoteVideos[id];
if (remoteVideo && remoteVideo.hasVideo()) {
2015-12-14 12:26:50 +00:00
// It is not always the case that a videoThumb exists (if there is
// no actual video).
if (remoteVideo.hasVideoStarted()) {
2015-12-14 12:26:50 +00:00
// We have a video src, great! Let's update the large video
// now.
VideoLayout.handleVideoThumbClicked(id);
2015-12-14 12:26:50 +00:00
} else {
// If we don't have a video src for jid, there's absolutely
// no point in calling handleVideoThumbClicked; Quite
// simply, it won't work because it needs an src to attach
// to the large video.
//
// Instead, we trigger the pinned endpoint changed event to
// let the bridge adjust its lastN set for myjid and store
// the pinned user in the lastNPickupId variable to be
// picked up later by the lastN changed event handler.
this.pinParticipant(remoteVideo.id);
2015-12-14 12:26:50 +00:00
}
}
2015-12-14 15:40:30 +00:00
}
2015-12-14 12:26:50 +00:00
/**
* Handler for local flip X changed event.
* @param {Object} val
*/
function onLocalFlipXChanged (val) {
localFlipX = val;
if(largeVideo) {
largeVideo.onLocalFlipXChange(val);
}
}
2015-12-14 14:51:02 +00:00
/**
* Returns the corresponding resource id to the given peer container
* DOM element.
*
* @return the corresponding resource id to the given peer container
* DOM element
*/
function getPeerContainerResourceId (containerElement) {
if (localVideoThumbnail.container === containerElement) {
return localVideoThumbnail.id;
}
let i = containerElement.id.indexOf('participant_');
if (i >= 0) {
return containerElement.id.substring(i + 12);
}
}
2015-12-25 16:55:45 +00:00
let largeVideo;
2015-12-14 12:26:50 +00:00
var VideoLayout = {
init (emitter) {
eventEmitter = emitter;
// Unregister listeners in case of reinitialization
this.unregisterListeners();
2015-12-01 12:53:01 +00:00
localVideoThumbnail = new LocalVideo(VideoLayout, emitter);
// sets default video type of local video
// FIXME container type is totally different thing from the video type
localVideoThumbnail.setVideoType(VIDEO_CONTAINER_TYPE);
// if we do not resize the thumbs here, if there is no video device
// the local video thumb maybe one pixel
this.resizeThumbnails(false, true);
this.registerListeners();
},
/**
* Cleans up any existing largeVideo instance.
*
* @returns {void}
*/
resetLargeVideo() {
if (largeVideo) {
largeVideo.destroy();
}
largeVideo = null;
},
/**
* Registering listeners for UI events in Video layout component.
*
* @returns {void}
*/
registerListeners() {
eventEmitter.addListener(UIEvents.LOCAL_FLIPX_CHANGED,
onLocalFlipXChanged);
eventEmitter.addListener(UIEvents.CONTACT_CLICKED, onContactClicked);
},
/**
* Unregistering listeners for UI events in Video layout component.
*
* @returns {void}
*/
unregisterListeners() {
eventEmitter.removeListener(UIEvents.CONTACT_CLICKED, onContactClicked);
2015-12-14 12:26:50 +00:00
},
initLargeVideo () {
this.resetLargeVideo();
largeVideo = new LargeVideoManager(eventEmitter);
if(localFlipX) {
largeVideo.onLocalFlipXChange(localFlipX);
}
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) {
2016-09-28 21:31:40 +00:00
let smallVideo = this.getSmallVideo(id);
if (smallVideo)
smallVideo.updateAudioLevelIndicator(lvl);
if (largeVideo && id === largeVideo.id)
largeVideo.updateLargeVideoAudioLevel(lvl);
2015-12-25 16:55:45 +00:00
},
2015-12-14 12:26:50 +00:00
changeLocalAudio (stream) {
let localAudio = document.getElementById('localAudio');
localAudio = stream.attach(localAudio);
2015-12-14 12:26:50 +00:00
// Now when Temasys plugin is converting also <audio> elements to
// plugin's <object>s, in current layout it will capture click events
// before it reaches the local video object. We hide it here in order
// to prevent that.
2016-02-02 21:50:02 +00:00
//if (RTCBrowserType.isIExplorer()) {
// The issue is not present on Safari. Also if we hide it in Safari
// then the local audio track will have 'enabled' flag set to false
// which will result in audio mute issues
2016-02-02 21:50:02 +00:00
// $(localAudio).hide();
localAudio.width = 1;
localAudio.height = 1;
//}
2015-12-14 12:26:50 +00:00
},
2015-12-14 12:26:50 +00:00
changeLocalVideo (stream) {
2016-07-08 01:44:04 +00:00
let localId = APP.conference.getMyUserId();
2015-12-30 12:14:56 +00:00
this.onVideoTypeChanged(localId, stream.videoType);
localVideoThumbnail.changeVideo(stream);
/* Update if we're currently being displayed */
2015-12-25 16:55:45 +00:00
if (this.isCurrentlyOnLarge(localId)) {
this.updateLargeVideo(localId);
}
2015-12-14 12:26:50 +00:00
},
/**
* Get's the localID of the conference and set it to the local video
* (small one). This needs to be called as early as possible, when muc is
* actually joined. Otherwise events can come with information like email
* and setting them assume the id is already set.
*/
2015-12-14 12:26:50 +00:00
mucJoined () {
2015-12-25 16:55:45 +00:00
if (largeVideo && !largeVideo.id) {
2016-07-08 01:44:04 +00:00
this.updateLargeVideo(APP.conference.getMyUserId(), true);
2015-12-14 12:26:50 +00:00
}
// FIXME: replace this call with a generic update call once SmallVideo
// only contains a ReactElement. Then remove this call once the
// Filmstrip is fully in React.
localVideoThumbnail.updateIndicators();
2015-12-14 12:26:50 +00:00
},
/**
* Adds or removes icons for not available camera and microphone.
* @param resourceJid the jid of user
* @param devices available devices
*/
2016-01-25 22:39:05 +00:00
setDeviceAvailabilityIcons (id, devices) {
if (APP.conference.isLocalId(id)) {
localVideoThumbnail.setDeviceAvailabilityIcons(devices);
return;
2016-01-25 22:39:05 +00:00
}
2016-01-25 22:39:05 +00:00
let video = remoteVideos[id];
if (!video) {
return;
}
2016-01-25 22:39:05 +00:00
video.setDeviceAvailabilityIcons(devices);
2015-12-14 12:26:50 +00:00
},
/**
* Enables/disables device availability icons for the given participant id.
* The default value is {true}.
* @param id the identifier of the participant
* @param enable {true} to enable device availability icons
*/
enableDeviceAvailabilityIcons (id, enable) {
let video;
if (APP.conference.isLocalId(id)) {
video = localVideoThumbnail;
}
else {
video = remoteVideos[id];
}
if (video)
video.enableDeviceAvailabilityIcons(enable);
},
2016-05-01 18:35:18 +00:00
/**
* Shows/hides local video.
* @param {boolean} true to make the local video visible, false - otherwise
*/
setLocalVideoVisible(visible) {
localVideoThumbnail.setVisible(visible);
},
/**
2014-06-19 13:40:54 +00:00
* Checks if removed video is currently displayed and tries to display
* another one instead.
* Uses focusedID if any or dominantSpeakerID if any,
* otherwise elects new video, in this order.
*/
updateAfterThumbRemoved (id) {
// Always trigger an update if large video is empty.
if (!largeVideo
|| (this.getLargeVideoID() && !this.isCurrentlyOnLarge(id))) {
2015-12-14 14:51:02 +00:00
return;
}
const pinnedId = this.getPinnedId();
2015-12-14 12:26:50 +00:00
let newId;
if (pinnedId)
newId = pinnedId;
else if (currentDominantSpeaker)
newId = currentDominantSpeaker;
else // Otherwise select last visible video
2015-12-14 14:51:02 +00:00
newId = this.electLastVisibleVideo();
2015-12-25 16:55:45 +00:00
this.updateLargeVideo(newId);
2015-12-14 12:26:50 +00:00
},
2015-12-14 12:26:50 +00:00
electLastVisibleVideo () {
// pick the last visible video in the row
// if nobody else is left, this picks the local video
let remoteThumbs = Filmstrip.getThumbs(true).remoteThumbs;
2016-09-15 02:20:54 +00:00
let thumbs = remoteThumbs.filter('[id!="mixedstream"]');
2015-12-30 10:55:51 +00:00
let lastVisible = thumbs.filter(':visible:last');
if (lastVisible.length) {
let id = getPeerContainerResourceId(lastVisible[0]);
2015-12-14 14:51:02 +00:00
if (remoteVideos[id]) {
2016-11-11 15:00:54 +00:00
logger.info("electLastVisibleVideo: " + id);
2015-12-14 14:51:02 +00:00
return id;
}
2015-12-14 14:51:02 +00:00
// The RemoteVideo was removed (but the DOM elements may still
// exist).
}
2016-11-11 15:00:54 +00:00
logger.info("Last visible video no longer exists");
thumbs = Filmstrip.getThumbs().remoteThumbs;
2015-12-30 10:55:51 +00:00
if (thumbs.length) {
let id = getPeerContainerResourceId(thumbs[0]);
2015-12-14 14:51:02 +00:00
if (remoteVideos[id]) {
2016-11-11 15:00:54 +00:00
logger.info("electLastVisibleVideo: " + id);
2015-12-14 14:51:02 +00:00
return id;
}
2015-12-14 14:51:02 +00:00
// The RemoteVideo was removed (but the DOM elements may
// still exist).
}
2015-12-14 14:51:02 +00:00
// Go with local video
2016-11-11 15:00:54 +00:00
logger.info("Fallback to local video...");
2016-07-08 01:44:04 +00:00
let id = APP.conference.getMyUserId();
2016-11-11 15:00:54 +00:00
logger.info("electLastVisibleVideo: " + id);
2015-12-14 14:51:02 +00:00
return id;
2015-12-14 12:26:50 +00:00
},
2015-11-30 11:54:54 +00:00
2015-12-14 12:26:50 +00:00
onRemoteStreamAdded (stream) {
let id = stream.getParticipantId();
2016-04-26 21:38:07 +00:00
let remoteVideo = remoteVideos[id];
if (!remoteVideo)
return;
remoteVideo.addRemoteStreamElement(stream);
// Make sure track's muted state is reflected
if (stream.getType() === "audio") {
this.onAudioMute(stream.getParticipantId(), stream.isMuted());
} else {
this.onVideoMute(stream.getParticipantId(), stream.isMuted());
}
2015-12-14 12:26:50 +00:00
},
onRemoteStreamRemoved (stream) {
let id = stream.getParticipantId();
let remoteVideo = remoteVideos[id];
// Remote stream may be removed after participant left the conference.
if (remoteVideo) {
remoteVideo.removeRemoteStreamElement(stream);
}
this.updateMutedForNoTracks(id, stream.getType());
},
/**
* 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
* @param {string} mediaType 'audio' or 'video'
*/
updateMutedForNoTracks(participantId, mediaType) {
const participant = APP.conference.getParticipantById(participantId);
if (participant
&& !participant.getTracksByMediaType(mediaType).length) {
if (mediaType === 'audio') {
APP.UI.setAudioMuted(participantId, true);
} else if (mediaType === 'video') {
APP.UI.setVideoMuted(participantId, true);
} else {
logger.error(`Unsupported media type: ${mediaType}`);
}
}
},
/**
* Return the type of the remote video.
2015-12-14 12:26:50 +00:00
* @param id the id for the remote video
* @returns {String} the video type video or screen.
*/
2015-12-14 12:26:50 +00:00
getRemoteVideoType (id) {
let smallVideo = VideoLayout.getSmallVideo(id);
return smallVideo ? smallVideo.getVideoType() : null;
2015-12-14 12:26:50 +00:00
},
isPinned (id) {
return id === this.getPinnedId();
},
getPinnedId () {
const { id } = getPinnedParticipant(APP.store.getState()) || {};
return id || null;
},
/**
* Updates the desired pinned participant and notifies web UI of the change.
*
* @param {string|null} id - The participant id of the participant to be
* pinned. Pass in null to unpin without pinning another participant.
* @returns {void}
*/
pinParticipant(id) {
APP.store.dispatch(pinParticipant(id));
APP.UI.emitEvent(UIEvents.PINNED_ENDPOINT, id, Boolean(id));
},
/**
* Handles the click on a video thumbnail.
*
* @param id the identifier of the video thumbnail
*/
handleVideoThumbClicked (id) {
var smallVideo = VideoLayout.getSmallVideo(id);
const pinnedId = this.getPinnedId();
if(pinnedId) {
var oldSmallVideo = VideoLayout.getSmallVideo(pinnedId);
if (oldSmallVideo && !interfaceConfig.filmStripOnly) {
2015-06-23 08:00:46 +00:00
oldSmallVideo.focus(false);
}
}
// Unpin if currently pinned.
if (pinnedId === id)
{
this.pinParticipant(null);
// Enable the currently set dominant speaker.
if (currentDominantSpeaker) {
if(smallVideo && smallVideo.hasVideo()) {
2015-12-25 16:55:45 +00:00
this.updateLargeVideo(currentDominantSpeaker);
}
} else {
// if there is no currentDominantSpeaker, it can also be
// that local participant is the dominant speaker
// we should act as a participant has left and was on large
// and we should choose somebody (electLastVisibleVideo)
this.updateLargeVideo(this.electLastVisibleVideo());
}
return;
}
// Update focused/pinned interface.
if (id) {
if (smallVideo && !interfaceConfig.filmStripOnly) {
2015-06-23 08:00:46 +00:00
smallVideo.focus(true);
this.pinParticipant(id);
}
}
this.updateLargeVideo(id);
2015-12-14 12:26:50 +00:00
},
/**
* Creates or adds a participant container for the given id and smallVideo.
2016-04-26 21:38:07 +00:00
*
* @param {JitsiParticipant} user the participant to add
* @param {SmallVideo} smallVideo optional small video instance to add as a
* remote video, if undefined <tt>RemoteVideo</tt> will be created
*/
addParticipantContainer (user, smallVideo) {
let id = user.getId();
let remoteVideo;
if(smallVideo)
remoteVideo = smallVideo;
else
remoteVideo = new RemoteVideo(user, VideoLayout, eventEmitter);
this._setRemoteControlProperties(user, remoteVideo);
this.addRemoteVideoContainer(id, remoteVideo);
this.updateMutedForNoTracks(id, 'audio');
this.updateMutedForNoTracks(id, 'video');
const remoteVideosCount = Object.keys(remoteVideos).length;
if (remoteVideosCount === 1) {
window.setTimeout(() => {
const updatedRemoteVideosCount
= Object.keys(remoteVideos).length;
if (updatedRemoteVideosCount === 1 && remoteVideos[id]) {
this._maybePlaceParticipantOnLargeVideo(id);
}
}, 3000);
}
},
/**
* Adds remote video container for the given id and <tt>SmallVideo</tt>.
*
* @param {string} the id of the video to add
* @param {SmallVideo} smallVideo the small video instance to add as a
* remote video
*/
addRemoteVideoContainer (id, remoteVideo) {
2015-12-14 12:26:50 +00:00
remoteVideos[id] = remoteVideo;
2016-11-08 02:39:28 +00:00
if (!remoteVideo.getVideoType()) {
// make video type the default one (camera)
// FIXME container type is not a video type
2016-11-08 02:39:28 +00:00
remoteVideo.setVideoType(VIDEO_CONTAINER_TYPE);
2015-12-14 12:26:50 +00:00
}
VideoLayout.resizeThumbnails(false, true);
// Initialize the view
remoteVideo.updateView();
2015-12-14 12:26:50 +00:00
},
// FIXME: what does this do???
remoteVideoActive(videoElement, resourceJid) {
2016-11-11 15:00:54 +00:00
logger.info(resourceJid + " video is now active", videoElement);
VideoLayout.resizeThumbnails(
false, false, () => {
if (videoElement) {
$(videoElement).show();
}
});
2015-06-23 08:00:46 +00:00
this._maybePlaceParticipantOnLargeVideo(resourceJid);
},
/**
* Update the large video to the last added video only if there's no current
* dominant, focused speaker or update it to the current dominant speaker.
*
* @params {string} resourceJid - The id of the user to maybe display on
* large video.
* @returns {void}
*/
_maybePlaceParticipantOnLargeVideo(resourceJid) {
const pinnedId = this.getPinnedId();
if ((!pinnedId &&
!currentDominantSpeaker &&
this.isLargeContainerTypeVisible(VIDEO_CONTAINER_TYPE)) ||
pinnedId === resourceJid ||
(!pinnedId && resourceJid &&
currentDominantSpeaker === resourceJid) ||
/* Playback started while we're on the stage - may need to update
video source with the new stream */
this.isCurrentlyOnLarge(resourceJid)) {
2015-12-25 16:55:45 +00:00
this.updateLargeVideo(resourceJid, true);
}
2015-12-14 12:26:50 +00:00
},
/**
* Shows a visual indicator for the moderator of the conference.
2016-01-13 21:17:33 +00:00
* On local or remote participants.
*/
2015-12-14 12:26:50 +00:00
showModeratorIndicator () {
let isModerator = APP.conference.isModerator;
if (isModerator) {
2016-09-28 21:31:40 +00:00
localVideoThumbnail.addModeratorIndicator();
2016-07-08 01:44:04 +00:00
} else {
2016-09-28 21:31:40 +00:00
localVideoThumbnail.removeModeratorIndicator();
}
2015-12-14 12:26:50 +00:00
APP.conference.listMembers().forEach(function (member) {
let id = member.getId();
2016-04-27 20:52:07 +00:00
let remoteVideo = remoteVideos[id];
if (!remoteVideo)
return;
2015-12-14 12:26:50 +00:00
if (member.isModerator()) {
2016-09-28 21:31:40 +00:00
remoteVideo.addModeratorIndicator();
}
if (isModerator) {
// We are moderator, but user is not - add menu
if(!remoteVideo.hasRemoteVideoMenu) {
2016-04-27 20:52:07 +00:00
remoteVideo.addRemoteVideoMenu();
}
}
});
2015-12-14 12:26:50 +00:00
},
/*
* Shows or hides the audio muted indicator over the local thumbnail video.
* @param {boolean} isMuted
*/
2015-12-14 12:26:50 +00:00
showLocalAudioIndicator (isMuted) {
2015-06-30 11:34:11 +00:00
localVideoThumbnail.showAudioIndicator(isMuted);
2015-12-14 12:26:50 +00:00
},
/**
* Shows/hides the indication about local connection being interrupted.
*
* @param {boolean} isInterrupted <tt>true</tt> if local connection is
* currently in the interrupted state or <tt>false</tt> if the connection
* is fine.
*/
showLocalConnectionInterrupted (isInterrupted) {
// Currently local video thumbnail displays only "active" or
// "interrupted" despite the fact that ConnectionIndicator supports more
// states.
const status
= isInterrupted
? ParticipantConnectionStatus.INTERRUPTED
: ParticipantConnectionStatus.ACTIVE;
localVideoThumbnail.updateConnectionStatus(status);
},
/**
* Resizes thumbnails.
*/
resizeThumbnails ( animate = false,
forceUpdate = false,
onComplete = null) {
const { localVideo, remoteVideo }
= Filmstrip.calculateThumbnailSize();
Filmstrip.resizeThumbnails(localVideo, remoteVideo,
animate, forceUpdate)
.then(function () {
if (onComplete && typeof onComplete === "function")
onComplete();
2016-09-15 02:20:54 +00:00
});
2016-09-15 02:20:54 +00:00
return { localVideo, remoteVideo };
2015-12-14 12:26:50 +00:00
},
/**
* On audio muted event.
*/
2016-01-06 22:39:13 +00:00
onAudioMute (id, isMuted) {
if (APP.conference.isLocalId(id)) {
2015-06-23 08:00:46 +00:00
localVideoThumbnail.showAudioIndicator(isMuted);
} else {
let remoteVideo = remoteVideos[id];
if (!remoteVideo)
return;
remoteVideo.showAudioIndicator(isMuted);
2016-01-06 22:39:13 +00:00
if (APP.conference.isModerator) {
remoteVideo.updateRemoteVideoMenu(isMuted);
2015-06-23 08:00:46 +00:00
}
}
2015-12-14 12:26:50 +00:00
},
/**
* On video muted event.
*/
2016-01-06 22:39:13 +00:00
onVideoMute (id, value) {
if (APP.conference.isLocalId(id)) {
2016-09-28 21:31:40 +00:00
localVideoThumbnail.setVideoMutedView(value);
} else {
let remoteVideo = remoteVideos[id];
if (remoteVideo)
2016-09-28 21:31:40 +00:00
remoteVideo.setVideoMutedView(value);
}
2016-02-10 15:16:55 +00:00
if (this.isCurrentlyOnLarge(id)) {
// large video will show avatar instead of muted stream
this.updateLargeVideo(id, true);
}
2015-12-14 12:26:50 +00:00
},
/**
* Display name changed.
*/
2015-12-14 12:26:50 +00:00
onDisplayNameChanged (id, displayName, status) {
2015-12-01 13:41:58 +00:00
if (id === 'localVideoContainer' ||
APP.conference.isLocalId(id)) {
2015-06-23 08:00:46 +00:00
localVideoThumbnail.setDisplayName(displayName);
} else {
let remoteVideo = remoteVideos[id];
if (remoteVideo)
remoteVideo.setDisplayName(displayName, status);
}
2015-12-14 12:26:50 +00:00
},
2016-06-20 21:13:17 +00:00
/**
* Sets the "raised hand" status for a participant identified by 'id'.
*/
setRaisedHandStatus(id, raisedHandStatus) {
var video
= APP.conference.isLocalId(id)
? localVideoThumbnail : remoteVideos[id];
if (video) {
video.showRaisedHandIndicator(raisedHandStatus);
if (raisedHandStatus) {
video.showDominantSpeakerIndicator(false);
}
2016-06-20 21:13:17 +00:00
}
},
/**
* On dominant speaker changed event.
*/
2015-12-14 12:26:50 +00:00
onDominantSpeakerChanged (id) {
if (id === currentDominantSpeaker) {
return;
2014-09-03 08:57:41 +00:00
}
let oldSpeakerRemoteVideo = remoteVideos[currentDominantSpeaker];
// We ignore local user events, but just unmark remote user as dominant
// while we are talking
if (APP.conference.isLocalId(id)) {
if(oldSpeakerRemoteVideo)
{
2016-06-20 21:13:17 +00:00
oldSpeakerRemoteVideo.showDominantSpeakerIndicator(false);
currentDominantSpeaker = null;
}
2016-06-20 21:13:17 +00:00
localVideoThumbnail.showDominantSpeakerIndicator(true);
return;
}
2015-12-14 12:26:50 +00:00
let remoteVideo = remoteVideos[id];
2015-12-14 12:26:50 +00:00
if (!remoteVideo) {
return;
2015-12-14 12:26:50 +00:00
}
// Update the current dominant speaker.
2016-06-20 21:13:17 +00:00
remoteVideo.showDominantSpeakerIndicator(true);
localVideoThumbnail.showDominantSpeakerIndicator(false);
2015-12-14 12:26:50 +00:00
// let's remove the indications from the remote video if any
if (oldSpeakerRemoteVideo) {
2016-06-20 21:13:17 +00:00
oldSpeakerRemoteVideo.showDominantSpeakerIndicator(false);
2015-12-14 12:26:50 +00:00
}
currentDominantSpeaker = id;
// Local video will not have container found, but that's ok
// since we don't want to switch to local video.
// Update the large video if the video source is already available,
// otherwise wait for the "videoactive.jingle" event.
2016-11-08 02:45:52 +00:00
// FIXME: there is no "videoactive.jingle" event.
if (!interfaceConfig.filmStripOnly && !this.getPinnedId()
&& remoteVideo.hasVideoStarted()
&& !this.getCurrentlyOnLargeContainer().stayOnStage()) {
this.updateLargeVideo(id);
}
2015-12-14 12:26:50 +00:00
},
/**
* Shows/hides warning about remote user's connectivity issues.
*
* @param {string} id the ID of the remote participant(MUC nickname)
*/
// eslint-disable-next-line no-unused-vars
onParticipantConnectionStatusChanged (id) {
// Show/hide warning on the large video
if (this.isCurrentlyOnLarge(id)) {
if (largeVideo) {
// We have to trigger full large video update to transition from
// avatar to video on connectivity restored.
this.updateLargeVideo(id, true /* force update */);
}
}
// Show/hide warning on the thumbnail
let remoteVideo = remoteVideos[id];
if (remoteVideo) {
// Updating only connection status indicator is not enough, because
// when we the connection is restored while the avatar was displayed
// (due to 'muted while disconnected' condition) we may want to show
// the video stream again and in order to do that the display mode
// must be updated.
//remoteVideo.updateConnectionStatusIndicator(isActive);
remoteVideo.updateView();
}
},
/**
* On last N change event.
*
* @param endpointsLeavingLastN the list currently leaving last N
* endpoints
* @param endpointsEnteringLastN the list currently entering last N
* endpoints
*/
onLastNEndpointsChanged (endpointsLeavingLastN, endpointsEnteringLastN) {
if (endpointsLeavingLastN) {
endpointsLeavingLastN.forEach(this._updateRemoteVideo, this);
}
if (endpointsEnteringLastN) {
endpointsEnteringLastN.forEach(this._updateRemoteVideo, this);
}
},
/**
* Updates remote video by id if it exists.
* @param {string} id of the remote video
* @private
*/
_updateRemoteVideo(id) {
const remoteVideo = remoteVideos[id];
if (remoteVideo) {
remoteVideo.updateView();
if (remoteVideo.isCurrentlyOnLargeVideo()) {
this.updateLargeVideo(id);
}
}
2015-12-14 12:26:50 +00:00
},
/**
* Hides the connection indicator
2015-12-14 15:40:30 +00:00
* @param id
*/
2015-12-14 15:40:30 +00:00
hideConnectionIndicator (id) {
let remoteVideo = remoteVideos[id];
if (remoteVideo)
remoteVideo.removeConnectionIndicator();
2015-12-14 12:26:50 +00:00
},
/**
* Hides all the indicators
*/
2015-12-14 12:26:50 +00:00
hideStats () {
for (var video in remoteVideos) {
let remoteVideo = remoteVideos[video];
if (remoteVideo)
remoteVideo.removeConnectionIndicator();
}
localVideoThumbnail.removeConnectionIndicator();
2015-12-14 12:26:50 +00:00
},
2015-12-14 15:40:30 +00:00
removeParticipantContainer (id) {
// Unlock large video
if (this.getPinnedId() === id) {
2016-11-11 15:00:54 +00:00
logger.info("Focused video owner has left the conference");
this.pinParticipant(null);
}
2015-12-14 12:26:50 +00:00
if (currentDominantSpeaker === id) {
2016-11-11 15:00:54 +00:00
logger.info("Dominant speaker has left the conference");
currentDominantSpeaker = null;
}
2015-12-14 12:26:50 +00:00
var remoteVideo = remoteVideos[id];
if (remoteVideo) {
// Remove remote video
2016-11-11 15:00:54 +00:00
logger.info("Removing remote video: " + id);
2015-12-14 12:26:50 +00:00
delete remoteVideos[id];
remoteVideo.remove();
} else {
2016-11-11 15:00:54 +00:00
logger.warn("No remote video for " + id);
}
VideoLayout.resizeThumbnails();
2015-12-14 12:26:50 +00:00
},
2015-11-30 11:54:54 +00:00
2015-12-14 12:26:50 +00:00
onVideoTypeChanged (id, newVideoType) {
if (VideoLayout.getRemoteVideoType(id) === newVideoType) {
return;
}
2016-11-11 15:00:54 +00:00
logger.info("Peer video type changed: ", id, newVideoType);
var smallVideo;
2015-12-14 12:26:50 +00:00
if (APP.conference.isLocalId(id)) {
if (!localVideoThumbnail) {
2016-11-11 15:00:54 +00:00
logger.warn("Local video not ready yet");
return;
}
smallVideo = localVideoThumbnail;
2015-12-14 12:26:50 +00:00
} else if (remoteVideos[id]) {
smallVideo = remoteVideos[id];
} else {
return;
}
smallVideo.setVideoType(newVideoType);
2015-12-25 16:55:45 +00:00
if (this.isCurrentlyOnLarge(id)) {
this.updateLargeVideo(id, true);
}
2015-12-14 12:26:50 +00:00
},
2015-11-13 17:04:49 +00:00
2015-06-23 08:00:46 +00:00
/**
2015-11-13 17:04:49 +00:00
* Resizes the video area.
*
* @param forceUpdate indicates that hidden thumbnails will be shown
* @param completeFunction a function to be called when the video area is
* resized.
*/
resizeVideoArea (forceUpdate = false,
animate = false,
completeFunction = null) {
2015-12-25 16:55:45 +00:00
if (largeVideo) {
largeVideo.updateContainerSize();
2015-12-25 16:55:45 +00:00
largeVideo.resize(animate);
}
// Calculate available width and height.
2016-01-20 14:26:39 +00:00
let availableHeight = window.innerHeight;
let availableWidth = UIUtil.getAvailableVideoWidth();
2016-01-20 14:26:39 +00:00
if (availableWidth < 0 || availableHeight < 0) {
return;
}
// Resize the thumbnails first.
this.resizeThumbnails(false, forceUpdate);
// Resize the video area element.
2016-01-20 14:26:39 +00:00
$('#videospace').animate({
right: window.innerWidth - availableWidth,
width: availableWidth,
height: availableHeight
}, {
queue: false,
duration: animate ? 500 : 1,
complete: completeFunction
});
2015-12-14 12:26:50 +00:00
},
2015-12-14 12:26:50 +00:00
getSmallVideo (id) {
if (APP.conference.isLocalId(id)) {
2015-06-23 08:00:46 +00:00
return localVideoThumbnail;
} else {
2015-12-14 12:26:50 +00:00
return remoteVideos[id];
2015-06-23 08:00:46 +00:00
}
2015-12-14 12:26:50 +00:00
},
changeUserAvatar (id, avatarUrl) {
2015-12-02 15:24:57 +00:00
var smallVideo = VideoLayout.getSmallVideo(id);
if (smallVideo) {
smallVideo.avatarChanged(avatarUrl);
2015-12-02 15:24:57 +00:00
} else {
2016-11-11 15:00:54 +00:00
logger.warn(
2015-12-02 15:24:57 +00:00
"Missed avatar update - no small video yet for " + id
);
}
2015-12-25 16:55:45 +00:00
if (this.isCurrentlyOnLarge(id)) {
largeVideo.updateAvatar(avatarUrl);
2015-12-25 16:55:45 +00:00
}
2015-12-14 12:26:50 +00:00
},
2015-08-03 16:21:56 +00:00
/**
* Indicates that the video has been interrupted.
*/
2015-12-14 12:26:50 +00:00
onVideoInterrupted () {
if (largeVideo) {
largeVideo.onVideoInterrupted();
}
2015-12-14 12:26:50 +00:00
},
2015-08-03 15:58:22 +00:00
2015-08-03 16:21:56 +00:00
/**
* Indicates that the video has been restored.
*/
2015-12-14 12:26:50 +00:00
onVideoRestored () {
if (largeVideo) {
largeVideo.onVideoRestored();
2015-12-25 16:55:45 +00:00
}
},
isLargeVideoVisible () {
return this.isLargeContainerTypeVisible(VIDEO_CONTAINER_TYPE);
2015-12-25 16:55:45 +00:00
},
/**
* @return {LargeContainer} the currently displayed container on large
* video.
*/
getCurrentlyOnLargeContainer () {
return largeVideo.getCurrentContainer();
},
2015-12-25 16:55:45 +00:00
isCurrentlyOnLarge (id) {
return largeVideo && largeVideo.id === id;
},
/**
* Triggers an update of remote video and large video displays so they may
* pick up any state changes that have occurred elsewhere.
*
* @returns {void}
*/
updateAllVideos() {
const displayedUserId = this.getLargeVideoID();
if (displayedUserId) {
this.updateLargeVideo(displayedUserId, true);
}
Object.keys(remoteVideos).forEach(video => {
remoteVideos[video].updateView();
});
},
2015-12-25 16:55:45 +00:00
updateLargeVideo (id, forceUpdate) {
if (!largeVideo) {
return;
}
const currentContainer = largeVideo.getCurrentContainer();
const currentContainerType = largeVideo.getCurrentContainerType();
const currentId = largeVideo.id;
const isOnLarge = this.isCurrentlyOnLarge(id);
const smallVideo = this.getSmallVideo(id);
if (isOnLarge && !forceUpdate
&& LargeVideoManager.isVideoContainer(currentContainerType)
&& smallVideo) {
const currentStreamId = currentContainer.getStreamID();
const newStreamId
= smallVideo.videoStream
? smallVideo.videoStream.getId() : null;
// FIXME it might be possible to get rid of 'forceUpdate' argument
if (currentStreamId !== newStreamId) {
logger.debug('Enforcing large video update for stream change');
forceUpdate = true;
}
}
2015-12-25 16:55:45 +00:00
if (!isOnLarge || forceUpdate) {
let videoType = this.getRemoteVideoType(id);
// FIXME video type is not the same thing as container type
if (id !== currentId && videoType === VIDEO_CONTAINER_TYPE) {
2015-12-25 16:55:45 +00:00
eventEmitter.emit(UIEvents.SELECTED_ENDPOINT, id);
}
2016-07-08 20:14:49 +00:00
let oldSmallVideo;
2015-12-25 16:55:45 +00:00
if (currentId) {
2016-07-08 20:14:49 +00:00
oldSmallVideo = this.getSmallVideo(currentId);
2015-12-25 16:55:45 +00:00
}
2016-07-08 20:14:49 +00:00
smallVideo.waitForResolutionChange();
if (oldSmallVideo)
oldSmallVideo.waitForResolutionChange();
2015-12-25 16:55:45 +00:00
largeVideo.updateLargeVideo(
id,
smallVideo.videoStream,
videoType
).then(function() {
// update current small video and the old one
smallVideo.updateView();
oldSmallVideo && oldSmallVideo.updateView();
}, function () {
// use clicked other video during update, nothing to do.
});
2015-12-25 16:55:45 +00:00
} else if (currentId) {
let currentSmallVideo = this.getSmallVideo(currentId);
currentSmallVideo.updateView();
2015-12-25 16:55:45 +00:00
}
},
addLargeVideoContainer (type, container) {
largeVideo && largeVideo.addContainer(type, container);
},
removeLargeVideoContainer (type) {
largeVideo && largeVideo.removeContainer(type);
},
/**
* @returns Promise
*/
showLargeVideoContainer (type, show) {
if (!largeVideo) {
return Promise.reject();
}
let isVisible = this.isLargeContainerTypeVisible(type);
if (isVisible === show) {
return Promise.resolve();
}
let currentId = largeVideo.id;
if(currentId) {
var oldSmallVideo = this.getSmallVideo(currentId);
}
let containerTypeToShow = type;
// 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
if (!show) {
const pinnedId = this.getPinnedId();
2016-03-24 18:16:42 +00:00
if(pinnedId)
containerTypeToShow = this.getRemoteVideoType(pinnedId);
else
containerTypeToShow = VIDEO_CONTAINER_TYPE;
}
return largeVideo.showContainer(containerTypeToShow)
.then(() => {
if(oldSmallVideo)
oldSmallVideo && oldSmallVideo.updateView();
});
2015-12-25 16:55:45 +00:00
},
isLargeContainerTypeVisible (type) {
return largeVideo && largeVideo.state === type;
},
/**
* Returns the id of the current video shown on large.
* Currently used by tests (torture).
*/
getLargeVideoID () {
return largeVideo.id;
},
/**
* Returns the the current video shown on large.
* Currently used by tests (torture).
*/
getLargeVideo () {
return largeVideo;
},
/**
* Sets the flipX state of the local video.
* @param {boolean} true for flipped otherwise false;
*/
setLocalFlipX (val) {
this.localFlipX = val;
},
getEventEmitter() {return eventEmitter;},
/**
* Handles user's features changes.
*/
onUserFeaturesChanged (user) {
let video = this.getSmallVideo(user.getId());
if (!video) {
return;
}
this._setRemoteControlProperties(user, video);
2016-07-08 20:14:49 +00:00
},
/**
* Sets the remote control properties (checks whether remote control
* is supported and executes remoteVideo.setRemoteControlSupport).
* @param {JitsiParticipant} user the user that will be checked for remote
* control support.
* @param {RemoteVideo} remoteVideo the remoteVideo on which the properties
* will be set.
*/
_setRemoteControlProperties (user, remoteVideo) {
APP.remoteControl.checkUserRemoteControlSupport(user).then(result =>
remoteVideo.setRemoteControlSupport(result));
},
/**
* Returns the wrapper jquery selector for the largeVideo
* @returns {JQuerySelector} the wrapper jquery selector for the largeVideo
*/
getLargeVideoWrapper() {
return this.getCurrentlyOnLargeContainer().$wrapper;
},
/**
* Returns the number of remove video ids.
*
* @returns {number} The number of remote videos.
*/
getRemoteVideosCount() {
return Object.keys(remoteVideos).length;
}
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;