Torch Capability Not Detected on Samsung Devices Using applyConstraint

I am implementing a flashlight toggle feature in a React web application using the WebRTC API. The code works correctly on most devices, but I have observed that on Samsung devices, the flashlight capability (torch) is not detected, even though the device has a flashlight.
Here is the code snippet I’m using:

const handleFlashToggle = async (flashStatus: boolean) => {
if (isTogglingFlash || flashOn === flashStatus) return;
setIsTogglingFlash(true);

if (mediaStream) {
    try {
        const track: any = mediaStream.getVideoTracks()[0];
        const capabilities: any = track.getCapabilities();

        if (capabilities?.torch) {
            await track.applyConstraints({
                advanced: [{ torch: flashStatus }],
            });
            setFlashOn(flashStatus);
        } else {
            toast.error("Torch is not supported on this device.");
        }
    } catch (error) {
        toast.error("Failed to toggle flash.");
    } finally {
        setIsTogglingFlash(false);
    }
} else {
    toast.error("MediaStream is not available.");
}

};

Steps to Reproduce:

  1. Use a Samsung device (tested on Samsung Galaxy models).
  2. Open the web application that includes the above code.
  3. Grant camera permissions and try to toggle the flashlight.

Expected Behavior:
The flashlight should toggle on and off if the device supports it.

Actual Behavior:
The getCapabilities() method returns an object that does not include torch as a capability, and the flashlight cannot be toggled.

  • The same code works correctly on non-Samsung devices like (list examples, e.g., Google Pixel, iPhone).

Questions:

  1. Does Samsung restrict access to the torch capability via the WebRTC API?
  2. Is there a workaround or a specific permission required to enable this?

Hello @ankit.t.kumar

Welcome to the Samsung Developers Forum.

Please create a support ticket in the Samsung Developer Support Portal detailing the issue and we will check the issue.

Best Regards,
Ahsan
Samsung Developer Relations