浏览代码

Implements getDisplayMedia when available on chrome.

dev1
damencho 7 年前
父节点
当前提交
9f123f3426
共有 3 个文件被更改,包括 71 次插入13 次删除
  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 查看文件

473
     return constraints;
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
  * Sets the availbale devices based on the options we requested and the
499
  * Sets the availbale devices based on the options we requested and the
478
  * streams we received.
500
  * streams we received.
1058
                 {
1080
                 {
1059
                     ...desktopSharingExtensionExternalInstallation,
1081
                     ...desktopSharingExtensionExternalInstallation,
1060
                     desktopSharingSources,
1082
                     desktopSharingSources,
1061
-                    gumOptions
1083
+                    gumOptions,
1084
+                    trackOptions: getTrackSSConstraints(options)
1062
                 },
1085
                 },
1063
                 stream => {
1086
                 stream => {
1064
                     resolve(stream);
1087
                     resolve(stream);
1251
             desktopSharingSources: options.desktopSharingSources,
1274
             desktopSharingSources: options.desktopSharingSources,
1252
             gumOptions: {
1275
             gumOptions: {
1253
                 frameRate: options.desktopSharingFrameRate
1276
                 frameRate: options.desktopSharingFrameRate
1254
-            }
1277
+            },
1278
+            trackOptions: getTrackSSConstraints(options)
1255
         };
1279
         };
1256
     }
1280
     }
1257
 
1281
 

+ 37
- 11
modules/RTC/ScreenObtainer.js 查看文件

167
                 logger.info('Chrome extension not supported until ver 34');
167
                 logger.info('Chrome extension not supported until ver 34');
168
 
168
 
169
                 return null;
169
                 return null;
170
+            } else if (browser.supportsGetDisplayMedia()
171
+                        && !options.desktopSharingChromeDisabled) {
172
+
173
+                return this.obtainScreenFromGetDisplayMedia;
170
             } else if (options.desktopSharingChromeDisabled
174
             } else if (options.desktopSharingChromeDisabled
171
-                || options.desktopSharingChromeMethod === false
172
                 || !options.desktopSharingChromeExtId) {
175
                 || !options.desktopSharingChromeExtId) {
173
 
176
 
174
-                // TODO: desktopSharingChromeMethod is deprecated, remove.
175
                 return null;
177
                 return null;
176
             }
178
             }
177
 
179
 
193
             }
195
             }
194
 
196
 
195
             return this.obtainScreenOnFirefox;
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
         logger.log(
202
         logger.log(
423
                 this.checkForChromeExtensionOnInterval(options,
418
                 this.checkForChromeExtensionOnInterval(options,
424
                     streamCallback, failCallback);
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 查看文件

247
     usesAdapter() {
247
     usesAdapter() {
248
         return this.usesNewGumFlow() || this.isEdge();
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
 }

正在加载...
取消
保存