Controlling torch, and other media constraints, through VideoTexture.CreateFromWebCam

The helper method VideTexture.CreateFromWebCam takes in a MediaTrackConstraints object that lets you specify requirements for the video stream that is picked. It however doesn’t give you a way to change those constraints later (which you can usually do through MediaStreamTrack.applyConstraints())

Some of the constraints are ones that you would ideally be able to modify during the lifetime of the VideoTexture. Some examples are:

  • Turning on/off the torch/flashlight using the torch constraint
  • Turning on/off autofocus using the focusMode constraint
    • Changing the focus using the focusDistance constraint

It would be very handy for BabylonJS to expose some way to query the MediaStreamTrack used internally by VideoTexture.CreateFromWebCam in order to apply changes at runtime.

I wonder if in this case you should not use CreateVideoFromStreamAsync instead so you d have all the required freedom to us the full extend of the media API.

That said it would prevent it to work in Babylon Native so summoning @bghgary on this one.

I’m not sure this is native related. If we need to call a different API on media source, we just need to support it in native also. Native code is all prototype at the moment anyways.