From 4aa6fbc4b9a967f357a9d337ec77cf025ec6bacc Mon Sep 17 00:00:00 2001 From: paweldomas Date: Thu, 23 Jul 2015 11:03:29 +0200 Subject: [PATCH] Switches to the last visible video correctly when current speaker leaves the conference. --- modules/UI/UI.js | 17 ++----------- modules/UI/videolayout/LargeVideo.js | 6 +++++ modules/UI/videolayout/VideoLayout.js | 36 ++++++++++++++++++--------- 3 files changed, 32 insertions(+), 27 deletions(-) diff --git a/modules/UI/UI.js b/modules/UI/UI.js index 655038afe2..a78878b94f 100644 --- a/modules/UI/UI.js +++ b/modules/UI/UI.js @@ -546,23 +546,10 @@ function onMucMemberLeft(jid) { if(!config.startAudioMuted || config.startAudioMuted > APP.members.size()) UIUtil.playSoundNotification('userLeft'); - // Need to call this with a slight delay, otherwise the element couldn't be - // found for some reason. - // XXX(gp) it works fine without the timeout for me (with Chrome 38). - window.setTimeout(function () { - var container = document.getElementById( - 'participant_' + Strophe.getResourceFromJid(jid)); - if (container) { - ContactList.removeContact(jid); - VideoLayout.removeConnectionIndicator(jid); - // hide here, wait for video to close before removing - $(container).hide(); - VideoLayout.resizeThumbnails(); - } - }, 10); - VideoLayout.participantLeft(jid); + ContactList.removeContact(jid); + VideoLayout.participantLeft(jid); }; diff --git a/modules/UI/videolayout/LargeVideo.js b/modules/UI/videolayout/LargeVideo.js index 7cdb17b5c5..1a9c4aa1f3 100644 --- a/modules/UI/videolayout/LargeVideo.js +++ b/modules/UI/videolayout/LargeVideo.js @@ -205,6 +205,12 @@ function updateActiveSpeakerAvatarSrc() { } function changeVideo(isVisible) { + + if (!currentSmallVideo) { + console.error("Unable to change large video - no 'currentSmallVideo'"); + return; + } + updateActiveSpeakerAvatarSrc(); APP.RTC.setVideoSrc($('#largeVideo')[0], currentSmallVideo.getSrc()); diff --git a/modules/UI/videolayout/VideoLayout.js b/modules/UI/videolayout/VideoLayout.js index df283f9495..f1f1a95f6f 100644 --- a/modules/UI/videolayout/VideoLayout.js +++ b/modules/UI/videolayout/VideoLayout.js @@ -119,7 +119,8 @@ var VideoLayout = (function (my) { var newResourceJid; // We'll show user's avatar if he is the dominant speaker or if // his video thumbnail is pinned - if (resourceJid === focusedVideoResourceJid || + if (remoteVideos[resourceJid] && + resourceJid === focusedVideoResourceJid || resourceJid === currentDominantSpeaker) { newResourceJid = resourceJid; } else { @@ -137,18 +138,20 @@ var VideoLayout = (function (my) { var videoElem = RTC.getVideoElementName(); var pick = $('#remoteVideos>span[id!="mixedstream"]:visible:last>' + videoElem); if (pick.length && APP.RTC.getVideoSrc(pick[0])) { - return VideoLayout.getPeerContainerResourceJid(pick[0].parentNode); + jid = VideoLayout.getPeerContainerResourceJid(pick[0].parentNode); } else { console.info("Last visible video no longer exists"); pick = $('#remoteVideos>span[id!="mixedstream"]>' + videoElem); if (pick.length && APP.RTC.getVideoSrc(pick[0])) { - return VideoLayout.getPeerContainerResourceJid(pick[0].parentNode); + jid = VideoLayout.getPeerContainerResourceJid(pick[0].parentNode); } else { // Try local video console.info("Fallback to local video..."); - return APP.xmpp.myResource(); + jid = APP.xmpp.myResource(); } } + console.info("electLastVisibleVideo: " + jid); + return jid; }; my.onRemoteStreamAdded = function (stream) { @@ -784,14 +787,6 @@ var VideoLayout = (function (my) { remoteVideos[resourceJid].updateStatsIndicator(percent, object); }; - /** - * Removes the connection - * @param jid - */ - my.removeConnectionIndicator = function (jid) { - remoteVideos[Strophe.getResourceFromJid(jid)].removeConnectionIndicator(); - }; - /** * Hides the connection indicator * @param jid @@ -819,6 +814,23 @@ var VideoLayout = (function (my) { console.info("Focused video owner has left the conference"); focusedVideoResourceJid = null; } + + if (currentDominantSpeaker === resourceJid) + { + console.info("Dominant speaker has left the conference"); + currentDominantSpeaker = null; + } + + var remoteVideo = remoteVideos[resourceJid]; + if (remoteVideo) { + remoteVideo.removeConnectionIndicator(); + // Remove remote video + delete remoteVideos[resourceJid]; + } else { + console.warn("No remote video for " + resourceJid); + } + + VideoLayout.resizeThumbnails(); }; my.onVideoTypeChanged = function (jid) {