Skip to content

Commit

Permalink
Small refactor + add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
dk981234 committed Oct 30, 2023
1 parent a83bf28 commit e3d5814
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/utils/camera.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'){
Expand Down
6 changes: 6 additions & 0 deletions tests/questionFileTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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" }]
Expand Down

0 comments on commit e3d5814

Please sign in to comment.