From e3d5814e318f50b982d2802e8b23ce0665a23d20 Mon Sep 17 00:00:00 2001 From: Dmitry Kuzin Date: Mon, 30 Oct 2023 17:43:33 +0400 Subject: [PATCH] Small refactor + add unit test --- src/utils/camera.ts | 9 +++++++-- tests/questionFileTests.ts | 6 ++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/utils/camera.ts b/src/utils/camera.ts index b89d369aa7..49709744c3 100644 --- a/src/utils/camera.ts +++ b/src/utils/camera.ts @@ -116,14 +116,19 @@ export class Camera { callback(undefined); }); } + public getImageSize(videoEl:HTMLVideoElement): { width: number, height: number } { + return { width: videoEl.videoWidth, height: videoEl.videoHeight }; + + } public snap(videoElementId: string, callback: BlobCallback): boolean { if("undefined" === typeof document) return false; const root = document; const videoEl: HTMLVideoElement = root.getElementById(videoElementId) as HTMLVideoElement; if(!videoEl) return false; const canvasEl = root.createElement("canvas"); - canvasEl.height = videoEl.videoHeight; - canvasEl.width = videoEl.videoWidth; + const imageSize = this.getImageSize(videoEl); + canvasEl.height = imageSize.height; + canvasEl.width = imageSize.width; let context = canvasEl.getContext("2d"); /* if(this._facingMode == 'user'){ diff --git a/tests/questionFileTests.ts b/tests/questionFileTests.ts index 610a315b32..8747ee4a18 100644 --- a/tests/questionFileTests.ts +++ b/tests/questionFileTests.ts @@ -1577,6 +1577,12 @@ QUnit.test("new Camera().getMediaConstraints width and height", function(assert) assert.deepEqual(mConst.video.height, { ideal: 100 }); Camera.clear(); }); +QUnit.test("Camera: check getImageSize method", function(assert) { + let imageSize = new Camera().getImageSize({ videoWidth: 100, videoHeight: 200 } as any); + assert.deepEqual(imageSize, { width: 100, height: 200 }); + imageSize = new Camera().getImageSize({ videoWidth: 130, videoHeight: 250 } as any); + assert.deepEqual(imageSize, { width: 130, height: 250 }); +}); QUnit.test("QuestionFile stop playing video on hiding question", function(assert) { let survey = new SurveyModel({ elements: [{ type: "file", name: "q1" }]