|
@@ -1,33 +1,12 @@
|
1
|
|
-/* global chrome, $, alert */
|
2
|
1
|
|
3
|
2
|
import JitsiTrackError from '../../JitsiTrackError';
|
4
|
3
|
import * as JitsiTrackErrors from '../../JitsiTrackErrors';
|
5
|
4
|
import browser from '../browser';
|
6
|
5
|
|
7
|
6
|
const logger = require('jitsi-meet-logger').getLogger(__filename);
|
8
|
|
-const GlobalOnErrorHandler = require('../util/GlobalOnErrorHandler');
|
9
|
|
-
|
10
|
|
-/**
|
11
|
|
- * Indicates whether the Chrome desktop sharing extension is installed.
|
12
|
|
- * @type {boolean}
|
13
|
|
- */
|
14
|
|
-let chromeExtInstalled = false;
|
15
|
|
-
|
16
|
|
-/**
|
17
|
|
- * Indicates whether an update of the Chrome desktop sharing extension is
|
18
|
|
- * required.
|
19
|
|
- * @type {boolean}
|
20
|
|
- */
|
21
|
|
-let chromeExtUpdateRequired = false;
|
22
|
7
|
|
23
|
8
|
let gumFunction = null;
|
24
|
9
|
|
25
|
|
-/**
|
26
|
|
- * The error message returned by chrome when the extension is installed.
|
27
|
|
- */
|
28
|
|
-const CHROME_NO_EXTENSION_ERROR_MSG // eslint-disable-line no-unused-vars
|
29
|
|
- = 'Could not establish connection. Receiving end does not exist.';
|
30
|
|
-
|
31
|
10
|
/**
|
32
|
11
|
* Handles obtaining a stream from a screen capture on different browsers.
|
33
|
12
|
*/
|
|
@@ -38,7 +17,6 @@ const ScreenObtainer = {
|
38
|
17
|
* after it's done.
|
39
|
18
|
* {@type Promise|null}
|
40
|
19
|
*/
|
41
|
|
- intChromeExtPromise: null,
|
42
|
20
|
|
43
|
21
|
obtainStream: null,
|
44
|
22
|
|
|
@@ -47,20 +25,13 @@ const ScreenObtainer = {
|
47
|
25
|
* (this.obtainStream).
|
48
|
26
|
*
|
49
|
27
|
* @param {object} options
|
50
|
|
- * @param {boolean} [options.desktopSharingChromeDisabled]
|
51
|
|
- * @param {boolean} [options.desktopSharingChromeExtId]
|
52
|
|
- * @param {boolean} [options.desktopSharingFirefoxDisabled]
|
53
|
28
|
* @param {Function} gum GUM method
|
54
|
29
|
*/
|
55
|
|
- init(options = {
|
56
|
|
- desktopSharingChromeDisabled: false,
|
57
|
|
- desktopSharingChromeExtId: null,
|
58
|
|
- desktopSharingFirefoxDisabled: false
|
59
|
|
- }, gum) {
|
|
30
|
+ init(options = {}, gum) {
|
60
|
31
|
this.options = options;
|
61
|
32
|
gumFunction = gum;
|
62
|
33
|
|
63
|
|
- this.obtainStream = this._createObtainStreamMethod(options);
|
|
34
|
+ this.obtainStream = this._createObtainStreamMethod();
|
64
|
35
|
|
65
|
36
|
if (!this.obtainStream) {
|
66
|
37
|
logger.info('Desktop sharing disabled');
|
|
@@ -71,12 +42,10 @@ const ScreenObtainer = {
|
71
|
42
|
* Returns a method which will be used to obtain the screen sharing stream
|
72
|
43
|
* (based on the browser type).
|
73
|
44
|
*
|
74
|
|
- * @param {object} options passed from {@link init} - check description
|
75
|
|
- * there
|
76
|
45
|
* @returns {Function}
|
77
|
46
|
* @private
|
78
|
47
|
*/
|
79
|
|
- _createObtainStreamMethod(options) {
|
|
48
|
+ _createObtainStreamMethod() {
|
80
|
49
|
if (browser.isNWJS()) {
|
81
|
50
|
return (_, onSuccess, onFailure) => {
|
82
|
51
|
window.JitsiMeetNW.obtainDesktopStream(
|
|
@@ -102,7 +71,7 @@ const ScreenObtainer = {
|
102
|
71
|
|
103
|
72
|
if (error && error.name === 'InvalidStateError') {
|
104
|
73
|
jitsiError = new JitsiTrackError(
|
105
|
|
- JitsiTrackErrors.CHROME_EXTENSION_USER_CANCELED
|
|
74
|
+ JitsiTrackErrors.SCREENSHARING_USER_CANCELED
|
106
|
75
|
);
|
107
|
76
|
} else {
|
108
|
77
|
jitsiError = new JitsiTrackError(
|
|
@@ -114,41 +83,10 @@ const ScreenObtainer = {
|
114
|
83
|
};
|
115
|
84
|
} else if (browser.isElectron()) {
|
116
|
85
|
return this.obtainScreenOnElectron;
|
117
|
|
- } else if (browser.isChrome() || browser.isOpera()) {
|
118
|
|
- if (browser.supportsGetDisplayMedia()
|
119
|
|
- && !options.desktopSharingChromeDisabled) {
|
120
|
|
-
|
121
|
|
- return this.obtainScreenFromGetDisplayMedia;
|
122
|
|
- } else if (options.desktopSharingChromeDisabled
|
123
|
|
- || !options.desktopSharingChromeExtId) {
|
124
|
|
-
|
125
|
|
- return null;
|
126
|
|
- }
|
127
|
|
-
|
128
|
|
- logger.info('Using Chrome extension for desktop sharing');
|
129
|
|
- this.intChromeExtPromise
|
130
|
|
- = initChromeExtension(options).then(() => {
|
131
|
|
- this.intChromeExtPromise = null;
|
132
|
|
- });
|
133
|
|
-
|
134
|
|
- return this.obtainScreenFromExtension;
|
135
|
|
- } else if (browser.isFirefox()) {
|
136
|
|
- if (options.desktopSharingFirefoxDisabled) {
|
137
|
|
- return null;
|
138
|
|
- } else if (browser.supportsGetDisplayMedia()) {
|
139
|
|
- // Firefox 66 support getDisplayMedia
|
140
|
|
- return this.obtainScreenFromGetDisplayMedia;
|
141
|
|
- }
|
142
|
|
-
|
143
|
|
- // Legacy Firefox
|
144
|
|
- return this.obtainScreenOnFirefox;
|
145
|
|
- } else if (browser.isSafari() && browser.supportsGetDisplayMedia()) {
|
|
86
|
+ } else if (browser.supportsGetDisplayMedia()) {
|
146
|
87
|
return this.obtainScreenFromGetDisplayMedia;
|
147
|
88
|
}
|
148
|
|
-
|
149
|
|
- logger.log(
|
150
|
|
- 'Screen sharing not supported by the current browser: ',
|
151
|
|
- browser.getName());
|
|
89
|
+ logger.log('Screen sharing not supported on ', browser.getName());
|
152
|
90
|
|
153
|
91
|
return null;
|
154
|
92
|
},
|
|
@@ -162,15 +100,6 @@ const ScreenObtainer = {
|
162
|
100
|
return this.obtainStream !== null;
|
163
|
101
|
},
|
164
|
102
|
|
165
|
|
- /**
|
166
|
|
- * Obtains a screen capture stream on Firefox.
|
167
|
|
- * @param callback
|
168
|
|
- * @param errorCallback
|
169
|
|
- */
|
170
|
|
- obtainScreenOnFirefox(options, callback, errorCallback) {
|
171
|
|
- obtainWebRTCScreen(options.gumOptions, callback, errorCallback);
|
172
|
|
- },
|
173
|
|
-
|
174
|
103
|
/**
|
175
|
104
|
* Obtains a screen capture stream on Electron.
|
176
|
105
|
*
|
|
@@ -215,88 +144,6 @@ const ScreenObtainer = {
|
215
|
144
|
}
|
216
|
145
|
},
|
217
|
146
|
|
218
|
|
- /**
|
219
|
|
- * Asks Chrome extension to call chooseDesktopMedia and gets chrome
|
220
|
|
- * 'desktop' stream for returned stream token.
|
221
|
|
- */
|
222
|
|
- obtainScreenFromExtension(options, streamCallback, failCallback) {
|
223
|
|
- if (this.intChromeExtPromise !== null) {
|
224
|
|
- this.intChromeExtPromise.then(() => {
|
225
|
|
- this.obtainScreenFromExtension(
|
226
|
|
- options, streamCallback, failCallback);
|
227
|
|
- });
|
228
|
|
-
|
229
|
|
- return;
|
230
|
|
- }
|
231
|
|
-
|
232
|
|
- const {
|
233
|
|
- desktopSharingChromeExtId,
|
234
|
|
- desktopSharingChromeSources
|
235
|
|
- } = this.options;
|
236
|
|
-
|
237
|
|
- const {
|
238
|
|
- gumOptions
|
239
|
|
- } = options;
|
240
|
|
-
|
241
|
|
- const doGetStreamFromExtensionOptions = {
|
242
|
|
- desktopSharingChromeExtId,
|
243
|
|
- desktopSharingChromeSources:
|
244
|
|
- options.desktopSharingSources || desktopSharingChromeSources,
|
245
|
|
- gumOptions
|
246
|
|
- };
|
247
|
|
-
|
248
|
|
- if (chromeExtInstalled) {
|
249
|
|
- doGetStreamFromExtension(
|
250
|
|
- doGetStreamFromExtensionOptions,
|
251
|
|
- streamCallback,
|
252
|
|
- failCallback);
|
253
|
|
- } else {
|
254
|
|
- if (chromeExtUpdateRequired) {
|
255
|
|
- /* eslint-disable no-alert */
|
256
|
|
- alert(
|
257
|
|
- 'Jitsi Desktop Streamer requires update. '
|
258
|
|
- + 'Changes will take effect after next Chrome restart.');
|
259
|
|
-
|
260
|
|
- /* eslint-enable no-alert */
|
261
|
|
- }
|
262
|
|
-
|
263
|
|
- this.handleExternalInstall(options, streamCallback,
|
264
|
|
- failCallback);
|
265
|
|
- }
|
266
|
|
- },
|
267
|
|
-
|
268
|
|
- /* eslint-disable max-params */
|
269
|
|
-
|
270
|
|
- handleExternalInstall(options, streamCallback, failCallback, e) {
|
271
|
|
- const webStoreInstallUrl = getWebStoreInstallUrl(this.options);
|
272
|
|
-
|
273
|
|
- options.listener('waitingForExtension', webStoreInstallUrl);
|
274
|
|
- this.checkForChromeExtensionOnInterval(options, streamCallback,
|
275
|
|
- failCallback, e);
|
276
|
|
- },
|
277
|
|
-
|
278
|
|
- /* eslint-enable max-params */
|
279
|
|
-
|
280
|
|
- checkForChromeExtensionOnInterval(options, streamCallback, failCallback) {
|
281
|
|
- if (options.checkAgain() === false) {
|
282
|
|
- failCallback(new JitsiTrackError(
|
283
|
|
- JitsiTrackErrors.CHROME_EXTENSION_INSTALLATION_ERROR));
|
284
|
|
-
|
285
|
|
- return;
|
286
|
|
- }
|
287
|
|
- waitForExtensionAfterInstall(this.options, options.interval, 1)
|
288
|
|
- .then(() => {
|
289
|
|
- chromeExtInstalled = true;
|
290
|
|
- options.listener('extensionFound');
|
291
|
|
- this.obtainScreenFromExtension(options,
|
292
|
|
- streamCallback, failCallback);
|
293
|
|
- })
|
294
|
|
- .catch(() => {
|
295
|
|
- this.checkForChromeExtensionOnInterval(options,
|
296
|
|
- streamCallback, failCallback);
|
297
|
|
- });
|
298
|
|
- },
|
299
|
|
-
|
300
|
147
|
/**
|
301
|
148
|
* Obtains a screen capture stream using getDisplayMedia.
|
302
|
149
|
*
|
|
@@ -341,236 +188,10 @@ const ScreenObtainer = {
|
341
|
188
|
})
|
342
|
189
|
.catch(() =>
|
343
|
190
|
errorCallback(new JitsiTrackError(JitsiTrackErrors
|
344
|
|
- .CHROME_EXTENSION_USER_CANCELED)));
|
|
191
|
+ .SCREENSHARING_USER_CANCELED)));
|
345
|
192
|
}
|
346
|
193
|
};
|
347
|
194
|
|
348
|
|
-/**
|
349
|
|
- * Obtains a desktop stream using getUserMedia.
|
350
|
|
- * For this to work on Chrome, the
|
351
|
|
- * 'chrome://flags/#enable-usermedia-screen-capture' flag must be enabled.
|
352
|
|
- *
|
353
|
|
- * On firefox, the document's domain must be white-listed in the
|
354
|
|
- * 'media.getusermedia.screensharing.allowed_domains' preference in
|
355
|
|
- * 'about:config'.
|
356
|
|
- */
|
357
|
|
-function obtainWebRTCScreen(options, streamCallback, failCallback) {
|
358
|
|
- gumFunction([ 'screen' ], options)
|
359
|
|
- .then(stream => streamCallback({ stream }), failCallback);
|
360
|
|
-}
|
361
|
|
-
|
362
|
|
-/**
|
363
|
|
- * Constructs inline install URL for Chrome desktop streaming extension.
|
364
|
|
- * The 'chromeExtensionId' must be defined in options parameter.
|
365
|
|
- * @param options supports "desktopSharingChromeExtId"
|
366
|
|
- * @returns {string}
|
367
|
|
- */
|
368
|
|
-function getWebStoreInstallUrl(options) {
|
369
|
|
- return (
|
370
|
|
- `https://chrome.google.com/webstore/detail/${
|
371
|
|
- options.desktopSharingChromeExtId}`);
|
372
|
|
-}
|
373
|
|
-
|
374
|
|
-/**
|
375
|
|
- * Checks whether an update of the Chrome extension is required.
|
376
|
|
- * @param minVersion minimal required version
|
377
|
|
- * @param extVersion current extension version
|
378
|
|
- * @returns {boolean}
|
379
|
|
- */
|
380
|
|
-function isUpdateRequired(minVersion, extVersion) {
|
381
|
|
- try {
|
382
|
|
- const s1 = minVersion.split('.');
|
383
|
|
- const s2 = extVersion.split('.');
|
384
|
|
-
|
385
|
|
- const len = Math.max(s1.length, s2.length);
|
386
|
|
-
|
387
|
|
- for (let i = 0; i < len; i++) {
|
388
|
|
- let n1 = 0,
|
389
|
|
- n2 = 0;
|
390
|
|
-
|
391
|
|
- if (i < s1.length) {
|
392
|
|
- n1 = parseInt(s1[i], 10);
|
393
|
|
- }
|
394
|
|
- if (i < s2.length) {
|
395
|
|
- n2 = parseInt(s2[i], 10);
|
396
|
|
- }
|
397
|
|
-
|
398
|
|
- if (isNaN(n1) || isNaN(n2)) {
|
399
|
|
- return true;
|
400
|
|
- } else if (n1 !== n2) {
|
401
|
|
- return n1 > n2;
|
402
|
|
- }
|
403
|
|
- }
|
404
|
|
-
|
405
|
|
- // will happen if both versions have identical numbers in
|
406
|
|
- // their components (even if one of them is longer, has more components)
|
407
|
|
- return false;
|
408
|
|
- } catch (e) {
|
409
|
|
- GlobalOnErrorHandler.callErrorHandler(e);
|
410
|
|
- logger.error('Failed to parse extension version', e);
|
411
|
|
-
|
412
|
|
- return true;
|
413
|
|
- }
|
414
|
|
-}
|
415
|
|
-
|
416
|
|
-/**
|
417
|
|
- *
|
418
|
|
- * @param callback
|
419
|
|
- * @param options
|
420
|
|
- */
|
421
|
|
-function checkChromeExtInstalled(callback, options) {
|
422
|
|
- if (typeof chrome === 'undefined' || !chrome || !chrome.runtime) {
|
423
|
|
- // No API, so no extension for sure
|
424
|
|
- callback(false, false);
|
425
|
|
-
|
426
|
|
- return;
|
427
|
|
- }
|
428
|
|
- chrome.runtime.sendMessage(
|
429
|
|
- options.desktopSharingChromeExtId,
|
430
|
|
- { getVersion: true },
|
431
|
|
- response => {
|
432
|
|
- if (!response || !response.version) {
|
433
|
|
- // Communication failure - assume that no endpoint exists
|
434
|
|
- logger.warn(
|
435
|
|
- 'Extension not installed?: ', chrome.runtime.lastError);
|
436
|
|
- callback(false, false);
|
437
|
|
-
|
438
|
|
- return;
|
439
|
|
- }
|
440
|
|
-
|
441
|
|
- // Check installed extension version
|
442
|
|
- const extVersion = response.version;
|
443
|
|
-
|
444
|
|
- logger.log(`Extension version is: ${extVersion}`);
|
445
|
|
- const updateRequired
|
446
|
|
- = isUpdateRequired(
|
447
|
|
- options.desktopSharingChromeMinExtVersion,
|
448
|
|
- extVersion);
|
449
|
|
-
|
450
|
|
- callback(!updateRequired, updateRequired);
|
451
|
|
- }
|
452
|
|
- );
|
453
|
|
-}
|
454
|
|
-
|
455
|
|
-/**
|
456
|
|
- *
|
457
|
|
- * @param options
|
458
|
|
- * @param streamCallback
|
459
|
|
- * @param failCallback
|
460
|
|
- */
|
461
|
|
-function doGetStreamFromExtension(options, streamCallback, failCallback) {
|
462
|
|
- const {
|
463
|
|
- desktopSharingChromeSources,
|
464
|
|
- desktopSharingChromeExtId,
|
465
|
|
- gumOptions
|
466
|
|
- } = options;
|
467
|
|
-
|
468
|
|
- // Sends 'getStream' msg to the extension.
|
469
|
|
- // Extension id must be defined in the config.
|
470
|
|
- chrome.runtime.sendMessage(
|
471
|
|
- desktopSharingChromeExtId,
|
472
|
|
- {
|
473
|
|
- getStream: true,
|
474
|
|
- sources: desktopSharingChromeSources
|
475
|
|
- },
|
476
|
|
- response => {
|
477
|
|
- if (!response) {
|
478
|
|
- // possibly re-wraping error message to make code consistent
|
479
|
|
- const lastError = chrome.runtime.lastError;
|
480
|
|
-
|
481
|
|
- failCallback(lastError instanceof Error
|
482
|
|
- ? lastError
|
483
|
|
- : new JitsiTrackError(
|
484
|
|
- JitsiTrackErrors.CHROME_EXTENSION_GENERIC_ERROR,
|
485
|
|
- lastError));
|
486
|
|
-
|
487
|
|
- return;
|
488
|
|
- }
|
489
|
|
- logger.log('Response from extension: ', response);
|
490
|
|
- onGetStreamResponse(
|
491
|
|
- {
|
492
|
|
- response,
|
493
|
|
- gumOptions
|
494
|
|
- },
|
495
|
|
- streamCallback,
|
496
|
|
- failCallback
|
497
|
|
- );
|
498
|
|
- }
|
499
|
|
- );
|
500
|
|
-}
|
501
|
|
-
|
502
|
|
-/**
|
503
|
|
- * Initializes <link rel=chrome-webstore-item /> with extension id set in
|
504
|
|
- * config.js to support inline installs. Host site must be selected as main
|
505
|
|
- * website of published extension.
|
506
|
|
- * @param options supports "desktopSharingChromeExtId"
|
507
|
|
- */
|
508
|
|
-function initInlineInstalls(options) {
|
509
|
|
- if ($('link[rel=chrome-webstore-item]').length === 0) {
|
510
|
|
- $('head').append('<link rel="chrome-webstore-item">');
|
511
|
|
- }
|
512
|
|
- $('link[rel=chrome-webstore-item]').attr('href',
|
513
|
|
- getWebStoreInstallUrl(options));
|
514
|
|
-}
|
515
|
|
-
|
516
|
|
-/**
|
517
|
|
- *
|
518
|
|
- * @param options
|
519
|
|
- *
|
520
|
|
- * @return {Promise} - a Promise resolved once the initialization process is
|
521
|
|
- * finished.
|
522
|
|
- */
|
523
|
|
-function initChromeExtension(options) {
|
524
|
|
- // Initialize Chrome extension inline installs
|
525
|
|
- initInlineInstalls(options);
|
526
|
|
-
|
527
|
|
- return new Promise(resolve => {
|
528
|
|
- // Check if extension is installed
|
529
|
|
- checkChromeExtInstalled((installed, updateRequired) => {
|
530
|
|
- chromeExtInstalled = installed;
|
531
|
|
- chromeExtUpdateRequired = updateRequired;
|
532
|
|
- logger.info(
|
533
|
|
- `Chrome extension installed: ${
|
534
|
|
- chromeExtInstalled} updateRequired: ${
|
535
|
|
- chromeExtUpdateRequired}`);
|
536
|
|
- resolve();
|
537
|
|
- }, options);
|
538
|
|
- });
|
539
|
|
-}
|
540
|
|
-
|
541
|
|
-/**
|
542
|
|
- * Checks "retries" times on every "waitInterval"ms whether the ext is alive.
|
543
|
|
- * @param {Object} options the options passed to ScreanObtainer.obtainStream
|
544
|
|
- * @param {int} waitInterval the number of ms between retries
|
545
|
|
- * @param {int} retries the number of retries
|
546
|
|
- * @returns {Promise} returns promise that will be resolved when the extension
|
547
|
|
- * is alive and rejected if the extension is not alive even after "retries"
|
548
|
|
- * checks
|
549
|
|
- */
|
550
|
|
-function waitForExtensionAfterInstall(options, waitInterval, retries) {
|
551
|
|
- if (retries === 0) {
|
552
|
|
- return Promise.reject();
|
553
|
|
- }
|
554
|
|
-
|
555
|
|
- return new Promise((resolve, reject) => {
|
556
|
|
- let currentRetries = retries;
|
557
|
|
- const interval = window.setInterval(() => {
|
558
|
|
- checkChromeExtInstalled(installed => {
|
559
|
|
- if (installed) {
|
560
|
|
- window.clearInterval(interval);
|
561
|
|
- resolve();
|
562
|
|
- } else {
|
563
|
|
- currentRetries--;
|
564
|
|
- if (currentRetries === 0) {
|
565
|
|
- reject();
|
566
|
|
- window.clearInterval(interval);
|
567
|
|
- }
|
568
|
|
- }
|
569
|
|
- }, options);
|
570
|
|
- }, waitInterval);
|
571
|
|
- });
|
572
|
|
-}
|
573
|
|
-
|
574
|
195
|
/**
|
575
|
196
|
* Handles response from external application / extension and calls GUM to
|
576
|
197
|
* receive the desktop streams or reports error.
|
|
@@ -614,13 +235,13 @@ function onGetStreamResponse(
|
614
|
235
|
// then the callback is called with an empty streamId.
|
615
|
236
|
if (streamId === '') {
|
616
|
237
|
onFailure(new JitsiTrackError(
|
617
|
|
- JitsiTrackErrors.CHROME_EXTENSION_USER_CANCELED));
|
|
238
|
+ JitsiTrackErrors.SCREENSHARING_USER_CANCELED));
|
618
|
239
|
|
619
|
240
|
return;
|
620
|
241
|
}
|
621
|
242
|
|
622
|
243
|
onFailure(new JitsiTrackError(
|
623
|
|
- JitsiTrackErrors.CHROME_EXTENSION_GENERIC_ERROR,
|
|
244
|
+ JitsiTrackErrors.SCREENSHARING_GENERIC_ERROR,
|
624
|
245
|
error));
|
625
|
246
|
}
|
626
|
247
|
}
|