|
@@ -1,11 +1,11 @@
|
1
|
1
|
/* global chrome, $, alert */
|
2
|
2
|
|
|
3
|
+var AdapterJS = require("./adapter.screenshare");
|
|
4
|
+var GlobalOnErrorHandler = require("../util/GlobalOnErrorHandler");
|
3
|
5
|
var logger = require("jitsi-meet-logger").getLogger(__filename);
|
4
|
6
|
var RTCBrowserType = require("./RTCBrowserType");
|
5
|
|
-var AdapterJS = require("./adapter.screenshare");
|
6
|
7
|
import JitsiTrackError from "../../JitsiTrackError";
|
7
|
8
|
import * as JitsiTrackErrors from "../../JitsiTrackErrors";
|
8
|
|
-var GlobalOnErrorHandler = require("../util/GlobalOnErrorHandler");
|
9
|
9
|
|
10
|
10
|
/**
|
11
|
11
|
* Indicates whether the Chrome desktop sharing extension is installed.
|
|
@@ -54,6 +54,7 @@ const CHROME_NO_EXTENSION_ERROR_MSG // eslint-disable-line no-unused-vars
|
54
|
54
|
*/
|
55
|
55
|
var ScreenObtainer = {
|
56
|
56
|
obtainStream: null,
|
|
57
|
+
|
57
|
58
|
/**
|
58
|
59
|
* Initializes the function used to obtain a screen capture
|
59
|
60
|
* (this.obtainStream).
|
|
@@ -68,7 +69,7 @@ var ScreenObtainer = {
|
68
|
69
|
* @param options {object}
|
69
|
70
|
* @param gum {Function} GUM method
|
70
|
71
|
*/
|
71
|
|
- init: function(options, gum) {
|
|
72
|
+ init(options, gum) {
|
72
|
73
|
var obtainDesktopStream = null;
|
73
|
74
|
this.options = options = options || {};
|
74
|
75
|
GUM = gum;
|
|
@@ -81,9 +82,10 @@ var ScreenObtainer = {
|
81
|
82
|
(options.desktopSharingChromeMethod || options.desktopSharing);
|
82
|
83
|
|
83
|
84
|
if (RTCBrowserType.isNWJS()) {
|
84
|
|
- obtainDesktopStream = function (options, onSuccess, onFailure) {
|
|
85
|
+ obtainDesktopStream = (options, onSuccess, onFailure) => {
|
85
|
86
|
window.JitsiMeetNW.obtainDesktopStream (
|
86
|
|
- onSuccess, function (error, constraints) {
|
|
87
|
+ onSuccess,
|
|
88
|
+ (error, constraints) => {
|
87
|
89
|
var jitsiError;
|
88
|
90
|
// FIXME:
|
89
|
91
|
// This is very very durty fix for recognising that the
|
|
@@ -148,7 +150,6 @@ var ScreenObtainer = {
|
148
|
150
|
} else {
|
149
|
151
|
obtainDesktopStream = this.obtainScreenOnFirefox;
|
150
|
152
|
}
|
151
|
|
-
|
152
|
153
|
}
|
153
|
154
|
|
154
|
155
|
if (!obtainDesktopStream) {
|
|
@@ -163,17 +164,16 @@ var ScreenObtainer = {
|
163
|
164
|
* environment.
|
164
|
165
|
* @returns {boolean}
|
165
|
166
|
*/
|
166
|
|
- isSupported: function() {
|
|
167
|
+ isSupported() {
|
167
|
168
|
return !!this.obtainStream;
|
168
|
169
|
},
|
|
170
|
+
|
169
|
171
|
/**
|
170
|
172
|
* Obtains a screen capture stream on Firefox.
|
171
|
173
|
* @param callback
|
172
|
174
|
* @param errorCallback
|
173
|
175
|
*/
|
174
|
|
- obtainScreenOnFirefox:
|
175
|
|
- function (options, callback, errorCallback) {
|
176
|
|
- var self = this;
|
|
176
|
+ obtainScreenOnFirefox(options, callback, errorCallback) {
|
177
|
177
|
var extensionRequired = false;
|
178
|
178
|
if (this.options.desktopSharingFirefoxMaxVersionExtRequired === -1 ||
|
179
|
179
|
(this.options.desktopSharingFirefoxMaxVersionExtRequired >= 0 &&
|
|
@@ -198,13 +198,12 @@ var ScreenObtainer = {
|
198
|
198
|
// extension if it hasn't.
|
199
|
199
|
if (firefoxExtInstalled === null) {
|
200
|
200
|
window.setTimeout(
|
201
|
|
- function() {
|
|
201
|
+ () => {
|
202
|
202
|
if (firefoxExtInstalled === null)
|
203
|
203
|
firefoxExtInstalled = false;
|
204
|
|
- self.obtainScreenOnFirefox(callback, errorCallback);
|
|
204
|
+ this.obtainScreenOnFirefox(callback, errorCallback);
|
205
|
205
|
},
|
206
|
|
- 300
|
207
|
|
- );
|
|
206
|
+ 300);
|
208
|
207
|
logger.log("Waiting for detection of jidesha on firefox to " +
|
209
|
208
|
"finish.");
|
210
|
209
|
return;
|
|
@@ -221,11 +220,12 @@ var ScreenObtainer = {
|
221
|
220
|
errorCallback(
|
222
|
221
|
new JitsiTrackError(JitsiTrackErrors.FIREFOX_EXTENSION_NEEDED));
|
223
|
222
|
},
|
|
223
|
+
|
224
|
224
|
/**
|
225
|
225
|
* Asks Chrome extension to call chooseDesktopMedia and gets chrome
|
226
|
226
|
* 'desktop' stream for returned stream token.
|
227
|
227
|
*/
|
228
|
|
- obtainScreenFromExtension: function(options, streamCallback, failCallback) {
|
|
228
|
+ obtainScreenFromExtension(options, streamCallback, failCallback) {
|
229
|
229
|
if (chromeExtInstalled) {
|
230
|
230
|
doGetStreamFromExtension(this.options, streamCallback,
|
231
|
231
|
failCallback);
|
|
@@ -239,20 +239,18 @@ var ScreenObtainer = {
|
239
|
239
|
try {
|
240
|
240
|
chrome.webstore.install(
|
241
|
241
|
getWebStoreInstallUrl(this.options),
|
242
|
|
- (arg) => {
|
|
242
|
+ arg => {
|
243
|
243
|
logger.log("Extension installed successfully", arg);
|
244
|
244
|
chromeExtInstalled = true;
|
245
|
|
- // We need to give a moment for the endpoint to become
|
246
|
|
- // available
|
|
245
|
+ // We need to give a moment to the endpoint to become
|
|
246
|
+ // available.
|
247
|
247
|
waitForExtensionAfterInstall(this.options, 200, 10)
|
248
|
248
|
.then(() => {
|
249
|
249
|
doGetStreamFromExtension(this.options,
|
250
|
250
|
streamCallback, failCallback);
|
251
|
|
- }).catch(() => {
|
252
|
|
- // options param is {} because we won't do
|
253
|
|
- // external install in this case.
|
254
|
|
- this.handleExtensionInstallationError({},
|
255
|
|
- streamCallback, failCallback);
|
|
251
|
+ }).catch(reason => {
|
|
252
|
+ this.handleExtensionInstallationError(options,
|
|
253
|
+ streamCallback, failCallback, reason);
|
256
|
254
|
});
|
257
|
255
|
},
|
258
|
256
|
this.handleExtensionInstallationError.bind(this,
|
|
@@ -264,29 +262,30 @@ var ScreenObtainer = {
|
264
|
262
|
}
|
265
|
263
|
}
|
266
|
264
|
},
|
267
|
|
- handleExtensionInstallationError: function (options, streamCallback,
|
268
|
|
- failCallback, e) {
|
269
|
|
- if( CHROME_EXTENSION_POPUP_ERROR === e && options.interval > 0 &&
|
270
|
|
- typeof(options.checkAgain) === "function" &&
|
271
|
|
- typeof(options.listener) === "function") {
|
272
|
|
- options.listener("waitingForExtension",
|
273
|
|
- getWebStoreInstallUrl(this.options));
|
274
|
|
- this.checkForChromeExtensionOnInterval(options,
|
275
|
|
- streamCallback, failCallback, e);
|
|
265
|
+
|
|
266
|
+ handleExtensionInstallationError(options, streamCallback, failCallback, e) {
|
|
267
|
+ const webStoreInstallUrl = getWebStoreInstallUrl(this.options);
|
|
268
|
+
|
|
269
|
+ if (CHROME_EXTENSION_POPUP_ERROR === e
|
|
270
|
+ && options.interval > 0
|
|
271
|
+ && typeof(options.checkAgain) === "function"
|
|
272
|
+ && typeof(options.listener) === "function") {
|
|
273
|
+ options.listener("waitingForExtension", webStoreInstallUrl);
|
|
274
|
+ this.checkForChromeExtensionOnInterval(options, streamCallback,
|
|
275
|
+ failCallback, e);
|
276
|
276
|
return;
|
277
|
277
|
}
|
278
|
|
- var msg = "Failed to install the extension from "
|
279
|
|
- + getWebStoreInstallUrl(this.options);
|
280
|
278
|
|
281
|
|
- logger.log(msg, e);
|
|
279
|
+ const msg
|
|
280
|
+ = "Failed to install the extension from " + webStoreInstallUrl;
|
282
|
281
|
|
|
282
|
+ logger.log(msg, e);
|
283
|
283
|
failCallback(new JitsiTrackError(
|
284
|
284
|
JitsiTrackErrors.CHROME_EXTENSION_INSTALLATION_ERROR,
|
285
|
|
- msg
|
286
|
|
- ));
|
|
285
|
+ msg));
|
287
|
286
|
},
|
288
|
|
- checkForChromeExtensionOnInterval: function (options,
|
289
|
|
- streamCallback, failCallback) {
|
|
287
|
+
|
|
288
|
+ checkForChromeExtensionOnInterval(options, streamCallback, failCallback) {
|
290
|
289
|
if (options.checkAgain() === false) {
|
291
|
290
|
failCallback(new JitsiTrackError(
|
292
|
291
|
JitsiTrackErrors.CHROME_EXTENSION_INSTALLATION_ERROR));
|
|
@@ -305,8 +304,6 @@ var ScreenObtainer = {
|
305
|
304
|
}
|
306
|
305
|
};
|
307
|
306
|
|
308
|
|
-
|
309
|
|
-
|
310
|
307
|
/**
|
311
|
308
|
* Obtains a desktop stream using getUserMedia.
|
312
|
309
|
* For this to work on Chrome, the
|
|
@@ -317,11 +314,7 @@ var ScreenObtainer = {
|
317
|
314
|
* 'about:config'.
|
318
|
315
|
*/
|
319
|
316
|
function obtainWebRTCScreen(options, streamCallback, failCallback) {
|
320
|
|
- GUM(
|
321
|
|
- ['screen'],
|
322
|
|
- streamCallback,
|
323
|
|
- failCallback
|
324
|
|
- );
|
|
317
|
+ GUM(['screen'], streamCallback, failCallback);
|
325
|
318
|
}
|
326
|
319
|
|
327
|
320
|
/**
|
|
@@ -386,7 +379,7 @@ function checkChromeExtInstalled(callback, options) {
|
386
|
379
|
//TODO: remove chromeExtensionId (deprecated)
|
387
|
380
|
(options.desktopSharingChromeExtId || options.chromeExtensionId),
|
388
|
381
|
{ getVersion: true },
|
389
|
|
- function (response) {
|
|
382
|
+ response => {
|
390
|
383
|
if (!response || !response.version) {
|
391
|
384
|
// Communication failure - assume that no endpoint exists
|
392
|
385
|
logger.warn(
|
|
@@ -420,7 +413,7 @@ function doGetStreamFromExtension(options, streamCallback, failCallback) {
|
420
|
413
|
sources: (options.desktopSharingChromeSources ||
|
421
|
414
|
options.desktopSharingSources)
|
422
|
415
|
},
|
423
|
|
- function (response) {
|
|
416
|
+ response => {
|
424
|
417
|
if (!response) {
|
425
|
418
|
// possibly re-wraping error message to make code consistent
|
426
|
419
|
var lastError = chrome.runtime.lastError;
|
|
@@ -435,11 +428,9 @@ function doGetStreamFromExtension(options, streamCallback, failCallback) {
|
435
|
428
|
if (response.streamId) {
|
436
|
429
|
GUM(
|
437
|
430
|
['desktop'],
|
438
|
|
- function (stream) {
|
439
|
|
- streamCallback(stream);
|
440
|
|
- },
|
|
431
|
+ stream => streamCallback(stream),
|
441
|
432
|
failCallback,
|
442
|
|
- {desktopStream: response.streamId});
|
|
433
|
+ { desktopStream: response.streamId });
|
443
|
434
|
} else {
|
444
|
435
|
// As noted in Chrome Desktop Capture API:
|
445
|
436
|
// If user didn't select any source (i.e. canceled the prompt)
|
|
@@ -478,7 +469,7 @@ function initChromeExtension(options) {
|
478
|
469
|
// Initialize Chrome extension inline installs
|
479
|
470
|
initInlineInstalls(options);
|
480
|
471
|
// Check if extension is installed
|
481
|
|
- checkChromeExtInstalled(function (installed, updateRequired) {
|
|
472
|
+ checkChromeExtInstalled((installed, updateRequired) => {
|
482
|
473
|
chromeExtInstalled = installed;
|
483
|
474
|
chromeExtUpdateRequired = updateRequired;
|
484
|
475
|
logger.info(
|
|
@@ -536,11 +527,11 @@ function initFirefoxExtensionDetection(options) {
|
536
|
527
|
}
|
537
|
528
|
|
538
|
529
|
var img = document.createElement('img');
|
539
|
|
- img.onload = function(){
|
|
530
|
+ img.onload = () => {
|
540
|
531
|
logger.log("Detected firefox screen sharing extension.");
|
541
|
532
|
firefoxExtInstalled = true;
|
542
|
533
|
};
|
543
|
|
- img.onerror = function(){
|
|
534
|
+ img.onerror = () => {
|
544
|
535
|
logger.log("Detected lack of firefox screen sharing extension.");
|
545
|
536
|
firefoxExtInstalled = false;
|
546
|
537
|
};
|