Encapsulates direct access to .currentTime field into 'hasVideoStarted' method of RemoteVideo.

Removes duplicated logic for hiding video element when the user is muted.
This commit is contained in:
paweldomas 2016-02-01 16:08:15 -06:00
parent ab13fa35b4
commit 103b5d71d0
2 changed files with 18 additions and 18 deletions

View File

@ -205,6 +205,18 @@ RemoteVideo.prototype.waitForPlayback = function (streamElement, stream) {
streamElement.onplaying = onPlayingHandler; streamElement.onplaying = onPlayingHandler;
}; };
/**
* Checks whether or not video stream exists and has started for this
* RemoteVideo instance. This is checked by trying to select video element in
* this container and checking if 'currentTime' field's value is greater than 0.
*
* @returns {*|boolean} true if this RemoteVideo has active video stream running
*/
RemoteVideo.prototype.hasVideoStarted = function () {
var videoSelector = this.selectVideoElement();
return videoSelector.length && videoSelector[0].currentTime > 0;
};
RemoteVideo.prototype.addRemoteStreamElement = function (stream) { RemoteVideo.prototype.addRemoteStreamElement = function (stream) {
if (!this.container) { if (!this.container) {
return; return;

View File

@ -46,11 +46,10 @@ function onContactClicked (id) {
} }
let remoteVideo = remoteVideos[id]; let remoteVideo = remoteVideos[id];
if (remoteVideo && remoteVideo.selectVideoElement().length) { if (remoteVideo && remoteVideo.hasVideo()) {
// It is not always the case that a videoThumb exists (if there is // It is not always the case that a videoThumb exists (if there is
// no actual video). // no actual video).
if (remoteVideo.videoStream) { if (remoteVideo.hasVideoStarted()) {
// We have a video src, great! Let's update the large video // We have a video src, great! Let's update the large video
// now. // now.
VideoLayout.handleVideoThumbClicked(false, id); VideoLayout.handleVideoThumbClicked(false, id);
@ -517,12 +516,6 @@ var VideoLayout = {
} else { } else {
var remoteVideo = remoteVideos[id]; var remoteVideo = remoteVideos[id];
remoteVideo.setMutedView(value); remoteVideo.setMutedView(value);
var el = remoteVideo.selectVideoElement();
if (!value)
el.show();
else
el.hide();
} }
if(this.isCurrentlyOnLarge(id)) if(this.isCurrentlyOnLarge(id))
@ -575,18 +568,13 @@ var VideoLayout = {
} }
currentDominantSpeaker = id; currentDominantSpeaker = id;
// Obtain container for new dominant speaker.
let videoSel = remoteVideo.selectVideoElement();
// Local video will not have container found, but that's ok // Local video will not have container found, but that's ok
// since we don't want to switch to local video. // since we don't want to switch to local video.
if (!focusedVideoResourceJid && videoSel.length) {
// Update the large video if the video source is already available, // Update the large video if the video source is already available,
// otherwise wait for the "videoactive.jingle" event. // otherwise wait for the "videoactive.jingle" event.
if (videoSel[0].currentTime > 0) { if (!focusedVideoResourceJid && remoteVideo.hasVideoStarted()) {
this.updateLargeVideo(id); this.updateLargeVideo(id);
} }
}
}, },
/** /**