From 564db6de0aa8b789bb7a21fe7f4b30ead79f7ce5 Mon Sep 17 00:00:00 2001 From: Simon Eisenmann Date: Sun, 20 Jul 2014 21:05:04 +0200 Subject: [PATCH] Try to get screensharing auto started after inline installation of extension. --- static/js/services/screensharing.js | 38 +++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 8 deletions(-) diff --git a/static/js/services/screensharing.js b/static/js/services/screensharing.js index 925128c8..056f59be 100644 --- a/static/js/services/screensharing.js +++ b/static/js/services/screensharing.js @@ -21,7 +21,7 @@ define(['underscore', 'webrtc.adapter'], function(_) { // screensharing - return ["$window", "$q", "chromeExtension", function($window, $q, chromeExtension) { + return ["$window", "$q", "$timeout", "chromeExtension", function($window, $q, $timeout, chromeExtension) { var Screensharing = function() { this.autoinstall = false; @@ -120,6 +120,7 @@ define(['underscore', 'webrtc.adapter'], function(_) { if (!this.supported && chromeExtension.autoinstall.install) { this.supported = this.autoinstall = true; var that = this; + var waiting = false; this.prepare = function(options) { var d = $q.defer(); var install = chromeExtension.autoinstall.install(); @@ -129,13 +130,33 @@ define(['underscore', 'webrtc.adapter'], function(_) { // We are still on auto install - must have failed. d.reject("Auto install failed"); } else { - // Seems we can do it now. - var prepare = that.prepare(options); - prepare.then(function(id) { - d.resolve(id); - }, function(err) { - d.reject(err); - }); + // Seems we triggered install - this can take a while. + console.log("Auto install success"); + waiting = true; + $timeout(function() { + var starter = function() { + waiting = false; + var prepare = that.prepare(options); + prepare.then(function(id) { + d.resolve(id); + }, function(err) { + d.reject(err); + }); + }; + if (!that.autoinstall && that.supported) { + // Got something. + starter(); + } else { + // Wait for it. + chromeExtension.e.one("available", function() { + $timeout(function() { + if (waiting && !that.autoinstall && that.supported) { + starter(); + } + }, 0); + }); + } + }, 0); } }, function(err) { d.reject(err); @@ -146,6 +167,7 @@ define(['underscore', 'webrtc.adapter'], function(_) { if (chromeExtension.autoinstall.cancel) { chromeExtension.autoinstall.cancel(); } + waiting = false; }; } else { this.autoinstall = false;