Ver código fonte

fix(RTCUtils) Apply default frameRate constraints.

This prevents the browser from starting the camera at 60 fps wherever supported as this could drastically affect the cpu and result in poor experience.
release-8443
Jaya Allamsetty 1 ano atrás
pai
commit
0a2b079c35
1 arquivos alterados com 13 adições e 8 exclusões
  1. 13
    8
      modules/RTC/RTCUtils.js

+ 13
- 8
modules/RTC/RTCUtils.js Ver arquivo

@@ -35,6 +35,10 @@ const DEFAULT_CONSTRAINTS = {
35 35
             ideal: 1280,
36 36
             max: 1280,
37 37
             min: 320
38
+        },
39
+        frameRate: {
40
+            min: 15,
41
+            max: 30
38 42
         }
39 43
     }
40 44
 };
@@ -88,11 +92,14 @@ function emptyFuncton() {
88 92
  * @returns {Object}
89 93
  */
90 94
 function getConstraints(um = [], options = {}) {
91
-    // Create a deep copy of the constraints to avoid any modification of
92
-    // the passed in constraints object.
95
+    // Create a deep copy of the constraints to avoid any modification of the passed in constraints object.
93 96
     const constraints = clonedeep(options.constraints || DEFAULT_CONSTRAINTS);
94 97
 
95 98
     if (um.indexOf('video') >= 0) {
99
+        if (!constraints.video) {
100
+            constraints.video = {};
101
+        }
102
+
96 103
         // The "resolution" option is a shortcut and takes precendence.
97 104
         if (Resolutions[options.resolution]) {
98 105
             const r = Resolutions[options.resolution];
@@ -101,8 +108,8 @@ function getConstraints(um = [], options = {}) {
101 108
             constraints.video.width = { ideal: r.width };
102 109
         }
103 110
 
104
-        if (!constraints.video) {
105
-            constraints.video = {};
111
+        if (!constraints.video.frameRate) {
112
+            constraints.video.frameRate = DEFAULT_CONSTRAINTS.video.frameRate;
106 113
         }
107 114
 
108 115
         // Override the constraints on Safari because of the following webkit bug.
@@ -123,10 +130,8 @@ function getConstraints(um = [], options = {}) {
123 130
         }
124 131
         if (options.cameraDeviceId) {
125 132
             constraints.video.deviceId = { exact: options.cameraDeviceId };
126
-        } else {
127
-            const facingMode = options.facingMode || CameraFacingMode.USER;
128
-
129
-            constraints.video.facingMode = facingMode;
133
+        } else if (browser.isMobileDevice()) {
134
+            constraints.video.facingMode = options.facingMode || CameraFacingMode.USER;
130 135
         }
131 136
     } else {
132 137
         constraints.video = false;

Carregando…
Cancelar
Salvar