Skip to content

Commit

Permalink
fix(RTCUtils) Apply default frameRate constraints.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jallamsetty1 committed Jul 11, 2024
1 parent 2f65997 commit 0a2b079
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions modules/RTC/RTCUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ const DEFAULT_CONSTRAINTS = {
ideal: 1280,
max: 1280,
min: 320
},
frameRate: {
min: 15,
max: 30
}
}
};
Expand Down Expand Up @@ -88,11 +92,14 @@ function emptyFuncton() {
* @returns {Object}
*/
function getConstraints(um = [], options = {}) {
// Create a deep copy of the constraints to avoid any modification of
// the passed in constraints object.
// Create a deep copy of the constraints to avoid any modification of the passed in constraints object.
const constraints = clonedeep(options.constraints || DEFAULT_CONSTRAINTS);

if (um.indexOf('video') >= 0) {
if (!constraints.video) {
constraints.video = {};
}

// The "resolution" option is a shortcut and takes precendence.
if (Resolutions[options.resolution]) {
const r = Resolutions[options.resolution];
Expand All @@ -101,8 +108,8 @@ function getConstraints(um = [], options = {}) {
constraints.video.width = { ideal: r.width };
}

if (!constraints.video) {
constraints.video = {};
if (!constraints.video.frameRate) {
constraints.video.frameRate = DEFAULT_CONSTRAINTS.video.frameRate;
}

// Override the constraints on Safari because of the following webkit bug.
Expand All @@ -123,10 +130,8 @@ function getConstraints(um = [], options = {}) {
}
if (options.cameraDeviceId) {
constraints.video.deviceId = { exact: options.cameraDeviceId };
} else {
const facingMode = options.facingMode || CameraFacingMode.USER;

constraints.video.facingMode = facingMode;
} else if (browser.isMobileDevice()) {
constraints.video.facingMode = options.facingMode || CameraFacingMode.USER;
}
} else {
constraints.video = false;
Expand Down

0 comments on commit 0a2b079

Please sign in to comment.