From 7ea867d4e5dc5e1fc83815faa0aab54882cfebb6 Mon Sep 17 00:00:00 2001 From: Simon Eisenmann Date: Wed, 12 Mar 2014 16:08:48 +0100 Subject: [PATCH] Use video waiter for screensharing videos and show screen sharing resolution in log. --- static/js/directives/audiovideo.js | 41 +------------- static/js/directives/screenshare.js | 7 ++- static/js/mediastream/peerscreenshare.js | 1 + static/js/services/services.js | 9 ++- static/js/services/videowaiter.js | 72 ++++++++++++++++++++++++ 5 files changed, 87 insertions(+), 43 deletions(-) create mode 100644 static/js/services/videowaiter.js diff --git a/static/js/directives/audiovideo.js b/static/js/directives/audiovideo.js index edc0a7b1..b5d600b9 100644 --- a/static/js/directives/audiovideo.js +++ b/static/js/directives/audiovideo.js @@ -20,48 +20,11 @@ */ define(['jquery', 'underscore', 'text!partials/audiovideo.html', 'text!partials/audiovideopeer.html', 'bigscreen', 'injectCSS', 'webrtc.adapter', 'rAF'], function($, _, template, templatePeer, BigScreen) { - return ["$window", "$compile", "$filter", "mediaStream", "safeApply", "desktopNotify", "buddyData", function($window, $compile, $filter, mediaStream, safeApply, desktopNotify, buddyData) { + return ["$window", "$compile", "$filter", "mediaStream", "safeApply", "desktopNotify", "buddyData", "videoWaiter", function($window, $compile, $filter, mediaStream, safeApply, desktopNotify, buddyData, videoWaiter) { var requestAnimationFrame = $window.requestAnimationFrame; var peerTemplate = $compile(templatePeer); - var waitForVideo = function(video, stream, cb, err_cb) { - var Waiter = function() { - this.stop = false; - this.count = 0; - this.retries = 100; - _.defer(_.bind(this.start, this), this); - }; - Waiter.prototype.start = function() { - if (this.stop) { - if (err_cb) { - err_cb(video, stream); - } - return; - } - var videoTracks = stream.getVideoTracks(); - //console.log("wait for video", videoTracks.length, video.currentTime, video) - if (videoTracks.length === 0) { - cb(false, video, stream); - } else if (video.currentTime > 0 && video.videoHeight > 0) { - cb(true, video, stream); - } else { - this.count++; - if (this.count < this.retries) { - $window.setTimeout(_.bind(this.start, this), 100); - } else { - if (err_cb) { - err_cb(video, stream); - } - } - } - }; - Waiter.prototype.stop = function() { - this.stop = true; - }; - return new Waiter(); - }; - var controller = ['$scope', '$element', '$attrs', function($scope, $element, $attrs) { var peers = {}; @@ -109,7 +72,7 @@ define(['jquery', 'underscore', 'text!partials/audiovideo.html', 'text!partials/ var video = clonedElement.find("video").get(0); $window.attachMediaStream(video, stream); // Waiter callbacks also count as connected, as browser support (FireFox 25) is not setting state changes properly. - waitForVideo(video, stream, function(withvideo) { + videoWaiter.wait(video, stream, function(withvideo) { peers[peerid] = scope; if (withvideo) { scope.$apply(function($scope) { diff --git a/static/js/directives/screenshare.js b/static/js/directives/screenshare.js index 91a93e08..78439882 100644 --- a/static/js/directives/screenshare.js +++ b/static/js/directives/screenshare.js @@ -20,7 +20,7 @@ */ define(['jquery', 'underscore', 'text!partials/screenshare.html', 'text!partials/screensharepeer.html', 'bigscreen'], function($, _, template, templatePeer, BigScreen) { - return ["$window", "mediaStream", "$compile", "safeApply", function($window, mediaStream, $compile, safeApply) { + return ["$window", "mediaStream", "$compile", "safeApply", "videoWaiter", function($window, mediaStream, $compile, safeApply, videoWaiter) { var peerTemplate = $compile(templatePeer); @@ -91,6 +91,11 @@ define(['jquery', 'underscore', 'text!partials/screenshare.html', 'text!partials scope.element = clonedElement; var video = clonedElement.find("video").get(0); $window.attachMediaStream(video, stream); + videoWaiter.wait(video, stream, function() { + console.log("Screensharing size: ", video.videoWidth, video.videoHeight); + }, function() { + console.warn("We did not receive screen sharing video data", currentscreenshare, stream, video); + }); screens[peerid] = scope; }); diff --git a/static/js/mediastream/peerscreenshare.js b/static/js/mediastream/peerscreenshare.js index c982469a..6a2ef36b 100644 --- a/static/js/mediastream/peerscreenshare.js +++ b/static/js/mediastream/peerscreenshare.js @@ -93,6 +93,7 @@ define(['jquery', 'underscore', 'mediastream/peercall', 'mediastream/tokens'], f optional: [] } } + console.log("Setting screen sharing media constraints", mandatoryVideoConstraints); return mediaConstraints; }; diff --git a/static/js/services/services.js b/static/js/services/services.js index de2f6954..80bf148b 100644 --- a/static/js/services/services.js +++ b/static/js/services/services.js @@ -41,7 +41,8 @@ define([ 'services/filetransfer', 'services/safedisplayname', 'services/randomgen', - 'services/fastscroll' + 'services/fastscroll', + 'services/videowaiter' ], function(_, desktopNotify, playSound, @@ -63,7 +64,8 @@ define([ fileTransfer, safeDisplayName, randomGen, - fastScroll + fastScroll, + videoWaiter ) { var services = { @@ -87,7 +89,8 @@ define([ fileTransfer: fileTransfer, safeDisplayName: safeDisplayName, randomGen: randomGen, - fastScroll: fastScroll + fastScroll: fastScroll, + videoWaiter: videoWaiter }; var initialize = function (angModule) { diff --git a/static/js/services/videowaiter.js b/static/js/services/videowaiter.js new file mode 100644 index 00000000..889ebc26 --- /dev/null +++ b/static/js/services/videowaiter.js @@ -0,0 +1,72 @@ +/* + * Spreed Speak Freely. + * Copyright (C) 2013-2014 struktur AG + * + * This file is part of Spreed Speak Freely. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ +define(["underscore"], function(_) { + + return ["$window", function($window) { + + var Waiter = function() { + this.stop = false; + this.count = 0; + this.retries = 100; + }; + Waiter.prototype.start = function(video, stream, cb, err_cb) { + if (this.stop) { + if (err_cb) { + err_cb(video, stream); + } + return; + } + var videoTracks = stream.getVideoTracks(); + //console.log("wait for video", videoTracks.length, video.currentTime, video) + if (videoTracks.length === 0) { + cb(false, video, stream); + } else if (video.currentTime > 0 && video.videoHeight > 0) { + cb(true, video, stream); + } else { + this.count++; + if (this.count < this.retries) { + $window.setTimeout(_.bind(this.start, this, video, stream, cb, err_cb), 100); + } else { + if (err_cb) { + err_cb(video, stream); + } + } + } + }; + Waiter.prototype.stop = function() { + this.stop = true; + }; + + // videoWaiter wait + return { + wait: function(video, stream, cb, err_cb) { + var waiter = new Waiter(); + _.defer(function() { + waiter.start(video, stream, cb, err_cb); + }); + return waiter; + } + } + + }] + + +}); \ No newline at end of file