From 9488386a48961eccb911d7eb23b5779ddbbbaa63 Mon Sep 17 00:00:00 2001 From: Josh de Leeuw Date: Tue, 31 May 2022 17:48:01 -0400 Subject: [PATCH] add width and height options to give some control to file size generated by recording --- .../plugin-initialize-camera/src/index.ts | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/packages/plugin-initialize-camera/src/index.ts b/packages/plugin-initialize-camera/src/index.ts index da351640..099c8c1e 100644 --- a/packages/plugin-initialize-camera/src/index.ts +++ b/packages/plugin-initialize-camera/src/index.ts @@ -13,6 +13,14 @@ const info = { type: ParameterType.STRING, default: "Use this camera", }, + width: { + type: ParameterType.INT, + default: null, + }, + height: { + type: ParameterType.INT, + default: null, + }, }, }; @@ -53,7 +61,16 @@ class InitializeCameraPlugin implements JsPsychPlugin { const camera_id = await this.waitForSelection(display_element); - const stream = await navigator.mediaDevices.getUserMedia({ video: { deviceId: camera_id } }); + const constraints: any = { video: { deviceId: camera_id } }; + + if (trial.width) { + constraints.video.width = trial.width; + } + if (trial.height) { + constraints.video.height = trial.height; + } + + const stream = await navigator.mediaDevices.getUserMedia(constraints); this.jsPsych.pluginAPI.initializeCameraRecorder(stream);