From 879fb9a590f1fca9030a2a036d5f283dfd5594b8 Mon Sep 17 00:00:00 2001 From: paweldomas Date: Wed, 15 Jul 2015 10:45:51 +0200 Subject: [PATCH] Adds getters for peer video selectors and simplifies the code a little bit. --- modules/RTC/RTC.js | 4 +- modules/RTC/RTCUtils.js | 4 +- modules/UI/videolayout/VideoLayout.js | 83 ++++++++++++++------------- 3 files changed, 46 insertions(+), 45 deletions(-) diff --git a/modules/RTC/RTC.js b/modules/RTC/RTC.js index 03adccba7..11efc6733 100644 --- a/modules/RTC/RTC.js +++ b/modules/RTC/RTC.js @@ -119,8 +119,8 @@ var RTC = { return this.rtcUtils.getUserMediaWithConstraints(um, success_callback, failure_callback, resolution, bandwidth, fps, desktopStream); }, - attachMediaStream: function (element, stream) { - this.rtcUtils.attachMediaStream(element, stream); + attachMediaStream: function (elSelector, stream) { + this.rtcUtils.attachMediaStream(elSelector, stream); }, getStreamID: function (stream) { return this.rtcUtils.getStreamID(stream); diff --git a/modules/RTC/RTCUtils.js b/modules/RTC/RTCUtils.js index 644e0ffa4..9aafeba0a 100644 --- a/modules/RTC/RTCUtils.js +++ b/modules/RTC/RTCUtils.js @@ -237,13 +237,13 @@ function RTCUtils(RTCService, onTemasysPluginReady) self.peerconnection = RTCPeerConnection; self.getUserMedia = getUserMedia; - self.attachMediaStream = function (element, stream) { + self.attachMediaStream = function (elSel, stream) { if (stream.id === "dummyAudio" || stream.id === "dummyVideo") { return; } - attachMediaStream(element[0], stream); + attachMediaStream(elSel[0], stream); }; self.getStreamID = function (stream) { var id = SDPUtil.filter_special_chars(stream.label); diff --git a/modules/UI/videolayout/VideoLayout.js b/modules/UI/videolayout/VideoLayout.js index 77c32bd20..e591f9c7e 100644 --- a/modules/UI/videolayout/VideoLayout.js +++ b/modules/UI/videolayout/VideoLayout.js @@ -456,6 +456,11 @@ var VideoLayout = (function (my) { return containerElement.id.substring(i + 12); }; + my.getPeerVideoSel = function (peerResourceJid) { + return $('#participant_' + peerResourceJid + + '>' + APP.RTC.getVideoElementName()); + }; + /** * On contact list item clicked. */ @@ -464,40 +469,40 @@ var VideoLayout = (function (my) { return; } + if (jid == APP.xmpp.myJid()) { + $("#localVideoContainer").click(); + return; + } + var resource = Strophe.getResourceFromJid(jid); - var videoContainer = $("#participant_" + resource); - if (videoContainer.length > 0) { - var videoThumb - = $(RTC.getVideoElementName(), videoContainer).get(0); + var videoSel = VideoLayout.getVideoSelector(resource); + if (videoSel.length > 0) { + var videoThumb = videoSel[0]; // It is not always the case that a videoThumb exists (if there is // no actual video). - if (videoThumb) { - if (videoThumb.src && videoThumb.src != '') { + // FIXME: checking on .src will not work with Temasys plugin + if (videoThumb.src && videoThumb.src !== '') { - // We have a video src, great! Let's update the large video - // now. + // We have a video src, great! Let's update the large video + // now. + VideoLayout.handleVideoThumbClicked( + false, + Strophe.getResourceFromJid(jid)); + } else { - VideoLayout.handleVideoThumbClicked( - false, - Strophe.getResourceFromJid(jid)); - } 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 lastNPickupJid variable to be + // picked up later by the lastN changed event handler. - // 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 lastNPickupJid variable to be - // picked up later by the lastN changed event handler. - - lastNPickupJid = jid; - eventEmitter.emit(UIEvents.PINNED_ENDPOINT, - Strophe.getResourceFromJid(jid)); - } - } else if (jid == APP.xmpp.myJid()) { - $("#localVideoContainer").click(); + lastNPickupJid = jid; + eventEmitter.emit(UIEvents.PINNED_ENDPOINT, + Strophe.getResourceFromJid(jid)); } } }); @@ -530,11 +535,12 @@ var VideoLayout = (function (my) { if (jid === APP.xmpp.myJid()) { localVideoThumbnail.showVideoIndicator(value); } else { - VideoLayout.ensurePeerContainerExists(jid); - remoteVideos[Strophe.getResourceFromJid(jid)].showVideoIndicator(value); + var resource = Strophe.getResourceFromJid(jid); - var el = $('#participant_' + Strophe.getResourceFromJid(jid) - + '>' + APP.RTC.getVideoElementName()); + VideoLayout.ensurePeerContainerExists(jid); + remoteVideos[resource].showVideoIndicator(value); + + var el = VideoLayout.getPeerVideoSel(resource); if (!value) el.show(); else @@ -587,19 +593,15 @@ var VideoLayout = (function (my) { } // Obtain container for new dominant speaker. - var container = document.getElementById( - 'participant_' + resourceJid); + var videoSel = VideoLayout.getPeerVideoSel(resourceJid); // Local video will not have container found, but that's ok // since we don't want to switch to local video. - if (container && !focusedVideoResourceJid) + if (!focusedVideoResourceJid && videoSel.length) { - var video - = container.getElementsByTagName(RTC.getVideoElementName()); - // Update the large video if the video source is already available, // otherwise wait for the "videoactive.jingle" event. - if (video.length && video[0].currentTime > 0) { + if (videoSel[0].currentTime > 0) { LargeVideo.updateLargeVideo(resourceJid); } } @@ -697,8 +699,7 @@ var VideoLayout = (function (my) { var jid = APP.xmpp.findJidFromResource(resourceJid); var mediaStream = APP.RTC.remoteStreams[jid][MediaStreamType.VIDEO_TYPE]; - var sel = $('#participant_' + resourceJid + - '>' + RTC.getVideoElementName()); + var sel = VideoLayout.getPeerVideoSel(resourceJid); APP.RTC.attachMediaStream(sel, mediaStream.stream); if (lastNPickupJid == mediaStream.peerjid) {