From 04ff8dfd02a88166a69ba77bd39478d8fb28c940 Mon Sep 17 00:00:00 2001 From: Evan Theurer Date: Fri, 2 Oct 2015 11:13:19 +0200 Subject: [PATCH 01/16] Add firefoxextension service. --- static/js/services/firefoxextension.js | 79 ++++++++++++++++++++++++++ static/js/services/services.js | 9 ++- 2 files changed, 85 insertions(+), 3 deletions(-) create mode 100644 static/js/services/firefoxextension.js diff --git a/static/js/services/firefoxextension.js b/static/js/services/firefoxextension.js new file mode 100644 index 00000000..a3fa8495 --- /dev/null +++ b/static/js/services/firefoxextension.js @@ -0,0 +1,79 @@ +/* + * Spreed WebRTC. + * Copyright (C) 2013-2015 struktur AG + * + * This file is part of Spreed WebRTC. + * + * 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 . + * + */ + +"use strict"; +define(["underscore", "jquery", "webrtc.adapter"], function(_, $) { + + // firefoxExtension + return ["$window", "$q", "alertify", "translation", function($window, $q, alertify, translation) { + + var FirefoxExtension = function() { + this.available = false; + this.e = $({}); + this.autoinstall = {}; + this.initialize(); + }; + + FirefoxExtension.prototype.initialize = function() { + var marker = $window.document.getElementById("firefoxextension-available"); + console.log('Firefox extension marker', marker); + if (marker) { + this.available = true; + console.log("Firefox extension is available."); + this.e.triggerHandler("available", true); + } else if (!marker && this.available) { + this.available = false; + console.log("Firefox extension is no longer available."); + this.e.triggerHandler("available", false); + } + }; + + FirefoxExtension.prototype.registerAutoInstall = function(installFunc, cancelInstallFunc, force) { + + this.autoinstall.install = installFunc; + this.autoinstall.cancel = cancelInstallFunc; + this.autoinstall.force = !!force; + if (!this.available && installFunc) { + this.e.triggerHandler("available", true); + } + + }; + + // Create extension api and wait for messages. + var extension = new FirefoxExtension(); + + // Always register default auto install which tells user that extension is required + // if screen sharing can only work with extension. + if ($window.webrtcDetectedBrowser === "firefox" && $window.webrtcDetectedVersion >= 36) { + extension.registerAutoInstall(function() { + var d = $q.defer(); + alertify.dialog.alert(translation._("Screen sharing requires a browser extension. Please add the Spreed WebRTC screen sharing extension to Firefox and try again.")); + d.reject("Manual extension installation required"); + return d.promise; + }); + } + + // Expose. + return extension; + + }]; + +}); diff --git a/static/js/services/services.js b/static/js/services/services.js index 4fa9919a..a5de387c 100644 --- a/static/js/services/services.js +++ b/static/js/services/services.js @@ -70,7 +70,8 @@ define([ 'services/mediadevices', 'services/sandbox', 'services/dummystream', - 'services/usermedia'], function(_, + 'services/usermedia', + 'services/firefoxextension'], function(_, desktopNotify, playSound, safeApply, @@ -118,7 +119,8 @@ modules, mediaDevices, sandbox, dummyStream, -userMedia) { +userMedia, +firefoxExtension) { var services = { desktopNotify: desktopNotify, @@ -168,7 +170,8 @@ userMedia) { mediaDevices: mediaDevices, sandbox: sandbox, dummyStream: dummyStream, - userMedia: userMedia + userMedia: userMedia, + firefoxExtension: firefoxExtension }; var initialize = function(angModule) { From 9289ad558fb7941d7c8d367ca7d92179329a1cf0 Mon Sep 17 00:00:00 2001 From: Evan Theurer Date: Fri, 2 Oct 2015 11:21:49 +0200 Subject: [PATCH 02/16] Add new firefoxextension api to screensharing service. --- static/js/services/screensharing.js | 49 ++++++++++++++++++++++++++--- 1 file changed, 44 insertions(+), 5 deletions(-) diff --git a/static/js/services/screensharing.js b/static/js/services/screensharing.js index 2cc5c54f..96b3d1e7 100644 --- a/static/js/services/screensharing.js +++ b/static/js/services/screensharing.js @@ -33,7 +33,7 @@ define(['underscore', 'text!partials/screensharedialogff.html', 'webrtc.adapter' }]; // screensharing - return ["$window", "$q", "$timeout", "chromeExtension", "dialogs", "$templateCache", function($window, $q, $timeout, chromeExtension, dialogs, $templateCache) { + return ["$window", "$q", "$timeout", "chromeExtension", "firefoxExtension", "dialogs", "$templateCache", function($window, $q, $timeout, chromeExtension, firefoxExtension, dialogs, $templateCache) { $templateCache.put('/dialogs/screensharedialogff.html', screenshareDialogFF); @@ -43,6 +43,9 @@ define(['underscore', 'text!partials/screensharedialogff.html', 'webrtc.adapter' chromeExtension.e.on("available", _.bind(function() { this.initialize(); }, this)); + firefoxExtension.e.on("available", _.bind(function() { + this.initialize(); + }, this)); }; Screensharing.prototype.initialize = function() { @@ -137,7 +140,7 @@ define(['underscore', 'text!partials/screensharedialogff.html', 'webrtc.adapter' // Firefox 36 got screen sharing support. // See https://bugzilla.mozilla.org/show_bug.cgi?id=923225 - if ($window.webrtcDetectedVersion >= 36) { + if ($window.webrtcDetectedVersion >= 36 && firefoxExtension.available) { this.supported = true; this.prepare = function(options) { // To work, the current domain must be whitelisted in @@ -165,12 +168,16 @@ define(['underscore', 'text!partials/screensharedialogff.html', 'webrtc.adapter' // No support for screen sharing. } + var that = null; + var waiting = null; + var prepareAlternative = null; + // Auto install support. if (!this.supported && chromeExtension.autoinstall.install) { this.supported = this.autoinstall = true; - var that = this; - var waiting = false; - var prepareAlternative = this.prepare; + that = this; + waiting = false; + prepareAlternative = this.prepare; this.prepare = function(options) { var d = $q.defer(); var install = chromeExtension.autoinstall.install(); @@ -230,6 +237,38 @@ define(['underscore', 'text!partials/screensharedialogff.html', 'webrtc.adapter' } waiting = false; }; + } else if (!this.supported && firefoxExtension.autoinstall.install) { + this.supported = this.autoinstall = true; + that = this; + waiting = false; + prepareAlternative = this.prepare; + this.prepare = function(options) { + var d = $q.defer(); + var install = firefoxExtension.autoinstall.install(); + install.then(function() { + // Do install of firefox extension + console.log('installing extension'); + }, function(err) { + console.log("Auto install of extension failed.", err); + if (prepareAlternative) { + var alternative = prepareAlternative(options); + alternative.then(function(id) { + d.resolve(id); + }, function() { + d.reject(err); + }); + } else { + d.reject(err); + } + }); + return d.promise; + }; + this.cancel = function() { + if (firefoxExtension.autoinstall.cancel) { + firefoxExtension.autoinstall.cancel(); + } + waiting = false; + }; } else { this.autoinstall = false; } From 89bc156ef516b23b0a52f808bf4bb7553ce13f89 Mon Sep 17 00:00:00 2001 From: Evan Theurer Date: Fri, 2 Oct 2015 11:31:20 +0200 Subject: [PATCH 03/16] Cleanup variable declarations. --- static/js/services/screensharing.js | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/static/js/services/screensharing.js b/static/js/services/screensharing.js index 96b3d1e7..ca914573 100644 --- a/static/js/services/screensharing.js +++ b/static/js/services/screensharing.js @@ -168,16 +168,13 @@ define(['underscore', 'text!partials/screensharedialogff.html', 'webrtc.adapter' // No support for screen sharing. } - var that = null; - var waiting = null; - var prepareAlternative = null; + var that = this; + var waiting = false; + var prepareAlternative = this.prepare; // Auto install support. if (!this.supported && chromeExtension.autoinstall.install) { this.supported = this.autoinstall = true; - that = this; - waiting = false; - prepareAlternative = this.prepare; this.prepare = function(options) { var d = $q.defer(); var install = chromeExtension.autoinstall.install(); @@ -239,9 +236,6 @@ define(['underscore', 'text!partials/screensharedialogff.html', 'webrtc.adapter' }; } else if (!this.supported && firefoxExtension.autoinstall.install) { this.supported = this.autoinstall = true; - that = this; - waiting = false; - prepareAlternative = this.prepare; this.prepare = function(options) { var d = $q.defer(); var install = firefoxExtension.autoinstall.install(); From e6cb70827b220d1ac72f302f6a4a9931f1da11d0 Mon Sep 17 00:00:00 2001 From: Evan Theurer Date: Fri, 2 Oct 2015 14:57:11 +0200 Subject: [PATCH 04/16] Force autoinstall of Firefox extension. --- static/js/services/screensharing.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/static/js/services/screensharing.js b/static/js/services/screensharing.js index ca914573..30386b72 100644 --- a/static/js/services/screensharing.js +++ b/static/js/services/screensharing.js @@ -162,6 +162,12 @@ define(['underscore', 'text!partials/screensharedialogff.html', 'webrtc.adapter' }); return d.promise; }; + } else { + + if (firefoxExtension.autoinstall.force) { + this.supported = false; + } + } } else { From 13256de141b90c5077abeeae10885acbcb1e301e Mon Sep 17 00:00:00 2001 From: Evan Theurer Date: Fri, 2 Oct 2015 16:46:41 +0200 Subject: [PATCH 05/16] Factor out firefox screensharing code into method. Add ability now to choose the screen you share after you install extension. --- static/js/services/screensharing.js | 73 ++++++++++++++++++++--------- 1 file changed, 52 insertions(+), 21 deletions(-) diff --git a/static/js/services/screensharing.js b/static/js/services/screensharing.js index 30386b72..abebdaa7 100644 --- a/static/js/services/screensharing.js +++ b/static/js/services/screensharing.js @@ -33,7 +33,7 @@ define(['underscore', 'text!partials/screensharedialogff.html', 'webrtc.adapter' }]; // screensharing - return ["$window", "$q", "$timeout", "chromeExtension", "firefoxExtension", "dialogs", "$templateCache", function($window, $q, $timeout, chromeExtension, firefoxExtension, dialogs, $templateCache) { + return ["$window", "$q", "$timeout", "$interval", "chromeExtension", "firefoxExtension", "dialogs", "$templateCache", function($window, $q, $timeout, $interval, chromeExtension, firefoxExtension, dialogs, $templateCache) { $templateCache.put('/dialogs/screensharedialogff.html', screenshareDialogFF); @@ -57,6 +57,27 @@ define(['underscore', 'text!partials/screensharedialogff.html', 'webrtc.adapter' this.prepare = null; this.cancel = null; + var selectFirefoxScreenToShare = function(options) { + // To work, the current domain must be whitelisted in + // media.getusermedia.screensharing.allowed_domains (about:config). + // See https://wiki.mozilla.org/Screensharing for reference. + var d = $q.defer(); + var dlg = dialogs.create('/dialogs/screensharedialogff.html', screenshareDialogFFController, {selection: "screen"}, {}); + dlg.result.then(function(source) { + if (source) { + var opts = _.extend({ + mediaSource: source + }, options); + d.resolve(opts); + } else { + d.resolve(null); + } + }, function(err) { + d.resolve(null); + }); + return d.promise; + }; + // Chrome support. if ($window.webrtcDetectedBrowser === "chrome") { @@ -143,24 +164,7 @@ define(['underscore', 'text!partials/screensharedialogff.html', 'webrtc.adapter' if ($window.webrtcDetectedVersion >= 36 && firefoxExtension.available) { this.supported = true; this.prepare = function(options) { - // To work, the current domain must be whitelisted in - // media.getusermedia.screensharing.allowed_domains (about:config). - // See https://wiki.mozilla.org/Screensharing for reference. - var d = $q.defer(); - var dlg = dialogs.create('/dialogs/screensharedialogff.html', screenshareDialogFFController, {selection: "screen"}, {}); - dlg.result.then(function(source) { - if (source) { - var opts = _.extend({ - mediaSource: source - }, options); - d.resolve(opts); - } else { - d.resolve(null); - } - }, function(err) { - d.resolve(null); - }); - return d.promise; + return selectFirefoxScreenToShare(options); }; } else { @@ -246,8 +250,35 @@ define(['underscore', 'text!partials/screensharedialogff.html', 'webrtc.adapter' var d = $q.defer(); var install = firefoxExtension.autoinstall.install(); install.then(function() { - // Do install of firefox extension - console.log('installing extension'); + var starter = function() { + var prepare = selectFirefoxScreenToShare(options); + prepare.then(function(id) { + d.resolve(id); + }, function(err) { + d.reject(err); + }); + }; + var hasBeenInstalled = function() { + return $window.document.getElementById('firefoxextension-available'); + }; + var cancelInterval = function(promise) { + $interval.cancel(promise); + }; + var maxTimeout = 30000; + var intervalCount = 1; + var intervalSecs = 50; + var intervalPromise = $interval(function() { + if (that.autoinstall && that.supported && hasBeenInstalled()) { + console.log("Auto install success Firefox extension"); + cancelInterval(intervalPromise); + starter(); + } else if (intervalCount * intervalSecs >= maxTimeout) { + cancelInterval(intervalPromise); + d.reject("Timeout while waiting for extension to become available"); + } + intervalCount++; + }, intervalSecs); + }, function(err) { console.log("Auto install of extension failed.", err); if (prepareAlternative) { From 7fd246c38781d3bc5ec852d20f2dd2caa2c41b1d Mon Sep 17 00:00:00 2001 From: Evan Theurer Date: Tue, 29 Sep 2015 18:01:22 +0200 Subject: [PATCH 06/16] Add events to notify Firefox screen sharing extension when screen sharing starts and stops. --- static/js/directives/screenshare.js | 3 +++ static/js/services/screensharing.js | 14 ++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/static/js/directives/screenshare.js b/static/js/directives/screenshare.js index 58e73dd7..b868cb89 100644 --- a/static/js/directives/screenshare.js +++ b/static/js/directives/screenshare.js @@ -172,6 +172,7 @@ define(['jquery', 'underscore', 'text!partials/screenshare.html', 'text!partials } $scope.layout.screenshare = true; + screensharing.globalNotify().screensharingStart(); screensharing.getScreen().then(function(options) { if (options) { $scope.startScreenshare(options); @@ -307,6 +308,8 @@ define(['jquery', 'underscore', 'text!partials/screenshare.html', 'text!partials $scope.layout.screenshare = false; } + screensharing.globalNotify().screensharingStop(); + }; $scope.toggleFullscreen = function(elem) { diff --git a/static/js/services/screensharing.js b/static/js/services/screensharing.js index abebdaa7..038c61ff 100644 --- a/static/js/services/screensharing.js +++ b/static/js/services/screensharing.js @@ -32,6 +32,9 @@ define(['underscore', 'text!partials/screensharedialogff.html', 'webrtc.adapter' }; }]; + var GLOBAL_SCREENSHARING_START_EVENT = new Event('webrtcStartScreensharing'); + var GLOBAL_SCREENSHARING_STOP_EVENT = new Event('webrtcStopScreensharing'); + // screensharing return ["$window", "$q", "$timeout", "$interval", "chromeExtension", "firefoxExtension", "dialogs", "$templateCache", function($window, $q, $timeout, $interval, chromeExtension, firefoxExtension, dialogs, $templateCache) { @@ -48,6 +51,17 @@ define(['underscore', 'text!partials/screensharedialogff.html', 'webrtc.adapter' }, this)); }; + Screensharing.prototype.globalNotify = function() { + return { + screensharingStart: function() { + $window.dispatchEvent(GLOBAL_SCREENSHARING_START_EVENT); + }, + screensharingStop: function() { + $window.dispatchEvent(GLOBAL_SCREENSHARING_STOP_EVENT); + } + }; + }; + Screensharing.prototype.initialize = function() { // Check if we can do screensharing. From 5a537a26d9c16af12d45d5c281faeb8d1a38703b Mon Sep 17 00:00:00 2001 From: Evan Theurer Date: Fri, 2 Oct 2015 17:22:20 +0200 Subject: [PATCH 07/16] Remove console log. --- static/js/services/firefoxextension.js | 1 - 1 file changed, 1 deletion(-) diff --git a/static/js/services/firefoxextension.js b/static/js/services/firefoxextension.js index a3fa8495..5dbcecfe 100644 --- a/static/js/services/firefoxextension.js +++ b/static/js/services/firefoxextension.js @@ -34,7 +34,6 @@ define(["underscore", "jquery", "webrtc.adapter"], function(_, $) { FirefoxExtension.prototype.initialize = function() { var marker = $window.document.getElementById("firefoxextension-available"); - console.log('Firefox extension marker', marker); if (marker) { this.available = true; console.log("Firefox extension is available."); From 49b45f67884985b88912faba05422a5af061730f Mon Sep 17 00:00:00 2001 From: Evan Theurer Date: Mon, 5 Oct 2015 10:39:33 +0200 Subject: [PATCH 08/16] Ensure screensharing start event is also called after the FF extension is installed. --- static/js/services/screensharing.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/static/js/services/screensharing.js b/static/js/services/screensharing.js index 038c61ff..5d74d6e7 100644 --- a/static/js/services/screensharing.js +++ b/static/js/services/screensharing.js @@ -70,11 +70,13 @@ define(['underscore', 'text!partials/screensharedialogff.html', 'webrtc.adapter' // Define our helpers. this.prepare = null; this.cancel = null; + var that = this; var selectFirefoxScreenToShare = function(options) { // To work, the current domain must be whitelisted in // media.getusermedia.screensharing.allowed_domains (about:config). // See https://wiki.mozilla.org/Screensharing for reference. + that.globalNotify().screensharingStart(); var d = $q.defer(); var dlg = dialogs.create('/dialogs/screensharedialogff.html', screenshareDialogFFController, {selection: "screen"}, {}); dlg.result.then(function(source) { @@ -192,7 +194,6 @@ define(['underscore', 'text!partials/screensharedialogff.html', 'webrtc.adapter' // No support for screen sharing. } - var that = this; var waiting = false; var prepareAlternative = this.prepare; From de5bac291960ca21645e1af26aed20d727a60fc7 Mon Sep 17 00:00:00 2001 From: Evan Theurer Date: Mon, 5 Oct 2015 12:12:12 +0200 Subject: [PATCH 09/16] Move detection of Firefox extension installation to firefoxExtension service. --- static/js/services/firefoxextension.js | 39 ++++++++++++++++++++++++-- static/js/services/screensharing.js | 26 ++++------------- 2 files changed, 43 insertions(+), 22 deletions(-) diff --git a/static/js/services/firefoxextension.js b/static/js/services/firefoxextension.js index 5dbcecfe..078fcfd5 100644 --- a/static/js/services/firefoxextension.js +++ b/static/js/services/firefoxextension.js @@ -23,7 +23,7 @@ define(["underscore", "jquery", "webrtc.adapter"], function(_, $) { // firefoxExtension - return ["$window", "$q", "alertify", "translation", function($window, $q, alertify, translation) { + return ["$window", "$q", "alertify", "translation", "$interval", function($window, $q, alertify, translation, $interval) { var FirefoxExtension = function() { this.available = false; @@ -46,14 +46,49 @@ define(["underscore", "jquery", "webrtc.adapter"], function(_, $) { }; FirefoxExtension.prototype.registerAutoInstall = function(installFunc, cancelInstallFunc, force) { - this.autoinstall.install = installFunc; this.autoinstall.cancel = cancelInstallFunc; this.autoinstall.force = !!force; if (!this.available && installFunc) { this.e.triggerHandler("available", true); } + }; + + var EXTENSION_DOM_ID = 'firefoxextension-available'; + var intervalSecs = 50; + var intervalCount = 1; + var hasBeenInstalled = function() { + return $window.document.getElementById(EXTENSION_DOM_ID); + }; + + /** + * Checks for availability of the Firefox extension by looking for the id which the extension + * will append to the body of the document. Unfortunately there is no callback + * API implemented by Firefox which will allow other domains to see if an + * extension is installed using `InstallTrigger.install`. Only priviledged + * domains may use the callback. + * + * @param {int} How long of a timespan the function should check for the extension install at intervalSecs interval rate + * @return {promise} + */ + FirefoxExtension.prototype.detectInstalled = function(maxTimeout) { + var defer = $q.defer(); + var that = this; + + var intervalPromise = $interval(function() { + if (hasBeenInstalled()) { + console.log("Auto install success Firefox extension"); + $interval.cancel(intervalPromise); + that.initialize(); + defer.resolve("Auto install success Firefox extension"); + } else if (intervalCount * intervalSecs >= maxTimeout) { + $interval.cancel(intervalPromise); + defer.reject("Timeout while waiting for extension to become available"); + } + intervalCount++; + }, intervalSecs); + return defer.promise; }; // Create extension api and wait for messages. diff --git a/static/js/services/screensharing.js b/static/js/services/screensharing.js index 5d74d6e7..3bdb43c3 100644 --- a/static/js/services/screensharing.js +++ b/static/js/services/screensharing.js @@ -36,7 +36,7 @@ define(['underscore', 'text!partials/screensharedialogff.html', 'webrtc.adapter' var GLOBAL_SCREENSHARING_STOP_EVENT = new Event('webrtcStopScreensharing'); // screensharing - return ["$window", "$q", "$timeout", "$interval", "chromeExtension", "firefoxExtension", "dialogs", "$templateCache", function($window, $q, $timeout, $interval, chromeExtension, firefoxExtension, dialogs, $templateCache) { + return ["$window", "$q", "$timeout", "chromeExtension", "firefoxExtension", "dialogs", "$templateCache", function($window, $q, $timeout, chromeExtension, firefoxExtension, dialogs, $templateCache) { $templateCache.put('/dialogs/screensharedialogff.html', screenshareDialogFF); @@ -273,27 +273,13 @@ define(['underscore', 'text!partials/screensharedialogff.html', 'webrtc.adapter' d.reject(err); }); }; - var hasBeenInstalled = function() { - return $window.document.getElementById('firefoxextension-available'); - }; - var cancelInterval = function(promise) { - $interval.cancel(promise); - }; - var maxTimeout = 30000; - var intervalCount = 1; - var intervalSecs = 50; - var intervalPromise = $interval(function() { - if (that.autoinstall && that.supported && hasBeenInstalled()) { - console.log("Auto install success Firefox extension"); - cancelInterval(intervalPromise); + firefoxExtension.detectInstalled(30000).then(function() { + if (!that.autoinstall && that.supported) { starter(); - } else if (intervalCount * intervalSecs >= maxTimeout) { - cancelInterval(intervalPromise); - d.reject("Timeout while waiting for extension to become available"); } - intervalCount++; - }, intervalSecs); - + }, function(reason) { + d.reject(reason); + }); }, function(err) { console.log("Auto install of extension failed.", err); if (prepareAlternative) { From 134ccaaa9c886d7bf468e0dcc7a6af122d7e0bf1 Mon Sep 17 00:00:00 2001 From: Evan Theurer Date: Mon, 2 Nov 2015 12:00:58 +0100 Subject: [PATCH 10/16] Remove function from globalNotify and simply use dict. --- static/js/directives/screenshare.js | 4 ++-- static/js/services/screensharing.js | 18 ++++++++---------- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/static/js/directives/screenshare.js b/static/js/directives/screenshare.js index b868cb89..0b069375 100644 --- a/static/js/directives/screenshare.js +++ b/static/js/directives/screenshare.js @@ -172,7 +172,7 @@ define(['jquery', 'underscore', 'text!partials/screenshare.html', 'text!partials } $scope.layout.screenshare = true; - screensharing.globalNotify().screensharingStart(); + screensharing.globalNotify.screensharingStart(); screensharing.getScreen().then(function(options) { if (options) { $scope.startScreenshare(options); @@ -308,7 +308,7 @@ define(['jquery', 'underscore', 'text!partials/screenshare.html', 'text!partials $scope.layout.screenshare = false; } - screensharing.globalNotify().screensharingStop(); + screensharing.globalNotify.screensharingStop(); }; diff --git a/static/js/services/screensharing.js b/static/js/services/screensharing.js index 3bdb43c3..6827dd97 100644 --- a/static/js/services/screensharing.js +++ b/static/js/services/screensharing.js @@ -51,15 +51,13 @@ define(['underscore', 'text!partials/screensharedialogff.html', 'webrtc.adapter' }, this)); }; - Screensharing.prototype.globalNotify = function() { - return { - screensharingStart: function() { - $window.dispatchEvent(GLOBAL_SCREENSHARING_START_EVENT); - }, - screensharingStop: function() { - $window.dispatchEvent(GLOBAL_SCREENSHARING_STOP_EVENT); - } - }; + Screensharing.prototype.globalNotify = { + screensharingStart: function() { + $window.dispatchEvent(GLOBAL_SCREENSHARING_START_EVENT); + }, + screensharingStop: function() { + $window.dispatchEvent(GLOBAL_SCREENSHARING_STOP_EVENT); + } }; Screensharing.prototype.initialize = function() { @@ -76,7 +74,7 @@ define(['underscore', 'text!partials/screensharedialogff.html', 'webrtc.adapter' // To work, the current domain must be whitelisted in // media.getusermedia.screensharing.allowed_domains (about:config). // See https://wiki.mozilla.org/Screensharing for reference. - that.globalNotify().screensharingStart(); + that.globalNotify.screensharingStart(); var d = $q.defer(); var dlg = dialogs.create('/dialogs/screensharedialogff.html', screenshareDialogFFController, {selection: "screen"}, {}); dlg.result.then(function(source) { From 2e3155fd607d33bb2a39de1d695ff1c5d5541546 Mon Sep 17 00:00:00 2001 From: Evan Theurer Date: Mon, 2 Nov 2015 15:27:33 +0100 Subject: [PATCH 11/16] Do not register an autoinstall function natively for firefox extension. --- static/js/services/firefoxextension.js | 28 +++++++++----------------- 1 file changed, 9 insertions(+), 19 deletions(-) diff --git a/static/js/services/firefoxextension.js b/static/js/services/firefoxextension.js index 078fcfd5..b4c4cd91 100644 --- a/static/js/services/firefoxextension.js +++ b/static/js/services/firefoxextension.js @@ -25,6 +25,14 @@ define(["underscore", "jquery", "webrtc.adapter"], function(_, $) { // firefoxExtension return ["$window", "$q", "alertify", "translation", "$interval", function($window, $q, alertify, translation, $interval) { + var EXTENSION_DOM_ID = 'firefoxextension-available'; + + var intervalSecs = 50; + var intervalCount = 1; + var isAvailable = function() { + return $window.document.getElementById(EXTENSION_DOM_ID); + }; + var FirefoxExtension = function() { this.available = false; this.e = $({}); @@ -54,13 +62,6 @@ define(["underscore", "jquery", "webrtc.adapter"], function(_, $) { } }; - var EXTENSION_DOM_ID = 'firefoxextension-available'; - var intervalSecs = 50; - var intervalCount = 1; - var hasBeenInstalled = function() { - return $window.document.getElementById(EXTENSION_DOM_ID); - }; - /** * Checks for availability of the Firefox extension by looking for the id which the extension * will append to the body of the document. Unfortunately there is no callback @@ -76,7 +77,7 @@ define(["underscore", "jquery", "webrtc.adapter"], function(_, $) { var that = this; var intervalPromise = $interval(function() { - if (hasBeenInstalled()) { + if (isAvailable()) { console.log("Auto install success Firefox extension"); $interval.cancel(intervalPromise); that.initialize(); @@ -94,17 +95,6 @@ define(["underscore", "jquery", "webrtc.adapter"], function(_, $) { // Create extension api and wait for messages. var extension = new FirefoxExtension(); - // Always register default auto install which tells user that extension is required - // if screen sharing can only work with extension. - if ($window.webrtcDetectedBrowser === "firefox" && $window.webrtcDetectedVersion >= 36) { - extension.registerAutoInstall(function() { - var d = $q.defer(); - alertify.dialog.alert(translation._("Screen sharing requires a browser extension. Please add the Spreed WebRTC screen sharing extension to Firefox and try again.")); - d.reject("Manual extension installation required"); - return d.promise; - }); - } - // Expose. return extension; From e8c2841833619692366f045399dc03afb03c289c Mon Sep 17 00:00:00 2001 From: Evan Theurer Date: Mon, 2 Nov 2015 15:36:23 +0100 Subject: [PATCH 12/16] Do not require firefox screensharing extension to be installed in order to share screen. --- static/js/services/screensharing.js | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/static/js/services/screensharing.js b/static/js/services/screensharing.js index 6827dd97..3b202ad4 100644 --- a/static/js/services/screensharing.js +++ b/static/js/services/screensharing.js @@ -175,17 +175,13 @@ define(['underscore', 'text!partials/screensharedialogff.html', 'webrtc.adapter' // Firefox 36 got screen sharing support. // See https://bugzilla.mozilla.org/show_bug.cgi?id=923225 - if ($window.webrtcDetectedVersion >= 36 && firefoxExtension.available) { - this.supported = true; + if ($window.webrtcDetectedVersion >= 36) { this.prepare = function(options) { return selectFirefoxScreenToShare(options); }; - } else { - - if (firefoxExtension.autoinstall.force) { - this.supported = false; + if (!firefoxExtension.autoinstall.force) { + this.supported = true; } - } } else { From 160d3bb17217804c20a98a9242cb13a3726d7783 Mon Sep 17 00:00:00 2001 From: Evan Theurer Date: Mon, 2 Nov 2015 16:03:30 +0100 Subject: [PATCH 13/16] Add explanation how to enable firefox screensharing via flag. --- static/js/directives/screenshare.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/static/js/directives/screenshare.js b/static/js/directives/screenshare.js index 0b069375..e105b626 100644 --- a/static/js/directives/screenshare.js +++ b/static/js/directives/screenshare.js @@ -22,7 +22,7 @@ "use strict"; define(['jquery', 'underscore', 'text!partials/screenshare.html', 'text!partials/screensharepeer.html', 'bigscreen', 'webrtc.adapter'], function($, _, template, templatePeer, BigScreen) { - return ["$window", "mediaStream", "$compile", "safeApply", "videoWaiter", "$timeout", "alertify", "translation", "screensharing", function($window, mediaStream, $compile, safeApply, videoWaiter, $timeout, alertify, translation, screensharing) { + return ["$window", "mediaStream", "$compile", "safeApply", "videoWaiter", "$timeout", "alertify", "translation", "screensharing", "$location", function($window, mediaStream, $compile, safeApply, videoWaiter, $timeout, alertify, translation, screensharing, $location) { var peerTemplate = $compile(templatePeer); @@ -279,9 +279,13 @@ define(['jquery', 'underscore', 'text!partials/screenshare.html', 'text!partials switch (error.name) { case "PermissionDeniedError": case "InvalidStateError": - if ($window.webrtcDetectedVersion >= 32 && + if ($window.webrtcDetectedBrowser === "chrome" && + $window.webrtcDetectedVersion >= 32 && $window.webrtcDetectedVersion < 37) { alertify.dialog.alert(translation._("Permission to start screen sharing was denied. Make sure to have enabled screen sharing access for your browser. Copy chrome://flags/#enable-usermedia-screen-capture and open it with your browser and enable the flag on top. Then restart the browser and you are ready to go.")); + } else if ($window.webrtcDetectedBrowser === "firefox" && + $window.webrtcDetectedVersion >= 36) { + alertify.dialog.alert(translation._("Permission to start screen sharing was denied. Make sure to have enabled screen sharing access for your browser. Copy about:config?filter=screensharing.allowed_domains and open it with your browser, double click the option, and add the domain %s to the list (include a comma). Then you are ready to go. Otherwise install the Firefox screensharing extension.", $location.host())); } else { alertify.dialog.alert(translation._("Permission to start screen sharing was denied.")); } From 481c7453ce7a86f0f1024716325b7f2fb5f34428 Mon Sep 17 00:00:00 2001 From: Evan Theurer Date: Mon, 2 Nov 2015 17:16:26 +0100 Subject: [PATCH 14/16] Improve initialize of firefox extension. --- static/js/services/firefoxextension.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/static/js/services/firefoxextension.js b/static/js/services/firefoxextension.js index b4c4cd91..1774f303 100644 --- a/static/js/services/firefoxextension.js +++ b/static/js/services/firefoxextension.js @@ -41,12 +41,11 @@ define(["underscore", "jquery", "webrtc.adapter"], function(_, $) { }; FirefoxExtension.prototype.initialize = function() { - var marker = $window.document.getElementById("firefoxextension-available"); - if (marker) { + if (isAvailable()) { this.available = true; console.log("Firefox extension is available."); this.e.triggerHandler("available", true); - } else if (!marker && this.available) { + } else if (this.available) { this.available = false; console.log("Firefox extension is no longer available."); this.e.triggerHandler("available", false); From 29d3fdd0bf4856374fab38c5f914082c20d625a9 Mon Sep 17 00:00:00 2001 From: Evan Theurer Date: Mon, 2 Nov 2015 17:18:29 +0100 Subject: [PATCH 15/16] Change when to show the firefox extension install dialog. --- static/js/services/screensharing.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/static/js/services/screensharing.js b/static/js/services/screensharing.js index 3b202ad4..28dd9ac8 100644 --- a/static/js/services/screensharing.js +++ b/static/js/services/screensharing.js @@ -179,7 +179,9 @@ define(['underscore', 'text!partials/screensharedialogff.html', 'webrtc.adapter' this.prepare = function(options) { return selectFirefoxScreenToShare(options); }; - if (!firefoxExtension.autoinstall.force) { + if (firefoxExtension.available) { + this.supported = true; + } else if (!firefoxExtension.autoinstall.force) { this.supported = true; } } @@ -268,9 +270,7 @@ define(['underscore', 'text!partials/screensharedialogff.html', 'webrtc.adapter' }); }; firefoxExtension.detectInstalled(30000).then(function() { - if (!that.autoinstall && that.supported) { - starter(); - } + starter(); }, function(reason) { d.reject(reason); }); From 8a4205bc8d28c185f964df97898298690142816d Mon Sep 17 00:00:00 2001 From: Evan Theurer Date: Mon, 2 Nov 2015 18:15:07 +0100 Subject: [PATCH 16/16] Fix depth of if statement firefox screensharing check. --- static/js/services/screensharing.js | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/static/js/services/screensharing.js b/static/js/services/screensharing.js index 28dd9ac8..b5f3cfc5 100644 --- a/static/js/services/screensharing.js +++ b/static/js/services/screensharing.js @@ -171,19 +171,17 @@ define(['underscore', 'text!partials/screensharedialogff.html', 'webrtc.adapter' } - } else if ($window.webrtcDetectedBrowser === "firefox") { + } else if ($window.webrtcDetectedBrowser === "firefox" && $window.webrtcDetectedVersion >= 36) { // Firefox 36 got screen sharing support. // See https://bugzilla.mozilla.org/show_bug.cgi?id=923225 - if ($window.webrtcDetectedVersion >= 36) { - this.prepare = function(options) { - return selectFirefoxScreenToShare(options); - }; - if (firefoxExtension.available) { - this.supported = true; - } else if (!firefoxExtension.autoinstall.force) { - this.supported = true; - } + this.prepare = function(options) { + return selectFirefoxScreenToShare(options); + }; + if (firefoxExtension.available) { + this.supported = true; + } else if (!firefoxExtension.autoinstall.force) { + this.supported = true; } } else {