Browse Source

Move detection of Firefox extension installation to firefoxExtension service.

pull/238/head
Evan Theurer 11 years ago
parent
commit
de5bac2919
  1. 39
      static/js/services/firefoxextension.js
  2. 26
      static/js/services/screensharing.js

39
static/js/services/firefoxextension.js

@ -23,7 +23,7 @@ @@ -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(_, $) { @@ -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.

26
static/js/services/screensharing.js

@ -36,7 +36,7 @@ define(['underscore', 'text!partials/screensharedialogff.html', 'webrtc.adapter' @@ -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' @@ -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) {

Loading…
Cancel
Save