Skip to content

QuestionFileModel: Enable customization of preferred cameraFacingMode option #10864

@PeterMarinov

Description

@PeterMarinov

Is your feature request related to a problem? Please describe.

Yes. Currently, the QuestionFileModel defaults to the user-facing (front) camera when sourceType is set to "camera". This creates friction for common mobile data collection use cases, such as:

  • Scanning product barcodes or QR codes.
  • Taking photos of documents or equipment for inspection.
  • Field reporting where the rear camera is the primary tool.

In these scenarios, the user is forced to manually flip the camera every time they interact with a question. Conversely, for identity verification (selfies), the default behavior is correct. There is currently no stable API to configure this preference per question.

Describe the solution you'd like

Just sharing some ideas - both will work with different trade-offs

Option 1: Add a cameraFacingMode property to QuestionFileModel.

We then pass it to the camera.ts when selecting facingMode if supported from the getMediaConstraints result.

// Question JSON
{
  "type": "file",
  "name": "equipment_photo",
  "sourceType": "camera",
  "cameraFacingMode": "environment" // Defaults to "user" if not set
}

Option 2: Add a onGetQuestionMediaConstraints event.

introduce an event in SurveyModel that allows developers to intercept and modify the MediaStreamConstraints before the camera.ts is initialized. This enables advanced configuration (resolution, facing mode, frame rate) without modifying the core library.

// Usage Example
survey.onGetQuestionMediaConstraints.add((sender, options) => {
    const q = options.question;
    // Apply logic based on question name or custom properties
    if (q.name === "scan_qr" || q.customProperty === "rear-camera") {
        if (!options.constraints.video) options.constraints.video = {};
        
        // Force environment facing mode
        options.constraints.video.facingMode = "environment";
        // Ensure cached deviceIds don't override the preference
        delete options.constraints.video.deviceId;
    }
});

Describe alternatives you've considered

We are currently using a workaround that involves monkey-patching the internal Camera.prototype.getMediaConstraints method. This approach is not-preferable as it relies on patching non-exported classes (packages/survey-core/src/utils/camera.ts).

Here is a demo of the work around - https://plnkr.co/edit/UH4ZElS8pjU5zk52?preview

Additional context

The QuestionFileModel.startVideoInCamera method currently generates constraints internally and passes them directly to the Camera class. Exposing a hook/callback here would significantly improve the library's capability for mobile-first field applications.

Both options will work, but it seems the event will be most flexible option covering numerous use cases beyond that specific one

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions