Explorar el Código

Implements getDisplayMedia when available on chrome.

dev1
damencho hace 7 años
padre
commit
9f123f3426
Se han modificado 3 ficheros con 71 adiciones y 13 borrados
  1. 26
    2
      modules/RTC/RTCUtils.js
  2. 37
    11
      modules/RTC/ScreenObtainer.js
  3. 8
    0
      modules/browser/BrowserCapabilities.js

+ 26
- 2
modules/RTC/RTCUtils.js Ver fichero

@@ -473,6 +473,28 @@ function getSSConstraints(options = {}) {
473 473
     return constraints;
474 474
 }
475 475
 
476
+/**
477
+ * Generates constraints for screen sharing when using getDisplayMedia.
478
+ * The constraints(MediaTrackConstraints) are applied to the resulting track.
479
+ *
480
+ * @returns {Object} - MediaTrackConstraints constraints.
481
+ */
482
+function getTrackSSConstraints(options = {}) {
483
+    // we used to set height and width in the constraints, but this can lead
484
+    // to inconsistencies if the browser is on a lower resolution screen
485
+    // and we share a screen with bigger resolution, so they are now not set
486
+    const constraints = {
487
+        frameRate: SS_DEFAULT_FRAME_RATE
488
+    };
489
+    const { desktopSharingFrameRate } = options;
490
+
491
+    if (desktopSharingFrameRate && desktopSharingFrameRate.max) {
492
+        constraints.frameRate = desktopSharingFrameRate.max;
493
+    }
494
+
495
+    return constraints;
496
+}
497
+
476 498
 /**
477 499
  * Sets the availbale devices based on the options we requested and the
478 500
  * streams we received.
@@ -1058,7 +1080,8 @@ class RTCUtils extends Listenable {
1058 1080
                 {
1059 1081
                     ...desktopSharingExtensionExternalInstallation,
1060 1082
                     desktopSharingSources,
1061
-                    gumOptions
1083
+                    gumOptions,
1084
+                    trackOptions: getTrackSSConstraints(options)
1062 1085
                 },
1063 1086
                 stream => {
1064 1087
                     resolve(stream);
@@ -1251,7 +1274,8 @@ class RTCUtils extends Listenable {
1251 1274
             desktopSharingSources: options.desktopSharingSources,
1252 1275
             gumOptions: {
1253 1276
                 frameRate: options.desktopSharingFrameRate
1254
-            }
1277
+            },
1278
+            trackOptions: getTrackSSConstraints(options)
1255 1279
         };
1256 1280
     }
1257 1281
 

+ 37
- 11
modules/RTC/ScreenObtainer.js Ver fichero

@@ -167,11 +167,13 @@ const ScreenObtainer = {
167 167
                 logger.info('Chrome extension not supported until ver 34');
168 168
 
169 169
                 return null;
170
+            } else if (browser.supportsGetDisplayMedia()
171
+                        && !options.desktopSharingChromeDisabled) {
172
+
173
+                return this.obtainScreenFromGetDisplayMedia;
170 174
             } else if (options.desktopSharingChromeDisabled
171
-                || options.desktopSharingChromeMethod === false
172 175
                 || !options.desktopSharingChromeExtId) {
173 176
 
174
-                // TODO: desktopSharingChromeMethod is deprecated, remove.
175 177
                 return null;
176 178
             }
177 179
 
@@ -193,15 +195,8 @@ const ScreenObtainer = {
193 195
             }
194 196
 
195 197
             return this.obtainScreenOnFirefox;
196
-        } else if (browser.isEdge() && navigator.getDisplayMedia) {
197
-            return (_, onSuccess, onFailure) => {
198
-                navigator.getDisplayMedia({ video: true })
199
-                    .then(stream => onSuccess({
200
-                        stream,
201
-                        sourceId: stream.id
202
-                    }))
203
-                    .catch(onFailure);
204
-            };
198
+        } else if (browser.isEdge() && browser.supportsGetDisplayMedia()) {
199
+            return this.obtainScreenFromGetDisplayMedia;
205 200
         }
206 201
 
207 202
         logger.log(
@@ -423,6 +418,37 @@ const ScreenObtainer = {
423 418
                 this.checkForChromeExtensionOnInterval(options,
424 419
                     streamCallback, failCallback);
425 420
             });
421
+    },
422
+
423
+    /**
424
+     * Obtains a screen capture stream using getDisplayMedia.
425
+     *
426
+     * @param callback - The success callback.
427
+     * @param errorCallback - The error callback.
428
+     */
429
+    obtainScreenFromGetDisplayMedia(options, callback, errorCallback) {
430
+        navigator.getDisplayMedia({ video: true })
431
+            .then(stream => {
432
+                let applyConstraintsPromise;
433
+
434
+                if (stream
435
+                    && stream.getTracks()
436
+                    && stream.getTracks().length > 0) {
437
+                    applyConstraintsPromise = stream.getTracks()[0]
438
+                        .applyConstraints(options.trackOptions);
439
+                } else {
440
+                    applyConstraintsPromise = Promise.resolve();
441
+                }
442
+
443
+                applyConstraintsPromise.then(() =>
444
+                    callback({
445
+                        stream,
446
+                        sourceId: stream.id
447
+                    }));
448
+            })
449
+            .catch(() =>
450
+                errorCallback(new JitsiTrackError(JitsiTrackErrors
451
+                    .CHROME_EXTENSION_USER_CANCELED)));
426 452
     }
427 453
 };
428 454
 

+ 8
- 0
modules/browser/BrowserCapabilities.js Ver fichero

@@ -247,4 +247,12 @@ export default class BrowserCapabilities extends BrowserDetection {
247 247
     usesAdapter() {
248 248
         return this.usesNewGumFlow() || this.isEdge();
249 249
     }
250
+
251
+    /**
252
+     * Checks if the browser supposrts getDisplayMedia.
253
+     * @returns {boolean} {@code true} if the browser supposrts getDisplayMedia.
254
+     */
255
+    supportsGetDisplayMedia() {
256
+        return navigator.getDisplayMedia !== undefined;
257
+    }
250 258
 }

Loading…
Cancelar
Guardar