From a16fa912a9342084a6a15b600f7abf3de1a123f8 Mon Sep 17 00:00:00 2001 From: amar-1995 Date: Wed, 20 Mar 2024 17:20:09 +0530 Subject: [PATCH] fix: uupdated the logic for getting actual constraint --- .../src/sdk/LocalTrackManager.ts | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/packages/hms-video-store/src/sdk/LocalTrackManager.ts b/packages/hms-video-store/src/sdk/LocalTrackManager.ts index 5a36836dfb..939bc8ade6 100644 --- a/packages/hms-video-store/src/sdk/LocalTrackManager.ts +++ b/packages/hms-video-store/src/sdk/LocalTrackManager.ts @@ -158,7 +158,6 @@ export class LocalTrackManager { nativeTracks.push(...this.getEmptyTracks(fetchTrackOptions)); return nativeTracks; } - // eslint-disable-next-line complexity private async optimizeScreenShareConstraint(stream: MediaStream, constraints: MediaStreamConstraints) { if (typeof constraints.video === 'boolean' || !constraints.video?.width || !constraints.video?.height) { return; @@ -177,18 +176,14 @@ export class LocalTrackManager { const currentAspectRatio = screen.width / screen.height; if (actualAspectRatio > currentAspectRatio) { const videoConstraint = constraints.video as MediaTrackConstraints; - videoConstraint.width = videoWidth; - videoConstraint.height = videoHeight; + const ratio = actualAspectRatio / currentAspectRatio; + const sqrt_ratio = Math.sqrt(ratio); if (videoWidth * videoHeight > pixels) { - const ratio = (videoWidth * videoHeight) / pixels; - const divide_ratio = Math.sqrt(ratio); - videoConstraint.width = videoWidth / divide_ratio; - videoConstraint.height = videoHeight / divide_ratio; + videoConstraint.width = videoWidth / sqrt_ratio; + videoConstraint.height = videoHeight / sqrt_ratio; } else { - const ratio = pixels / (videoWidth * videoHeight); - const multiply_ratio = Math.sqrt(ratio); - videoConstraint.height = videoHeight * multiply_ratio; - videoConstraint.width = videoWidth * multiply_ratio; + videoConstraint.height = videoHeight * sqrt_ratio; + videoConstraint.width = videoWidth * sqrt_ratio; } await stream.getVideoTracks()[0].applyConstraints(videoConstraint); }