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

1024 lines
33 KiB
JavaScript
Raw Normal View History

2016-02-10 15:16:55 +00:00
/* global config, APP, $, interfaceConfig, JitsiMeetJS */
/* jshint -W101 */
2015-12-14 12:26:50 +00:00
import AudioLevels from "../audio_levels/AudioLevels";
import Avatar from "../avatar/Avatar";
2015-12-25 16:55:45 +00:00
import BottomToolbar from "../toolbars/BottomToolbar";
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";
2015-12-25 16:55:45 +00:00
import LargeVideoManager, {VideoContainerType} from "./LargeVideo";
import {PreziContainerType} from '../prezi/Prezi';
2015-12-14 12:26:50 +00:00
import LocalVideo from "./LocalVideo";
2016-02-02 21:50:02 +00:00
const RTCUIUtil = JitsiMeetJS.util.RTCUIHelper;
2015-06-23 08:00:46 +00:00
var remoteVideos = {};
var remoteVideoTypes = {};
2015-06-23 08:00:46 +00:00
var localVideoThumbnail = null;
2015-01-07 14:54:03 +00:00
var currentDominantSpeaker = null;
var lastNCount = config.channelLastN;
var localLastNCount = config.channelLastN;
var localLastNSet = [];
var lastNEndpointsCache = [];
2015-12-14 12:26:50 +00:00
var lastNPickupId = null;
var eventEmitter = null;
2015-01-07 14:54:03 +00:00
/**
2015-06-23 08:00:46 +00:00
* Currently focused video jid
* @type {String}
2015-01-07 14:54:03 +00:00
*/
2015-06-23 08:00:46 +00:00
var focusedVideoResourceJid = null;
2015-12-30 10:55:51 +00:00
const thumbAspectRatio = 16.0 / 9.0;
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(false, id);
} 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.
lastNPickupId = id;
eventEmitter.emit(UIEvents.PINNED_ENDPOINT, id);
}
}
2015-12-14 15:40:30 +00:00
}
2015-12-14 12:26:50 +00:00
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;
2015-12-01 12:53:01 +00:00
localVideoThumbnail = new LocalVideo(VideoLayout, emitter);
2015-12-14 15:40:30 +00:00
emitter.addListener(UIEvents.CONTACT_CLICKED, onContactClicked);
2015-12-14 12:26:50 +00:00
},
2015-12-25 16:55:45 +00:00
initLargeVideo (isSideBarVisible) {
largeVideo = new LargeVideoManager();
largeVideo.updateContainerSize(isSideBarVisible);
AudioLevels.init();
},
setAudioLevel(id, lvl) {
if (!largeVideo) {
return;
}
AudioLevels.updateAudioLevel(
id, lvl, largeVideo.id
);
},
2015-12-14 12:26:50 +00:00
isInLastN (resource) {
return lastNCount < 0 || // lastN is disabled
// lastNEndpoints cache not built yet
2015-09-11 03:26:29 +00:00
(lastNCount > 0 && !lastNEndpointsCache.length) ||
(lastNEndpointsCache &&
lastNEndpointsCache.indexOf(resource) !== -1);
2015-12-14 12:26:50 +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) {
// Set default display name.
2015-06-23 08:00:46 +00:00
localVideoThumbnail.setDisplayName();
localVideoThumbnail.createConnectionIndicator();
2015-12-14 12:26:50 +00:00
let localId = APP.conference.localId;
2015-12-30 12:14:56 +00:00
this.onVideoTypeChanged(localId, stream.videoType);
2015-12-30 10:55:51 +00:00
let {thumbWidth, thumbHeight} = this.calculateThumbnailSize();
AudioLevels.updateAudioLevelCanvas(
null, thumbWidth, thumbHeight);
2015-12-31 15:23:23 +00:00
if (!stream.isMuted()) {
localVideoThumbnail.changeVideo(stream);
}
/* force update if we're currently being displayed */
2015-12-25 16:55:45 +00:00
if (this.isCurrentlyOnLarge(localId)) {
this.updateLargeVideo(localId, true);
}
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) {
this.updateLargeVideo(APP.conference.localId, true);
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
},
/**
2014-06-19 13:40:54 +00:00
* Checks if removed video is currently displayed and tries to display
* another one instead.
*/
2015-12-14 12:26:50 +00:00
updateRemovedVideo (id) {
2015-12-25 16:55:45 +00:00
if (!this.isCurrentlyOnLarge(id)) {
2015-12-14 14:51:02 +00:00
return;
}
2015-12-14 12:26:50 +00:00
let newId;
2015-12-14 14:51:02 +00:00
// We'll show user's avatar if he is the dominant speaker or if
// his video thumbnail is pinned
if (remoteVideos[id] && (id === focusedVideoResourceJid
|| id === currentDominantSpeaker)) {
2015-12-14 14:51:02 +00:00
newId = id;
} else {
// Otherwise select last visible video
newId = this.electLastVisibleVideo();
}
2015-12-14 14:51:02 +00:00
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
2015-12-30 12:14:56 +00:00
let thumbs = BottomToolbar.getThumbs(true).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]) {
console.info("electLastVisibleVideo: " + id);
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
console.info("Last visible video no longer exists");
2015-12-30 10:55:51 +00:00
thumbs = BottomToolbar.getThumbs();
if (thumbs.length) {
let id = getPeerContainerResourceId(thumbs[0]);
2015-12-14 14:51:02 +00:00
if (remoteVideos[id]) {
console.info("electLastVisibleVideo: " + id);
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
console.info("Fallback to local video...");
2015-12-14 14:51:02 +00:00
let id = APP.conference.localId;
console.info("electLastVisibleVideo: " + id);
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();
remoteVideos[id].addRemoteStreamElement(stream);
// if track is muted make sure we reflect that
if(stream.isMuted())
{
if(stream.getType() === "audio")
this.onAudioMute(stream.getParticipantId(), true);
else
this.onVideoMute(stream.getParticipantId(), true);
}
2015-12-14 12:26:50 +00:00
},
onRemoteStreamRemoved (stream) {
let id = stream.getParticipantId();
let remoteVideo = remoteVideos[id];
if (remoteVideo) { // remote stream may be removed after participant left the conference
remoteVideo.removeRemoteStreamElement(stream);
}
},
/**
* Return the type of the remote video.
2015-12-14 12:26:50 +00:00
* @param id the id for the remote video
* @returns the video type video or screen.
*/
2015-12-14 12:26:50 +00:00
getRemoteVideoType (id) {
return remoteVideoTypes[id];
},
2015-12-14 12:26:50 +00:00
handleVideoThumbClicked (noPinnedEndpointChangedEvent,
resourceJid) {
2015-06-23 08:00:46 +00:00
if(focusedVideoResourceJid) {
2015-11-13 17:04:49 +00:00
var oldSmallVideo
= VideoLayout.getSmallVideo(focusedVideoResourceJid);
if (oldSmallVideo && !interfaceConfig.filmStripOnly)
2015-06-23 08:00:46 +00:00
oldSmallVideo.focus(false);
}
2015-06-23 08:00:46 +00:00
var smallVideo = VideoLayout.getSmallVideo(resourceJid);
2014-11-24 11:00:15 +00:00
// Unlock current focused.
2015-06-23 08:00:46 +00:00
if (focusedVideoResourceJid === resourceJid)
{
2015-06-23 08:00:46 +00:00
focusedVideoResourceJid = null;
// Enable the currently set dominant speaker.
if (currentDominantSpeaker) {
if(smallVideo && smallVideo.hasVideo()) {
2015-12-25 16:55:45 +00:00
this.updateLargeVideo(currentDominantSpeaker);
}
}
if (!noPinnedEndpointChangedEvent) {
eventEmitter.emit(UIEvents.PINNED_ENDPOINT);
}
return;
}
// Lock new video
2015-06-23 08:00:46 +00:00
focusedVideoResourceJid = resourceJid;
// Update focused/pinned interface.
if (resourceJid) {
if (smallVideo && !interfaceConfig.filmStripOnly)
2015-06-23 08:00:46 +00:00
smallVideo.focus(true);
if (!noPinnedEndpointChangedEvent) {
eventEmitter.emit(UIEvents.PINNED_ENDPOINT, resourceJid);
}
}
2015-12-25 16:55:45 +00:00
this.updateLargeVideo(resourceJid);
2015-12-14 12:26:50 +00:00
},
/**
2015-12-14 12:26:50 +00:00
* Checks if container for participant identified by given id exists
* in the document and creates it eventually.
2015-11-30 11:54:54 +00:00
*
* @return Returns <tt>true</tt> if the peer container exists,
* <tt>false</tt> - otherwise
*/
2015-12-14 15:40:30 +00:00
addParticipantContainer (id) {
2015-12-14 12:26:50 +00:00
let remoteVideo = new RemoteVideo(id, VideoLayout, eventEmitter);
remoteVideos[id] = remoteVideo;
2015-12-14 12:26:50 +00:00
let videoType = remoteVideoTypes[id];
if (videoType) {
remoteVideo.setVideoType(videoType);
}
2015-12-14 12:26:50 +00:00
// In case this is not currently in the last n we don't show it.
if (localLastNCount && localLastNCount > 0 &&
2015-12-30 10:55:51 +00:00
BottomToolbar.getThumbs().length >= localLastNCount + 2) {
2015-12-14 12:26:50 +00:00
remoteVideo.showPeerContainer('hide');
} else {
VideoLayout.resizeThumbnails(false, true);
}
2015-12-14 12:26:50 +00:00
},
2015-12-14 12:26:50 +00:00
videoactive (videoelem, resourceJid) {
console.info(resourceJid + " video is now active", videoelem);
$(videoelem).show();
2015-06-23 08:00:46 +00:00
VideoLayout.resizeThumbnails();
// Update the large video to the last added video only if there's no
// current dominant, focused speaker or prezi playing or update it to
// the current dominant speaker.
if ((!focusedVideoResourceJid &&
!currentDominantSpeaker &&
2015-12-25 16:55:45 +00:00
!this.isLargeContainerTypeVisible(PreziContainerType)) ||
focusedVideoResourceJid === resourceJid ||
2015-06-23 08:00:46 +00:00
(resourceJid &&
currentDominantSpeaker === resourceJid)) {
2015-12-25 16:55:45 +00:00
this.updateLargeVideo(resourceJid, true);
}
2015-12-14 12:26:50 +00:00
},
/**
* Shows the presence status message for the given video.
*/
2016-01-25 22:39:05 +00:00
setPresenceStatus (id, statusMsg) {
remoteVideos[id].setPresenceStatus(statusMsg);
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) {
2015-06-23 08:00:46 +00:00
localVideoThumbnail.createModeratorIndicatorElement();
}
2015-12-14 12:26:50 +00:00
APP.conference.listMembers().forEach(function (member) {
let id = member.getId();
if (member.isModerator()) {
remoteVideos[id].removeRemoteVideoMenu();
remoteVideos[id].createModeratorIndicatorElement();
} else if (isModerator) {
// We are moderator, but user is not - add menu
2015-12-14 12:26:50 +00:00
if ($(`#remote_popupmenu_${id}`).length <= 0) {
remoteVideos[id].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
},
/**
* Resizes the large video container.
*/
resizeLargeVideoContainer (isSideBarVisible, forceUpdate) {
2016-01-20 14:26:39 +00:00
let animate = false;
2015-12-25 16:55:45 +00:00
if (largeVideo) {
largeVideo.updateContainerSize(isSideBarVisible);
2016-01-20 14:26:39 +00:00
largeVideo.resize(animate);
}
2016-01-20 14:26:39 +00:00
this.resizeVideoSpace(animate, isSideBarVisible);
this.resizeThumbnails(false, forceUpdate);
2015-12-14 12:26:50 +00:00
},
/**
* Resizes thumbnails.
*/
resizeThumbnails (animate = false, forceUpdate = false) {
2015-12-30 10:55:51 +00:00
let {thumbWidth, thumbHeight} = this.calculateThumbnailSize();
2015-12-30 10:55:51 +00:00
$('.userAvatar').css('left', (thumbWidth - thumbHeight) / 2);
BottomToolbar.resizeThumbnails(thumbWidth, thumbHeight,
animate, forceUpdate)
.then(function () {
BottomToolbar.resizeToolbar(thumbWidth, thumbHeight);
AudioLevels.updateCanvasSize(thumbWidth, thumbHeight);
2015-12-25 16:55:45 +00:00
});
2015-12-14 12:26:50 +00:00
},
/**
* Calculates the thumbnail size.
*
*/
2015-12-30 10:55:51 +00:00
calculateThumbnailSize () {
let videoSpaceWidth = BottomToolbar.getFilmStripWidth();
2015-11-13 17:04:49 +00:00
// Calculate the available height, which is the inner window height
// minus 39px for the header minus 2px for the delimiter lines on the
// top and bottom of the large video, minus the 36px space inside the
// remoteVideos container used for highlighting shadow.
2015-12-30 10:55:51 +00:00
let availableHeight = 100;
2015-12-30 10:55:51 +00:00
let numvids = BottomToolbar.getThumbs().length;
2014-11-19 10:08:38 +00:00
if (localLastNCount && localLastNCount > 0) {
numvids = Math.min(localLastNCount + 1, numvids);
}
2015-12-30 10:55:51 +00:00
// Remove the 3px borders arround videos and border around the remote
// videos area and the 4 pixels between the local video and the others
//TODO: Find out where the 4 pixels come from and remove them
let availableWinWidth = videoSpaceWidth - 2 * 3 * numvids - 70 - 4;
2015-12-30 10:55:51 +00:00
let availableWidth = availableWinWidth / numvids;
let maxHeight = Math.min(160, availableHeight);
availableHeight
= Math.min( maxHeight,
availableWidth / thumbAspectRatio,
window.innerHeight - 18);
2015-11-13 17:04:49 +00:00
2015-12-30 10:55:51 +00:00
if (availableHeight < availableWidth / thumbAspectRatio) {
availableWidth = Math.floor(availableHeight * thumbAspectRatio);
}
2015-12-30 10:55:51 +00:00
return {
thumbWidth: availableWidth,
thumbHeight: availableHeight
};
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 {
2016-01-06 22:39:13 +00:00
remoteVideos[id].showAudioIndicator(isMuted);
if (APP.conference.isModerator) {
remoteVideos[id].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)) {
localVideoThumbnail.setMutedView(value);
} else {
2016-01-06 22:39:13 +00:00
var remoteVideo = remoteVideos[id];
remoteVideo.setMutedView(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 {
2015-12-01 13:41:58 +00:00
remoteVideos[id].setDisplayName(displayName, status);
}
2015-12-14 12:26:50 +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)
{
oldSpeakerRemoteVideo.updateDominantSpeakerIndicator(false);
localVideoThumbnail.updateDominantSpeakerIndicator(true);
currentDominantSpeaker = null;
}
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.
remoteVideo.updateDominantSpeakerIndicator(true);
localVideoThumbnail.updateDominantSpeakerIndicator(false);
2015-12-14 12:26:50 +00:00
// let's remove the indications from the remote video if any
if (oldSpeakerRemoteVideo) {
oldSpeakerRemoteVideo.updateDominantSpeakerIndicator(false);
}
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.
if (!focusedVideoResourceJid && remoteVideo.hasVideoStarted()) {
this.updateLargeVideo(id);
}
2015-12-14 12:26:50 +00:00
},
/**
* On last N change event.
*
* @param lastNEndpoints the list of last N endpoints
* @param endpointsEnteringLastN the list currently entering last N
* endpoints
*/
2015-12-14 12:26:50 +00:00
onLastNEndpointsChanged (lastNEndpoints, endpointsEnteringLastN) {
if (lastNCount !== lastNEndpoints.length)
lastNCount = lastNEndpoints.length;
lastNEndpointsCache = lastNEndpoints;
2014-11-19 10:08:38 +00:00
// Say A, B, C, D, E, and F are in a conference and LastN = 3.
//
// If LastN drops to, say, 2, because of adaptivity, then E should see
// thumbnails for A, B and C. A and B are in E's server side LastN set,
// so E sees them. C is only in E's local LastN set.
//
// If F starts talking and LastN = 3, then E should see thumbnails for
// F, A, B. B gets "ejected" from E's server side LastN set, but it
// enters E's local LastN ejecting C.
// Increase the local LastN set size, if necessary.
if (lastNCount > localLastNCount) {
localLastNCount = lastNCount;
}
// Update the local LastN set preserving the order in which the
// endpoints appeared in the LastN/local LastN set.
var nextLocalLastNSet = lastNEndpoints.slice(0);
for (var i = 0; i < localLastNSet.length; i++) {
if (nextLocalLastNSet.length >= localLastNCount) {
break;
}
var resourceJid = localLastNSet[i];
if (nextLocalLastNSet.indexOf(resourceJid) === -1) {
nextLocalLastNSet.push(resourceJid);
}
}
localLastNSet = nextLocalLastNSet;
var updateLargeVideo = false;
2014-11-19 10:08:38 +00:00
// Handle LastN/local LastN changes.
BottomToolbar.getThumbs().each(( index, element ) => {
2015-12-14 14:51:02 +00:00
var resourceJid = getPeerContainerResourceId(element);
var smallVideo = remoteVideos[resourceJid];
// We do not want to process any logic for our own(local) video
// because the local participant is never in the lastN set.
// The code of this function might detect that the local participant
// has been dropped out of the lastN set and will update the large
// video
// Detected from avatar tests, where lastN event override
// local video pinning
2016-01-06 22:39:13 +00:00
if(APP.conference.isLocalId(resourceJid))
return;
2014-11-19 10:08:38 +00:00
var isReceived = true;
if (resourceJid &&
lastNEndpoints.indexOf(resourceJid) < 0 &&
localLastNSet.indexOf(resourceJid) < 0) {
console.log("Remove from last N", resourceJid);
if (smallVideo)
smallVideo.showPeerContainer('hide');
2016-01-06 22:39:13 +00:00
else if (!APP.conference.isLocalId(resourceJid))
2015-08-24 09:37:23 +00:00
console.error("No remote video for: " + resourceJid);
2014-11-19 10:08:38 +00:00
isReceived = false;
} else if (resourceJid &&
smallVideo.isVisible() &&
lastNEndpoints.indexOf(resourceJid) < 0 &&
localLastNSet.indexOf(resourceJid) >= 0) {
if (smallVideo)
smallVideo.showPeerContainer('avatar');
2016-01-06 22:39:13 +00:00
else if (!APP.conference.isLocalId(resourceJid))
2015-08-24 09:37:23 +00:00
console.error("No remote video for: " + resourceJid);
2014-11-19 10:08:38 +00:00
isReceived = false;
}
2014-11-20 15:40:58 +00:00
2014-11-19 10:08:38 +00:00
if (!isReceived) {
2014-11-20 15:40:58 +00:00
// resourceJid has dropped out of the server side lastN set, so
// it is no longer being received. If resourceJid was being
// displayed in the large video we have to switch to another
// user.
if (!updateLargeVideo &&
2015-12-25 16:55:45 +00:00
this.isCurrentlyOnLarge(resourceJid)) {
updateLargeVideo = true;
2014-11-20 15:40:58 +00:00
}
}
});
if (!endpointsEnteringLastN || endpointsEnteringLastN.length < 0)
endpointsEnteringLastN = lastNEndpoints;
if (endpointsEnteringLastN && endpointsEnteringLastN.length > 0) {
endpointsEnteringLastN.forEach(function (resourceJid) {
var remoteVideo = remoteVideos[resourceJid];
remoteVideo.showPeerContainer('show');
if (!remoteVideo.isVisible()) {
console.log("Add to last N", resourceJid);
remoteVideo.addRemoteStreamElement(remoteVideo.videoStream);
if (lastNPickupId == resourceJid) {
2015-12-14 12:26:50 +00:00
// Clean up the lastN pickup id.
lastNPickupId = null;
// Don't fire the events again, they've already
// been fired in the contact list click handler.
VideoLayout.handleVideoThumbClicked(
false,
resourceJid);
updateLargeVideo = false;
}
remoteVideo.waitForPlayback(
remoteVideo.selectVideoElement()[0],
remoteVideo.videoStream);
}
});
}
// The endpoint that was being shown in the large video has dropped out
// of the lastN set and there was no lastN pickup jid. We need to update
// the large video now.
if (updateLargeVideo) {
var resource;
// Find out which endpoint to show in the large video.
for (i = 0; i < lastNEndpoints.length; i++) {
resource = lastNEndpoints[i];
2016-01-06 22:39:13 +00:00
if (!resource || APP.conference.isLocalId(resource))
continue;
// videoSrcToSsrc needs to be update for this call to succeed.
2015-12-25 16:55:45 +00:00
this.updateLargeVideo(resource);
break;
}
}
2015-12-14 12:26:50 +00:00
},
/**
* Updates local stats
* @param percent
* @param object
*/
2015-12-14 12:26:50 +00:00
updateLocalConnectionStats (percent, object) {
2016-01-29 15:33:16 +00:00
let resolutions = object.resolution;
object.resolution = resolutions[APP.conference.localId];
2015-06-23 08:00:46 +00:00
localVideoThumbnail.updateStatsIndicator(percent, object);
2015-12-29 12:41:43 +00:00
Object.keys(resolutions).forEach(function (id) {
if (APP.conference.isLocalId(id)) {
return;
}
2015-12-29 12:41:43 +00:00
let resolution = resolutions[id];
let remoteVideo = remoteVideos[id];
if (resolution && remoteVideo) {
remoteVideo.updateResolution(resolution);
}
});
2015-12-14 12:26:50 +00:00
},
/**
* Updates remote stats.
2015-12-14 15:40:30 +00:00
* @param id the id associated with the stats
* @param percent the connection quality percent
* @param object the stats data
*/
2015-12-14 15:40:30 +00:00
updateConnectionStats (id, percent, object) {
if (remoteVideos[id]) {
remoteVideos[id].updateStatsIndicator(percent, object);
}
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) {
remoteVideos[id].hideConnectionIndicator();
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) {
2015-06-26 12:32:40 +00:00
remoteVideos[video].hideIndicator();
}
2015-06-23 08:00:46 +00:00
localVideoThumbnail.hideIndicator();
2015-12-14 12:26:50 +00:00
},
2015-12-14 15:40:30 +00:00
removeParticipantContainer (id) {
// Unlock large video
2015-12-14 12:26:50 +00:00
if (focusedVideoResourceJid === id) {
console.info("Focused video owner has left the conference");
2015-06-23 08:00:46 +00:00
focusedVideoResourceJid = null;
}
2015-12-14 12:26:50 +00:00
if (currentDominantSpeaker === id) {
console.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
2015-12-14 12:26:50 +00:00
console.info("Removing remote video: " + id);
delete remoteVideos[id];
remoteVideo.remove();
} else {
2015-12-14 12:26:50 +00:00
console.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 (remoteVideoTypes[id] === newVideoType) {
return;
}
2015-12-14 12:26:50 +00:00
console.info("Peer video type changed: ", id, newVideoType);
remoteVideoTypes[id] = newVideoType;
var smallVideo;
2015-12-14 12:26:50 +00:00
if (APP.conference.isLocalId(id)) {
if (!localVideoThumbnail) {
console.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
2016-02-10 15:26:16 +00:00
showMore (id) {
if (id === 'local') {
2015-06-23 08:00:46 +00:00
localVideoThumbnail.connectionIndicator.showMore();
} else {
2016-02-10 15:26:16 +00:00
let remoteVideo = remoteVideos[id];
if (remoteVideo) {
remoteVideo.connectionIndicator.showMore();
} else {
2016-02-10 15:26:16 +00:00
console.info("Error - no remote video for id: " + id);
}
2015-06-23 08:00:46 +00:00
}
2015-12-14 12:26:50 +00:00
},
2015-12-25 16:55:45 +00:00
addRemoteVideoContainer (id) {
return RemoteVideo.createContainer(id);
2015-12-14 12:26:50 +00:00
},
2015-06-23 08:00:46 +00:00
/**
2015-11-13 17:04:49 +00:00
* Resizes the video area.
*
* @param isSideBarVisible indicates if the side bar is currently visible
* @param callback a function to be called when the video space is
* resized.
2015-06-23 08:00:46 +00:00
*/
2015-12-14 12:26:50 +00:00
resizeVideoArea (isSideBarVisible, callback) {
2015-12-25 16:55:45 +00:00
let animate = true;
if (largeVideo) {
largeVideo.updateContainerSize(isSideBarVisible);
largeVideo.resize(animate);
this.resizeVideoSpace(animate, isSideBarVisible, callback);
}
VideoLayout.resizeThumbnails(animate);
2015-12-14 12:26:50 +00:00
},
2015-06-23 08:00:46 +00:00
/**
* Resizes the #videospace html element
2015-11-13 17:04:49 +00:00
* @param animate boolean property that indicates whether the resize should
* be animated or not.
* @param isChatVisible boolean property that indicates whether the chat
* area is displayed or not.
* If that parameter is null the method will check the chat panel
* visibility.
* @param completeFunction a function to be called when the video space
* is resized.
*/
2015-12-14 12:26:50 +00:00
resizeVideoSpace (animate, isChatVisible, completeFunction) {
2016-01-20 14:26:39 +00:00
let availableHeight = window.innerHeight;
let availableWidth = UIUtil.getAvailableVideoWidth(isChatVisible);
if (availableWidth < 0 || availableHeight < 0) {
return;
}
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 {
console.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 () {
2015-12-25 16:55:45 +00:00
this.enableVideoProblemFilter(true);
let reconnectingKey = "connection.RECONNECTING";
2015-11-13 17:04:49 +00:00
$('#videoConnectionMessage')
2015-12-25 16:55:45 +00:00
.attr("data-i18n", reconnectingKey)
.text(APP.translation.translateString(reconnectingKey))
.css({display: "block"});
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 () {
2015-12-25 16:55:45 +00:00
this.enableVideoProblemFilter(false);
2015-08-03 15:58:22 +00:00
$('#videoConnectionMessage').css({display: "none"});
2015-12-25 16:55:45 +00:00
},
enableVideoProblemFilter (enable) {
if (!largeVideo) {
return;
}
largeVideo.enableVideoProblemFilter(enable);
},
isLargeVideoVisible () {
return this.isLargeContainerTypeVisible(VideoContainerType);
},
isCurrentlyOnLarge (id) {
return largeVideo && largeVideo.id === id;
},
updateLargeVideo (id, forceUpdate) {
if (!largeVideo) {
return;
}
let isOnLarge = this.isCurrentlyOnLarge(id);
let currentId = largeVideo.id;
if (!isOnLarge || forceUpdate) {
if (id !== currentId) {
eventEmitter.emit(UIEvents.SELECTED_ENDPOINT, id);
}
if (currentId) {
var oldSmallVideo = this.getSmallVideo(currentId);
2015-12-25 16:55:45 +00:00
}
let smallVideo = this.getSmallVideo(id);
2015-12-30 12:14:56 +00:00
let videoType = this.getRemoteVideoType(id);
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();
}
// if !show then use default type - large video
return largeVideo.showContainer(show ? type : VideoContainerType);
},
isLargeContainerTypeVisible (type) {
return largeVideo && largeVideo.state === type;
},
/**
* Returns the id of the current video shown on large.
* Currently used by tests (troture).
*/
getLargeVideoID () {
return largeVideo.id;
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;